Top Description Fields Constructors Methods
org.jboss.logmanager.handlers

public Class DelayedHandler

extends ExtHandler
Class Inheritance
Annotations
@SuppressWarnings:unused, WeakerAccess
Imports
java.util.ArrayDeque, .Arrays, .Deque, .HashMap, .List, .Map, java.util.function.Supplier, java.util.logging.ErrorManager, .Formatter, .Handler, .Level, org.jboss.logmanager.ExtHandler, .ExtLogRecord, .LogContext, .StandardOutputStreams, org.jboss.logmanager.formatters.PatternFormatter

A handler that queues messages until it's at least one child handler is added or set. If the children handlers are cleared then the handler is no longer considered activated and messages will once again be queued.
Author
James R. Perkins

Field Summary

Modifier and TypeField and Description
private volatile boolean
private volatile boolean
private final LogContext
private final int
private final Map<Level, Deque<ExtLogRecord>>
private final Level
Inherited from org.jboss.logmanager.ExtHandler:
handlershandlersUpdaterlock

Constructor Summary

AccessConstructor and Description
public
DelayedHandler()

Construct a new instance.

public
DelayedHandler(LogContext
the log context to use for level checks on replay, or null for none
logContext
)

Construct a new instance, with the given log context used to recheck log levels on replay.

public
DelayedHandler(int
the queue limit
queueLimit
)

Construct a new instance.

public
DelayedHandler(LogContext
the log context to use for level checks on replay, or null for none
logContext
,
int
the queue limit
queueLimit
)

Construct a new instance, with the given log context used to recheck log levels on replay.

public
DelayedHandler(int
the queue limit
queueLimit
,
Level
the threshold level to report queue overruns for
warnThreshold
)

Construct a new instance.

public
DelayedHandler(LogContext
the log context to use for level checks on replay, or null for none
logContext
,
int
the queue limit
queueLimit
,
Level
the threshold level to report queue overruns for
warnThreshold
)

Construct a new instance, with the given log context used to recheck log levels on replay.

Method Summary

Modifier and TypeMethod and Description
private void
public void
addHandler(final Handler
the handler to add
handler
)

Overrides org.jboss.logmanager.ExtHandler.addHandler.

Add a sub-handler to this handler.

public Handler[]
clearHandlers()

Overrides org.jboss.logmanager.ExtHandler.clearHandlers.

A convenience method to atomically get and clear all sub-handlers.

public final void
close()

Overrides org.jboss.logmanager.ExtHandler.close.

Implements java.lang.AutoCloseable.close.

Close all child handlers.

protected void
doPublish(final ExtLogRecord
the log record to publish
record
)

Overrides org.jboss.logmanager.ExtHandler.doPublish.

Do the actual work of publication; the record will have been filtered already.

private Supplier<ExtLogRecord>
private void
enqueueOrdered(Deque<ExtLogRecord>
the queue
q
,
ExtLogRecord
the record
record
)

Enqueue the log record such that the queue's order (by sequence number) is maintained.

public final boolean

Returns:

true if the handler has been activated, otherwise false
isActivated
()

Indicates whether or not this handler has been activated.

public boolean
isCallerCalculationRequired()

Overrides org.jboss.logmanager.ExtHandler.isCallerCalculationRequired.

Indicates whether or not the formatter associated with this handler or a formatter from a child handler requires the caller to be calculated.

private static <E> Deque<E>
newDeque(Object ignored)

public void
removeHandler(final Handler
the handler to remove
handler
)

Overrides org.jboss.logmanager.ExtHandler.removeHandler.

Remove a sub-handler from this handler.

public void
setCallerCalculationRequired(final boolean
true if the caller information should always be calculated before the record is being placed in the queue
callerCalculationRequired
)

Sets whether or not caller information will be required when formatting records.

public Handler[]
setHandlers(final Handler[]
the new sub-handlers
newHandlers
)

Overrides org.jboss.logmanager.ExtHandler.setHandlers.

A convenience method to atomically get and replace the sub-handler array.

Inherited from org.jboss.logmanager.ExtHandler:
checkAccesscheckAccessflushgetCharsetgetEncodinggetErrorManagergetFiltergetFormattergetHandlersgetLevelisAutoFlushisCloseChildrenisEnabledpublishpublishpublishToNestedHandlersreportErrorreportErrorsetAutoFlushsetCharsetsetCharsetPrivatesetCloseChildrensetEnabledsetEncodingsetErrorManagersetFiltersetFormattersetLevel

Field Detail

activatedback to summary
private volatile boolean activated
callerCalculationRequiredback to summary
private volatile boolean callerCalculationRequired
logContextback to summary
private final LogContext logContext
queueLimitback to summary
private final int queueLimit
queuesback to summary
private final Map<Level, Deque<ExtLogRecord>> queues
warnThresholdback to summary
private final Level warnThreshold

Constructor Detail

DelayedHandlerback to summary
public DelayedHandler()

Construct a new instance.

DelayedHandlerback to summary
public DelayedHandler(LogContext logContext)

Construct a new instance, with the given log context used to recheck log levels on replay.

Parameters
logContext:LogContext

the log context to use for level checks on replay, or null for none

DelayedHandlerback to summary
public DelayedHandler(int queueLimit)

Construct a new instance. The given queue limit value is used to limit the length of each level queue.

Parameters
queueLimit:int

the queue limit

DelayedHandlerback to summary
public DelayedHandler(LogContext logContext, int queueLimit)

Construct a new instance, with the given log context used to recheck log levels on replay. The given queue limit value is used to limit the length of each level queue.

Parameters
logContext:LogContext

the log context to use for level checks on replay, or null for none

queueLimit:int

the queue limit

DelayedHandlerback to summary
public DelayedHandler(int queueLimit, Level warnThreshold)

Construct a new instance. The given queue limit value is used to limit the length of each level queue. The warning threshold specifies that only queues with the threshold level or higher will report overrun errors.

Parameters
queueLimit:int

the queue limit

warnThreshold:Level

the threshold level to report queue overruns for

DelayedHandlerback to summary
public DelayedHandler(LogContext logContext, int queueLimit, Level warnThreshold)

Construct a new instance, with the given log context used to recheck log levels on replay. The given queue limit value is used to limit the length of each level queue. The warning threshold specifies that only queues with the threshold level or higher will report overrun errors.

Parameters
logContext:LogContext

the log context to use for level checks on replay, or null for none

queueLimit:int

the queue limit

warnThreshold:Level

the threshold level to report queue overruns for

Method Detail

activateback to summary
private void activate()
addHandlerback to summary
public void addHandler(final Handler handler) throws SecurityException

Overrides org.jboss.logmanager.ExtHandler.addHandler.

Doc from org.jboss.logmanager.ExtHandler.addHandler.

Add a sub-handler to this handler. Some handler types do not utilize sub-handlers.

Note that once this is invoked the handler will be activated and the messages will no longer be queued. If more than one child handler is required the setHandlers(Handler[]) should be used.

Parameters
handler:Handler

the handler to add

Annotations
@Override
Exceptions
SecurityException:
if a security manager exists and if the caller does not have LoggingPermission(control)
See Also
setHandlers(Handler[])
clearHandlersback to summary
public Handler[] clearHandlers() throws SecurityException

Overrides org.jboss.logmanager.ExtHandler.clearHandlers.

Doc from org.jboss.logmanager.ExtHandler.clearHandlers.

A convenience method to atomically get and clear all sub-handlers.

Note that once this is invoked the handler will no longer be activated and messages will again be queued.

Returns:Handler[]

the old sub-handler array

Annotations
@Override
Exceptions
SecurityException:
if a security manager exists and if the caller does not have LoggingPermission(control)
See Also
removeHandler(Handler)
closeback to summary
public final void close() throws SecurityException

Overrides org.jboss.logmanager.ExtHandler.close.

Implements java.lang.AutoCloseable.close.

Doc from org.jboss.logmanager.ExtHandler.close.

Close all child handlers.

Annotations
@Override
Exceptions
SecurityException:

Doc from java.util.logging.Handler.close.

if a security manager exists and if the caller does not have LoggingPermission("control").

doPublishback to summary
protected void doPublish(final ExtLogRecord record)

Overrides org.jboss.logmanager.ExtHandler.doPublish.

Doc from org.jboss.logmanager.ExtHandler.doPublish.

Do the actual work of publication; the record will have been filtered already. The default implementation does nothing except to flush if the autoFlush property is set to true; if this behavior is to be preserved in a subclass then this method should be called after the record is physically written.

Parameters
record:ExtLogRecord

the log record to publish

Annotations
@Override
drainback to summary
private Supplier<ExtLogRecord> drain()
enqueueOrderedback to summary
private void enqueueOrdered(Deque<ExtLogRecord> q, ExtLogRecord record)

Enqueue the log record such that the queue's order (by sequence number) is maintained.

Parameters
q:Deque<ExtLogRecord>

the queue

record:ExtLogRecord

the record

isActivatedback to summary
public final boolean isActivated()

Indicates whether or not this handler has been activated.

Returns:boolean

true if the handler has been activated, otherwise false

isCallerCalculationRequiredback to summary
public boolean isCallerCalculationRequired()

Overrides org.jboss.logmanager.ExtHandler.isCallerCalculationRequired.

Doc from org.jboss.logmanager.ExtHandler.isCallerCalculationRequired.

Indicates whether or not the formatter associated with this handler or a formatter from a child handler requires the caller to be calculated.

Calculating the caller on a log record can be an expensive operation. Some handlers may be required to copy some data from the log record, but may not need the caller information. If the formatter is a ExtFormatter the ExtFormatter#isCallerCalculationRequired() is used to determine if calculation of the caller is required.

This can be overridden to always require the caller calculation by setting the setCallerCalculationRequired(boolean) value to true.

Returns:boolean

true if the caller should be calculated, otherwise false if it can be skipped

Annotations
@Override
See Also
setCallerCalculationRequired(boolean)
newDequeback to summary
private static <E> Deque<E> newDeque(Object ignored)
removeHandlerback to summary
public void removeHandler(final Handler handler) throws SecurityException

Overrides org.jboss.logmanager.ExtHandler.removeHandler.

Doc from org.jboss.logmanager.ExtHandler.removeHandler.

Remove a sub-handler from this handler. Some handler types do not utilize sub-handlers.

Note that if the last child handler is removed the handler will no longer be activated and the messages will again be queued.

Parameters
handler:Handler

the handler to remove

Annotations
@Override
Exceptions
SecurityException:
if a security manager exists and if the caller does not have LoggingPermission(control)
See Also
clearHandlers()
setCallerCalculationRequiredback to summary
public void setCallerCalculationRequired(final boolean callerCalculationRequired)

Sets whether or not caller information will be required when formatting records.

If set to true the caller information will be calculated for each record that is placed in the queue. A value of false means the super#isCallerCalculationRequired() will be used.

Note that the caller information is only attempted to be calculated when the handler has not been activated. Once activated it's up to the children handlers to determine how the record is processed.

Parameters
callerCalculationRequired:boolean

true if the caller information should always be calculated before the record is being placed in the queue

setHandlersback to summary
public Handler[] setHandlers(final Handler[] newHandlers) throws SecurityException

Overrides org.jboss.logmanager.ExtHandler.setHandlers.

Doc from org.jboss.logmanager.ExtHandler.setHandlers.

A convenience method to atomically get and replace the sub-handler array.

Note that once this is invoked the handler will be activated and the messages will no longer be queued.

Parameters
newHandlers:Handler[]

the new sub-handlers

Returns:Handler[]

the old sub-handler array

Annotations
@Override
Exceptions
SecurityException:
if a security manager exists and if the caller does not have LoggingPermission(control)