de.fhg.igd.logging
Class AbstractAsynchronousMessageDispatcher

java.lang.Object
  extended byjava.lang.Thread
      extended byde.fhg.igd.logging.AbstractAsynchronousMessageDispatcher
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
AsynchronousStreamHandler.SunMessageDispatcher, AsynchronousWriterAppender.Log4jMessageDispatcher

public abstract class AbstractAsynchronousMessageDispatcher
extends Thread

This abstract class provides the main functionality of Asynchronous Message Dispatching.

Messages handed over via dispatch() will be put into an internal FIFO (First In, First Out) buffer. As soon as the dispatcher Thread gains the monitor, it will try to deliver buffered messages via the attached Messenger.

In case the internal buffer would exceed its limit, any further calls of dispatch() will drop the oldest message until either the dispatcher was able to catch up or enough messages have been discarded. An additional notification log entry will inform about the number of lost messages.

Version:
"$Id: AbstractAsynchronousMessageDispatcher.java 1913 2007-08-08 02:41:53Z jpeters $"
Author:
Matthias Pressfreund

Field Summary
protected  List fifo_
          The internal message buffer
protected  boolean finished_
          This flag will be set to true as soon as finish() has been called.
protected  int lost_
          Counter for discarded messages
protected  int maxbuf_
          The maximum size of the internal message buffer
protected  Messenger messenger_
          The actual messenger that posts messages into the underlying logging system
protected  boolean notified_
          This flag will be set to true once a notification about message loss has been printed to System.out
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
AbstractAsynchronousMessageDispatcher(Messenger messenger, int maxbuf)
          Create an AbstractAsynchronousMessageDispatcher daemon.
 
Method Summary
protected abstract  Object createLossEntry(int lost, Object ref)
          Create a notification log entry informing about lost messages.
 void dispatch(Object msg)
          Hand over a message for dispatching.
 void finish()
          Calling this method will stop the dispatcher as soon as all remaining messages in the buffer are written into the destination stream.
protected abstract  void printLossMessage(Object ref)
          Print a notification about automatic message discarding to System.out.
 void run()
          This is the actual dispatcher implementation.
 String toString()
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

fifo_

protected List fifo_
The internal message buffer


messenger_

protected Messenger messenger_
The actual messenger that posts messages into the underlying logging system


maxbuf_

protected int maxbuf_
The maximum size of the internal message buffer


lost_

protected int lost_
Counter for discarded messages


finished_

protected boolean finished_
This flag will be set to true as soon as finish() has been called.


notified_

protected boolean notified_
This flag will be set to true once a notification about message loss has been printed to System.out

Constructor Detail

AbstractAsynchronousMessageDispatcher

public AbstractAsynchronousMessageDispatcher(Messenger messenger,
                                             int maxbuf)
Create an AbstractAsynchronousMessageDispatcher daemon.

Parameters:
messenger - The messenger that actually posts log messages into the underlying logging system
maxbuf - The maximum size of the internal message buffer
Method Detail

printLossMessage

protected abstract void printLossMessage(Object ref)
Print a notification about automatic message discarding to System.out.

Parameters:
ref - The message to refer to and get information from

createLossEntry

protected abstract Object createLossEntry(int lost,
                                          Object ref)
Create a notification log entry informing about lost messages.

Parameters:
lost - The number of lost messages
ref - The message to refer to and get information from
Returns:
The notification message object

dispatch

public void dispatch(Object msg)
Hand over a message for dispatching.

Parameters:
msg - The message to be dispatched

finish

public void finish()
Calling this method will stop the dispatcher as soon as all remaining messages in the buffer are written into the destination stream.


run

public void run()
This is the actual dispatcher implementation.


toString

public String toString()


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.