com.quartzdesk.api.agent.log
Class WorkerThreadLoggingInterceptorRegistry

java.lang.Object
  extended by com.quartzdesk.api.agent.log.WorkerThreadLoggingInterceptorRegistry

public class WorkerThreadLoggingInterceptorRegistry
extends Object

A registry that can be used to turn on/off interception of log messages produced by worker threads spawned and used by executing jobs. The registry is to be used like so:


 public class MyCallable
     implements Callable
 {
   private Thread jobThread;

   // @param jobThread the main job execution thread that will be using this Callable instance.
   public MyCallable( Thread jobThread )
   {
     this.jobThread = jobThread;
   }

   public Foo call()
       throws Exception
   {
     // Start intercepting logging events from the current worker thread (returned by Thread.currentThread())
     // and associate these events with the specified main job execution thread.
     WorkerThreadLoggingInterceptorRegistry.INSTANCE.startIntercepting( jobThread );
     try
     {
       // some business logic and logging
       return foo;
     }
     finally
     {
       // Stop intercepting logging events from the current worker thread.
       WorkerThreadLoggingInterceptorRegistry.INSTANCE.stopIntercepting();
     }
   }
 }

 

Version:
$Id:$
Author:
Jan Moravec

Field Summary
static WorkerThreadLoggingInterceptorRegistry INSTANCE
           
 
Method Summary
 Thread getJobThreadForWorkerThread(Thread workerThread)
          Returns the job thread associated with the specified thread.
 void startIntercepting(Thread jobThread)
          Starts intercepting log messages produced by the current thread (as returned by Thread.currentThread()) that is used by the specified job thread.
 void stopIntercepting()
          Stops intercepting log messages produced by the current thread (as returned by Thread.currentThread()).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INSTANCE

public static final WorkerThreadLoggingInterceptorRegistry INSTANCE
Method Detail

getJobThreadForWorkerThread

public Thread getJobThreadForWorkerThread(Thread workerThread)
Returns the job thread associated with the specified thread.

Parameters:
workerThread - a worker thread.
Returns:
the job thread.

startIntercepting

public void startIntercepting(Thread jobThread)
Starts intercepting log messages produced by the current thread (as returned by Thread.currentThread()) that is used by the specified job thread.

Parameters:
jobThread - a job thread.

stopIntercepting

public void stopIntercepting()
Stops intercepting log messages produced by the current thread (as returned by Thread.currentThread()).



Copyright © 2013–2017 QuartzDesk.com. All rights reserved.