Class DelayedHandler

  • All Implemented Interfaces:
    Flushable, AutoCloseable

    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
    • Constructor Detail

      • DelayedHandler

        public DelayedHandler()
        Construct a new instance.
      • DelayedHandler

        public DelayedHandler​(LogContext logContext)
        Construct a new instance, with the given log context used to recheck log levels on replay.
        Parameters:
        logContext - the log context to use for level checks on replay, or null for none
      • DelayedHandler

        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 - the queue limit
      • DelayedHandler

        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 - the log context to use for level checks on replay, or null for none
        queueLimit - the queue limit
      • DelayedHandler

        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 - the queue limit
        warnThreshold - the threshold level to report queue overruns for
      • DelayedHandler

        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 - the log context to use for level checks on replay, or null for none
        queueLimit - the queue limit
        warnThreshold - the threshold level to report queue overruns for
    • 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
      • addHandler

        public void addHandler​(Handler handler)
                        throws 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:
        SecurityException - if a security manager exists and if the caller does not have LoggingPermission(control)
        See Also:
        setHandlers(Handler[])
      • setHandlers

        public Handler[] setHandlers​(Handler[] newHandlers)
                              throws 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:
        SecurityException - if a security manager exists and if the caller does not have LoggingPermission(control)
      • removeHandler

        public void removeHandler​(Handler handler)
                           throws 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:
        SecurityException - if a security manager exists and if the caller does not have LoggingPermission(control)
        See Also:
        clearHandlers()
      • clearHandlers

        public Handler[] clearHandlers()
                                throws 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:
        SecurityException - if a security manager exists and if the caller does not have LoggingPermission(control)
        See Also:
        removeHandler(Handler)
      • 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