jj2000.j2k.util
Class FacilityManager

java.lang.Object
  |
  +--jj2000.j2k.util.FacilityManager

public class FacilityManager
extends java.lang.Object

This class manages common facilities for multi-threaded environments, It can register different facilities for each thread, and also a default one, so that they can be referred by static methods, while possibly having different ones for different threads. Also a default facility exists that is used for threads for which no particular facility has been registerd registered.

Currently the only kind of facilities managed is MsgLogger.

An example use of this class is if 2 instances of a decoder are running in different threads and the messages of the 2 instances should be separated.

The default MsgLogger is a StreamMsgLogger that uses System.out as the 'out' stream and System.err as the 'err' stream, and a line width of 78. This can be changed using the registerMsgLogger() method.

See Also:
MsgLogger, StreamMsgLogger

Field Summary
private static MsgLogger defMsgLogger
          The default logger, for threads that have none associated with them
private static ProgressWatch defWatchProg
          The default ProgressWatch for threads that have none associated with them.
private static java.util.Hashtable loggerList
          The loggers associated to different threads
private static java.util.Hashtable watchProgList
          The ProgressWatch instance associated to different threads
 
Constructor Summary
FacilityManager()
           
 
Method Summary
static MsgLogger getMsgLogger()
          Returns the MsgLogger registered with the current thread (the thread that calls this method).
static MsgLogger getMsgLogger(java.lang.Thread t)
          Returns the MsgLogger registered with the thread 't' (the thread that calls this method).
static ProgressWatch getProgressWatch()
          Returns the ProgressWatch instance registered with the current thread (the thread that calls this method).
static void registerMsgLogger(java.lang.Thread t, MsgLogger ml)
          Registers the MsgLogger 'ml' as the logging facility of the thread 't'.
static void registerProgressWatch(java.lang.Thread t, ProgressWatch pw)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

loggerList

private static final java.util.Hashtable loggerList
The loggers associated to different threads


defMsgLogger

private static MsgLogger defMsgLogger
The default logger, for threads that have none associated with them


watchProgList

private static final java.util.Hashtable watchProgList
The ProgressWatch instance associated to different threads


defWatchProg

private static ProgressWatch defWatchProg
The default ProgressWatch for threads that have none associated with them.

Constructor Detail

FacilityManager

public FacilityManager()
Method Detail

registerProgressWatch

public static void registerProgressWatch(java.lang.Thread t,
                                         ProgressWatch pw)

getProgressWatch

public static ProgressWatch getProgressWatch()
Returns the ProgressWatch instance registered with the current thread (the thread that calls this method). If the current thread has no registered ProgressWatch, then the default one is used.


registerMsgLogger

public static void registerMsgLogger(java.lang.Thread t,
                                     MsgLogger ml)
Registers the MsgLogger 'ml' as the logging facility of the thread 't'. If any other logging facility was registered with the thread 't' it is overriden by 'ml'. If 't' is null then 'ml' is taken as the default message logger that is used for threads that have no MsgLogger registered.

Parameters:
t - The thread to associate with 'ml'
ml - The MsgLogger to associate with therad ml

getMsgLogger

public static MsgLogger getMsgLogger()
Returns the MsgLogger registered with the current thread (the thread that calls this method). If the current thread has no registered MsgLogger then the default message logger is returned.

Returns:
The MsgLogger registerd for the current thread, or the default one if there is none registered for it.

getMsgLogger

public static MsgLogger getMsgLogger(java.lang.Thread t)
Returns the MsgLogger registered with the thread 't' (the thread that calls this method). If the thread 't' has no registered MsgLogger then the default message logger is returned.

Parameters:
t - The thread for which to return the MsgLogger
Returns:
The MsgLogger registerd for the current thread, or the default one if there is none registered for it.