Package Functions

alma.acs.logging.DispatchingLogQueue Class Reference

List of all members.

Package Functions

 DispatchingLogQueue ()
int getMaxQueueSize ()
synchronized void setMaxQueueSize (int maxQueueSize)
synchronized boolean log (LogRecord logRecord)
void flushAllAndWait ()
Future< Boolean > flush ()
boolean hasRemoteDispatcher ()
int recordQueueSize ()
int pendingFlushes ()
int realQueueSize ()
boolean flushesPeriodically ()
void setPeriodicFlushing (final int periodMillisec)
void setRemoteLogDispatcher (RemoteLogDispatcher remoteLogDispatcher)
void shutDown ()

Detailed Description

Queue for LogRecords which takes care of dispatching them to a remote log service, using the one provided in setRemoteLogDispatcher(RemoteLogDispatcher).

Technically this class is not a singleton, but it is foreseen to be used as a single instance. It is thread-safe, so multiple log handlers can submit records.

All log records to be sent remotely to the central log service must be submitted to the log(LogRecord) method. If the remote log service is not available (e.g. during startup, or later temporarily due to network problems), the log records will be cached. The cache size is given by MAX_QUEUE_SIZE. If the cache is more than 70% full, the log method will only accept records with level INFO or higher. If the cache is full, no records are accepted. The idea is to not jeopardize the running system, but rather stop remote logging.

The queue sorts log records by their log levels and thus dispatches the most important records first, using LogRecordComparator.

Author:
hsommer created Apr 19, 2005 1:48:27 PM

Constructor & Destructor Documentation

alma.acs.logging.DispatchingLogQueue.DispatchingLogQueue (  )  [package]

Member Function Documentation

Future<Boolean> alma.acs.logging.DispatchingLogQueue.flush (  )  [package]

Tries to send log records to the remote log service, but at most RemoteLogDispatcher#getBufferSize(). If sending fails, the log records remain in the queue (actually they may be first taken out and then get re-submitted).

This method returns immediately, since flushing is done in a separate thread. The returned future object can be used to wait for termination of the log flush and get the result, or to cancel the flush. The result is a Boolean which is true if all or at least 1 log record could be taken off the log queue.

References alma.acs.logging.DispatchingLogQueue.pendingFlushes().

Referenced by alma.acs.logging.AcsLoggingHandler.flush(), alma.acs.logging.DispatchingLogQueue.flushAllAndWait(), alma.acs.logging.AcsLoggingHandler.publish(), alma.acs.logging.DispatchingLogQueue.setPeriodicFlushing(), and alma.acs.logging.ClientLogManager.shutdown().

void alma.acs.logging.DispatchingLogQueue.flushAllAndWait (  )  [package]

Flushes all log records if the remote log service has been made available before. Returns only when the log queue contains no more records, so execution time may be long. Should better not be called from the main thread.

References alma.acs.logging.DispatchingLogQueue.flush(), alma.acs.logging.DispatchingLogQueue.hasRemoteDispatcher(), and alma.acs.logging.DispatchingLogQueue.realQueueSize().

Referenced by alma.acs.logging.ClientLogManager.flushAll(), and alma.acs.logging.ClientLogManager.initRemoteLogging().

boolean alma.acs.logging.DispatchingLogQueue.flushesPeriodically (  )  [package]
int alma.acs.logging.DispatchingLogQueue.getMaxQueueSize (  )  [package]
boolean alma.acs.logging.DispatchingLogQueue.hasRemoteDispatcher (  )  [package]
synchronized boolean alma.acs.logging.DispatchingLogQueue.log ( LogRecord  logRecord  )  [package]

Adds a LogRecord to the internal queue, so that it gets scheduled for logging. If a high-level log record should be sent out immediately, the caller of this method should subsequently call flush(), as the log method itself does not trigger a flush based on levels.

Threading note: it seems ok to make this method "synchronized". This avoids problems with stale queue size, even though the damage would be small since the treatment of queue size is somewhat arbitrary anyway. Synchronization should not block callers long at all because flushing is done in a separate thread and only gets triggered here.

TODO: there is currently a minor problem with queue overflow: log records get drained from the queue, and when they can't be sent off to the log service, they are resubmitted to the queue. It could happen that in the meantime, some other record with INFO or higher level has been added to the queue, and that resubmitting some of the even more important records may fail. The solution would be to replace the 70-filter rule with a running priority filter: any incoming record can kick out a less important record if the queue is full.

Parameters:
logRecord to be logged
Returns:
true if logRecord was added to the queue for logging. False if queue was too full for this record.

References alma.acs.logging.DispatchingLogQueue.setPeriodicFlushing().

Referenced by alma.acs.logging.AcsLoggingHandler.publish().

int alma.acs.logging.DispatchingLogQueue.pendingFlushes (  )  [package]

Returns the number of currently waiting flush requests. This method is intended only for monitoring the logging system. Periodic flushing enabled by setPeriodicFlushing(int) is not counted as a waiting flush request.

Note that not all of these requested flushes necessarily result in a flushing of log records, because some of them may find an empty log record queue when they get executed, and thus end w/o effect.

References alma.acs.logging.DispatchingLogQueue.flushesPeriodically().

Referenced by alma.acs.logging.DispatchingLogQueue.flush().

int alma.acs.logging.DispatchingLogQueue.realQueueSize (  )  [package]

Waits if necessary until a flushing thread has finished, and then returns the real number of currently queued log records.

Note that during flushing, the records are first taken out of the queue, but then get resubmitted if sending them to the central log service failed. Therefore, calling queue.size() w/o flush synchronization may yield too low a value.

Referenced by alma.acs.logging.DispatchingLogQueue.flushAllAndWait().

int alma.acs.logging.DispatchingLogQueue.recordQueueSize (  )  [package]

Returns the number of currently queued log messages. This method is intended only for testing and monitoring of the logging system.

synchronized void alma.acs.logging.DispatchingLogQueue.setMaxQueueSize ( int  maxQueueSize  )  [package]

Sets the maximum size of the log queue. Logs will be dropped when the queue is full. The default is 1000, but gets overwritten by the value of <LoggingConfig MaxLogQueueSize/> in the CDB.

Referenced by alma.acs.logging.ClientLogManager.configureLogging(), alma.acs.logging.DispatchingLogQueue.DispatchingLogQueue(), and alma.acs.logging.ClientLogManager.prepareRemoteLogging().

void alma.acs.logging.DispatchingLogQueue.setPeriodicFlushing ( final int  periodMillisec  )  [package]

Triggers periodic calls to flush(boolean), or terminates such automatic flushing if periodMillisec == 0.

All control over periodic log flushing is confined in this method.

The call returns without further action if flushing is already enabled with the same period as periodMillisec.

Parameters:
periodMillisec the delay between end of last scheduled flush() and the next scheduled flush().

References alma.acs.logging.DispatchingLogQueue.flush(), alma.acs.logging.DispatchingLogQueue.flushesPeriodically(), and alma.acs.logging.DispatchingLogQueue.hasRemoteDispatcher().

Referenced by alma.acs.logging.ClientLogManager.configureLogging(), alma.acs.logging.ClientLogManager.initRemoteLogging(), and alma.acs.logging.DispatchingLogQueue.log().

void alma.acs.logging.DispatchingLogQueue.setRemoteLogDispatcher ( RemoteLogDispatcher  remoteLogDispatcher  )  [package]

Sets the remote log dispatcher. Should be called once the remote log service is available. Calling this method will not flush the log queue (need to call flushAllAndWait() separately), nor will it automatically trigger periodic flushes (call setPeriodicFlushing(int) for this).

Parameters:
remoteLogDispatcher The remoteLogDispatcher to set.

Referenced by alma.acs.logging.ClientLogManager.initRemoteLogging().

void alma.acs.logging.DispatchingLogQueue.shutDown (  )  [package]

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Enumerations Properties