Package org.jboss.logmanager.handlers

## Class DelayedHandler

- java.lang.Object
- - java.util.logging.Handler
  - - org.jboss.logmanager.ExtHandler
    - - org.jboss.logmanager.handlers.DelayedHandler

All Implemented Interfaces:
  `java.io.Closeable`, `java.io.Flushable`, `java.lang.AutoCloseable`, `FlushableCloseable`, `Protectable`

    public class DelayedHandler
    extends ExtHandler

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

### Fields inherited from class org.jboss.logmanager.ExtHandler

`handlers, handlersUpdater`

### Constructor Summary

Constructors
`DelayedHandler()`

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `addHandler​(java.util.logging.Handler handler)` Add a sub-handler to this handler.
`java.util.logging.Handler[]` `clearHandlers()` A convenience method to atomically get and clear all sub-handlers.
`void` `close()` Close all child handlers.
`protected void` `doPublish​(ExtLogRecord record)` Do the actual work of publication; the record will have been filtered already.
`boolean` `isActivated()` Indicates whether or not this handler has been activated.
`boolean` `isCallerCalculationRequired()` Indicates whether or not the formatter associated with this handler or a formatter from a child handler requires the caller to be calculated.
`void` `removeHandler​(java.util.logging.Handler handler)` Remove a sub-handler from this handler.
`void` `setCallerCalculationRequired​(boolean callerCalculationRequired)` Sets whether or not caller information will be required when formatting records.
`java.util.logging.Handler[]` `setHandlers​(java.util.logging.Handler[] newHandlers)` A convenience method to atomically get and replace the sub-handler array.

### Methods inherited from class org.jboss.logmanager.ExtHandler

`checkAccess, checkAccess, disableAccess, enableAccess, flush, getHandlers, isAutoFlush, isCloseChildren, isEnabled, protect, publish, publish, setAutoFlush, setCloseChildren, setEnabled, setEncoding, setErrorManager, setFilter, setFormatter, setLevel, unprotect`

### Methods inherited from class java.util.logging.Handler

`getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### DelayedHandler

    public DelayedHandler()

### Method Detail

#### doPublish

    protected void doPublish​(ExtLogRecord record)

Description copied from class: `ExtHandler`
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.

Overrides:
  `doPublish` in class `ExtHandler`
Parameters:
  `record` - the log record to publish

#### close

    public final void close()
                     throws java.lang.SecurityException

Description copied from class: `ExtHandler`
Close all child handlers.

Specified by:
  `close` in interface `java.lang.AutoCloseable`
Specified by:
  `close` in interface `java.io.Closeable`
Overrides:
  `close` in class `ExtHandler`
Throws:
  `java.lang.SecurityException`

#### addHandler

    public void addHandler​(java.util.logging.Handler handler)
                    throws java.lang.SecurityException

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.

Overrides:
  `addHandler` in class `ExtHandler`
Parameters:
  `handler` - the handler to add
Throws:
  `java.lang.SecurityException` - if a security manager exists and if the caller does not have `LoggingPermission(control)` or the handler is `protected`.
See Also:
  `setHandlers(Handler[])`

#### setHandlers

    public java.util.logging.Handler[] setHandlers​(java.util.logging.Handler[] newHandlers)
                                            throws java.lang.SecurityException

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.

Overrides:
  `setHandlers` in class `ExtHandler`
Parameters:
  `newHandlers` - the new sub-handlers
Returns:
  the old sub-handler array
Throws:
  `java.lang.SecurityException` - if a security manager exists and if the caller does not have `LoggingPermission(control)` or the handler is `protected`.

#### removeHandler

    public void removeHandler​(java.util.logging.Handler handler)
                       throws java.lang.SecurityException

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.

Overrides:
  `removeHandler` in class `ExtHandler`
Parameters:
  `handler` - the handler to remove
Throws:
  `java.lang.SecurityException` - if a security manager exists and if the caller does not have `LoggingPermission(control)` or the handler is `protected`.
See Also:
  `clearHandlers()`

#### clearHandlers

    public java.util.logging.Handler[] clearHandlers()
                                              throws java.lang.SecurityException

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.

Overrides:
  `clearHandlers` in class `ExtHandler`
Returns:
  the old sub-handler array
Throws:
  `java.lang.SecurityException` - if a security manager exists and if the caller does not have `LoggingPermission(control)` or the handler is `protected`.
See Also:
  `removeHandler(Handler)`

#### isCallerCalculationRequired

    public boolean 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`.

Overrides:
  `isCallerCalculationRequired` in class `ExtHandler`
Returns:
  `true` if the caller should be calculated, otherwise `false` if it can be skipped
See Also:
  `setCallerCalculationRequired(boolean)`

#### setCallerCalculationRequired

    public void setCallerCalculationRequired​(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 {@link 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` - `true` if the caller information should always be calculated before the record is being placed in the queue

#### isActivated

    public final boolean isActivated()

Indicates whether or not this handler has been activated.

Returns:
  `true` if the handler has been activated, otherwise `false`