org.x4juli.global.components
Class AbstractHandler

java.lang.Object
  extended byjava.util.logging.Handler
      extended byorg.x4juli.global.components.AbstractHandler
All Implemented Interfaces:
Component, ExtendedHandler, Handler, OptionHandler
Direct Known Subclasses:
WriterHandler

public abstract class AbstractHandler
extends java.util.logging.Handler
implements Component, OptionHandler, ExtendedHandler

Abstract superclass of the other handlers in the package. This class provides the code for common functionality, such as support for threshold filtering and support for general filters. This class takes care of usage of org.x4juli.global.spi.ExtendedFilter, org.x4juli.global.spi.ExtendedFormatter, org.x4juli.global.spi.ExtendedLogRecord.

Attribute Description Required
.name Name of the handler. YES. No default, exception instead.
.level Level of the handler. Allowed valued are from java.util.logging.Level.*. No. Default ALL
.formatter Formatter of the handler. Value is the full qualified classname of the formatter. No, but recommened. Default org.x4juli.formatter.SimpleFormatter
.filter Filter of the handler. Value is the full qualified Classname of the filter. WARNING STILL UNDER DEVELOPMENT! No. Default null.

Logging API as a whole was originally done for Apache log4j. Juli is a port of main parts of that to complete the Java Logging APIs. All credits for initial idea, design, implementation, documentation belong to the log4j crew. This file was originally published by Ceki Gülcü. Please use exclusively the appropriate mailing lists for questions, remarks and contribution.

Since:
0.5
Author:
Boris Unckel

Field Summary
protected  boolean active
          Is the appender ready for action.
protected  boolean closed
          Is this appender closed?
private  int errorCount
          The component error counter.
protected  ExtendedFormatter extFormatter
          The extendedFormatter remains null if an java.util.Logging.Formatter is set.
private  boolean guard
          The guard prevents an appender from repeatedly calling its own doAppend method.
protected  ExtendedFilter headFilter
          The first @link{ExtendedFilter} in the filter chain.
private  ExtendedLogger logger
          The component logger.
protected  java.util.logging.LogManager manager
          The component logmanager.
protected  java.lang.String name
          Handlers are named.
protected  ObjectStore repository
          The component object store.
protected  ExtendedFilter tailFilter
          The last @link{ExtendedFilter} in the filter chain.
 
Fields inherited from class java.util.logging.Handler
 
Constructor Summary
protected AbstractHandler()
          Default Constructor instantiation used for configuration by file.
protected AbstractHandler(java.lang.String handlerName)
          Utility Constructor.
 
Method Summary
 void activateOptions()
          Activate the options that were previously set with calls to option setters.

This allows to defer activiation of the options until all options have been set. This is required for components which have related options that remain ambigous until all are set.
Subclasses have not set active to true, but call super as last statement!

 void addFilter(ExtendedFilter newFilter)
          Add a filter to end of the filter list.
protected abstract  void appendLogRecord(ExtendedLogRecord record)
          Subclasses of AbstractHandler should implement this method to perform actual logging.
 void clearFilters()
          Clear the filters chain.
 void configure()
          Configure all properties of the object.
protected  void finalize()
          Finalize this appender by calling the derived class' close method.
 java.util.logging.Filter getFilter()
          Returns the head filter of the filter chain.
 java.util.logging.Formatter getFormatter()
          
 java.lang.String getFullQualifiedClassName()
          Determine performant the FullQualifiedClassName. Subclasses should overwrite this method. Dynamic determination is not recommended.
protected  ExtendedLogger getLogger()
          Return an instance specific logger to be used by the component itself.
protected  ObjectStore getLoggerRepository()
          Return the ObjectStore this component is attached to.
 MessageProperties getMessageProperties()
          Specifiy Properties for the component. Default Implementation returns null.
 java.lang.String getName()
          Retrieve name of the Handler.
protected  ExtendedLogger getNonFloodingLogger()
          Frequently called methods in juli components can invoke this method in order to avoid flooding the output when logging lasting error conditions.
protected  boolean getProperty(java.lang.String propname, boolean defaultValue)
          Get an property value out of the LogManager by name.
protected  int getProperty(java.lang.String propname, int defaultValue)
          Get an property value out of the LogManager by name.
protected  java.lang.String getProperty(java.lang.String propname, java.lang.String defaultValue)
          Get an property value out of the LogManager by name.
 boolean isActive()
          Returns true if this appender is working order.
 boolean isClosed()
          Returns true if this appender instance is closed.
 boolean isLoggable(ExtendedLogRecord record)
          Checks whether a record should be logged or not. Criteria: not null, level, filter chain passed.
 boolean isLoggable(java.util.logging.LogRecord record)
          
 void publish(ExtendedLogRecord record)
          
 void publish(java.util.logging.LogRecord record)
          
protected  void resetErrorCount()
          Called by derived classes when they deem that the component has recovered from an erroneous state.
 void setFilter(java.util.logging.Filter newFilter)
          Different to the super Class, the filter is wrapped and added to the chain.
 void setFormatter(java.util.logging.Formatter newFormatter)
          
 void setName(java.lang.String name)
          Set the name of this Appender.
 void setObjectStore(ObjectStore objectstore)
          Set owning object repository for this component. This operation can only be performed once. Once set, the owning repository cannot be changed.
 java.lang.String toString()
          
 
Methods inherited from class java.util.logging.Handler
close, flush, getEncoding, getErrorManager, getLevel, reportError, setEncoding, setErrorManager, setLevel
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.x4juli.global.spi.ExtendedHandler
close, flush, getEncoding, getErrorManager, getLevel, setEncoding, setErrorManager, setLevel
 

Field Detail

repository

protected ObjectStore repository
The component object store.


manager

protected final java.util.logging.LogManager manager
The component logmanager.


headFilter

protected ExtendedFilter headFilter
The first @link{ExtendedFilter} in the filter chain. Set to null initially.


tailFilter

protected ExtendedFilter tailFilter
The last @link{ExtendedFilter} in the filter chain. Set to null initially.


closed

protected boolean closed
Is this appender closed?


active

protected boolean active
Is the appender ready for action.


name

protected java.lang.String name
Handlers are named.


extFormatter

protected ExtendedFormatter extFormatter
The extendedFormatter remains null if an java.util.Logging.Formatter is set. Then the formatter of the super class is used instead.


logger

private ExtendedLogger logger
The component logger.


errorCount

private int errorCount
The component error counter.


guard

private boolean guard
The guard prevents an appender from repeatedly calling its own doAppend method.

Constructor Detail

AbstractHandler

protected AbstractHandler()
Default Constructor instantiation used for configuration by file. This automatically activatesOptions(). Avoid in programmatically use.

Since:
0.5

AbstractHandler

protected AbstractHandler(java.lang.String handlerName)
Utility Constructor. All properties must be set programmatically. Finally you need to call actiavtesOptions().

Parameters:
handlerName - of the current instance.
Since:
0.5
Method Detail

activateOptions

public void activateOptions()
Activate the options that were previously set with calls to option setters.

This allows to defer activiation of the options until all options have been set. This is required for components which have related options that remain ambigous until all are set.
Subclasses have not set active to true, but call super as last statement!

Specified by:
activateOptions in interface OptionHandler
Since:
0.5

configure

public void configure()
Configure all properties of the object. Subclasses should call super.configure() to ensure proper configuration.

Since:
0.5

getFullQualifiedClassName

public java.lang.String getFullQualifiedClassName()
Determine performant the FullQualifiedClassName. Subclasses should overwrite this method. Dynamic determination is not recommended.

Specified by:
getFullQualifiedClassName in interface ExtendedHandler
Returns:
the FQCN
Since:
0.5

setObjectStore

public void setObjectStore(ObjectStore objectstore)
Set owning object repository for this component. This operation can only be performed once. Once set, the owning repository cannot be changed.

Specified by:
setObjectStore in interface Component
Parameters:
objectstore - The repository where the configuration is stored
Since:
0.5

getMessageProperties

public MessageProperties getMessageProperties()
Specifiy Properties for the component. Default Implementation returns null.

Specified by:
getMessageProperties in interface Component
Returns:
the key for the Properties for the component
Since:
0.5

publish

public final void publish(java.util.logging.LogRecord record)

Specified by:
publish in interface Handler
Since:
0.5

publish

public void publish(ExtendedLogRecord record)

Specified by:
publish in interface ExtendedHandler
Parameters:
record - to check and write in the log.
Since:
0.5
See Also:
publish(LogRecord)

isLoggable

public final boolean isLoggable(java.util.logging.LogRecord record)

Specified by:
isLoggable in interface Handler
Since:
0.5

isLoggable

public boolean isLoggable(ExtendedLogRecord record)
Checks whether a record should be logged or not. Criteria: not null, level, filter chain passed.

Specified by:
isLoggable in interface ExtendedHandler
Parameters:
record - the record to check.
Returns:
true if record fullfills criteria.
Since:
0.5

getFilter

public java.util.logging.Filter getFilter()
Returns the head filter of the filter chain.

Specified by:
getFilter in interface Handler
Returns:
headFilter
Since:
0.5

setFilter

public final void setFilter(java.util.logging.Filter newFilter)
                     throws java.lang.SecurityException
Different to the super Class, the filter is wrapped and added to the chain.

Specified by:
setFilter in interface Handler
Parameters:
newFilter - the filter to add
Throws:
java.lang.SecurityException - if changing the filter is not allowed.
Since:
0.5

addFilter

public void addFilter(ExtendedFilter newFilter)
Add a filter to end of the filter list.

Specified by:
addFilter in interface ExtendedHandler
Parameters:
newFilter - the filter to add
Since:
0.5

clearFilters

public void clearFilters()
Clear the filters chain.

Specified by:
clearFilters in interface ExtendedHandler
Since:
0.5

setFormatter

public final void setFormatter(java.util.logging.Formatter newFormatter)
                        throws java.lang.SecurityException

Specified by:
setFormatter in interface Handler
Throws:
java.lang.SecurityException
Since:
0.5

getFormatter

public final java.util.logging.Formatter getFormatter()

Specified by:
getFormatter in interface Handler
Since:
0.5

isClosed

public boolean isClosed()
Returns true if this appender instance is closed.

Specified by:
isClosed in interface ExtendedHandler
Since:
0.5

isActive

public boolean isActive()
Returns true if this appender is working order.

Specified by:
isActive in interface ExtendedHandler
Since:
0.5

setName

public void setName(java.lang.String name)
Set the name of this Appender.

Specified by:
setName in interface ExtendedHandler
Since:
0.5

getName

public java.lang.String getName()
Retrieve name of the Handler.

Specified by:
getName in interface ExtendedHandler
Returns:
the name of the Handler.
Since:
0.5

toString

public java.lang.String toString()

Since:
0.5

finalize

protected void finalize()
                 throws java.lang.Throwable
Finalize this appender by calling the derived class' close method.

Throws:
java.lang.Throwable
Since:
0.5

getLoggerRepository

protected ObjectStore getLoggerRepository()
Return the ObjectStore this component is attached to.

Returns:
Owning ObjectStore
Since:
0.5

resetErrorCount

protected void resetErrorCount()
Called by derived classes when they deem that the component has recovered from an erroneous state.

Since:
0.5

getLogger

protected ExtendedLogger getLogger()
Return an instance specific logger to be used by the component itself. This logger is not intended to be accessed by the end-user, hence the protected keyword.

This logger always sends output to an ConsoleHandler, which outputs to System.err

Returns:
A Logger instance.
Since:
0.5

getNonFloodingLogger

protected ExtendedLogger getNonFloodingLogger()
Frequently called methods in juli components can invoke this method in order to avoid flooding the output when logging lasting error conditions.

Returns:
a regular logger, or a NOPLogger if called too frequently.
Since:
0.5

getProperty

protected java.lang.String getProperty(java.lang.String propname,
                                       java.lang.String defaultValue)
Get an property value out of the LogManager by name.

Parameters:
propname - of the parameter to be obtained
defaultValue - if propname is not found.
Returns:
the value of the given property, if null defaultValue

getProperty

protected int getProperty(java.lang.String propname,
                          int defaultValue)
Get an property value out of the LogManager by name.

Parameters:
propname - of the parameter to be obtained
defaultValue - to return if no value has been found.
Returns:
the value of the given property, if null defaultValue

getProperty

protected boolean getProperty(java.lang.String propname,
                              boolean defaultValue)
Get an property value out of the LogManager by name.

Parameters:
propname - of the parameter to be obtained
defaultValue - to return if no value has been found.
Returns:
the value of the given property, if null defaultValue

appendLogRecord

protected abstract void appendLogRecord(ExtendedLogRecord record)
Subclasses of AbstractHandler should implement this method to perform actual logging. See also publish(ExtendedLogRecord) method.

Parameters:
record - to write to the log


${license_html}