FileDocCategorySizeDatePackage
MessageLogQueue.javaAPI DocExample2361Thu May 23 09:32:50 BST 2002 sample.utility

MessageLogQueue

public class MessageLogQueue extends MessageLog implements NotificationListener
This is a log class that implements the NotificationListener interface. May be a bit lame, but shows how an asynchronous log facility can be constructed using JMX.

Fields Summary
public static final String
FLUSH_LOG
private ArrayList
_store
private static MessageLogQueue
_instance
Constructors Summary
private MessageLogQueue()


       
        super(INCLUDE_THREAD_INFO);
    
Methods Summary
public synchronized voidhandleNotification(javax.management.Notification notification, java.lang.Object obj)

        if (notification instanceof TimerNotification) {
            String type = notification.getType();
            System.out.println("MessageLogQueue.handleNotification(): INFO: "
                    + "Received a " + type + " notification.");
            if (type.equals(MessageLogQueue.FLUSH_LOG)) {
                if (_store.size() > 0) {
                    super.write("--- " + new Date() + " ---");
                    Iterator iter = _store.iterator();
                    while (iter.hasNext()) {
                        Object message = iter.next();
                        if (message instanceof String)
                            super.write((String)message); 
                        else if (message instanceof Throwable)
                            super.write((Throwable)message);
                    }
                    _store.clear();
                }
            }
        } 
        else 
            throw  new RuntimeException("MessageLogQueue.handleNotification(): ERROR: "
                    + "Only TimerNotification type supported. Received: " + 
                    notification.getClass().getName());
    
public static sample.utility.MessageLogQueueinstance()


         
        if (_instance == null)
            _instance = new MessageLogQueue();
        return  _instance;
    
public synchronized voidwrite(java.lang.String message)

        _store.add(message);
    
public synchronized voidwrite(java.lang.Throwable t)

        _store.add(t);