Class FacilityManager


  • public class FacilityManager
    extends Object
    This class manages common facilities for mutithreading 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
    • Method Detail

      • registerProgressWatch

        public static void registerProgressWatch​(Thread t,
                                                 ProgressWatch pw)
        Register the ProgressWatch for the given thread.

        If any other logging facility was registered with the given thread, it is overridden. If the Thread is null then 'ml' is taken as the default message logger that is used for threads that have no ProgressWatch registered.

        To unregister, use unregisterProgressWatch(Thread)

        Parameters:
        t - The thread to associate with progress watcher
        pw - The ProgressWatch to associate with thread
      • unregisterProgressWatch

        public static void unregisterProgressWatch​(Thread t)
        Unregister the ProgressWatch previously registered for the given thread.

        If t is null, the default progress watch is unregistered.

        Parameters:
        t - Thread to unregister progress watch for, or null to unregister the default progress watch.
        See Also:
        registerProgressWatch(Thread, ProgressWatch)
      • registerMsgLogger

        public static void registerMsgLogger​(Thread t,
                                             MsgLogger ml)
        Register MsgLogger 'ml' as the logging facility of the given thread.

        If any other logging facility was registered with the thread, it is overriden. If the Thread is null, then the given message logger will be set as the default for threads that have no MsgLogger registered.

        Parameters:
        t - The thread to associate a MsgLogger for
        ml - The MsgLogger to associate
        See Also:
        unregisterMsgLogger(Thread)
      • getMsgLogger

        public static MsgLogger getMsgLogger​(Thread t)
        Return the MsgLogger registered with the thread 't'.

        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 registered for the current thread, or the default one if there is none registered for it.