Package adams.core.logging
Class RemoteSendHandler
- java.lang.Object
-
- java.util.logging.Handler
-
- adams.core.logging.AbstractLogHandler
-
- adams.core.logging.RemoteSendHandler
-
- All Implemented Interfaces:
Comparable<Handler>
public class RemoteSendHandler extends AbstractLogHandler
Sends the log records to the specified host/port.- Author:
- FracPete (fracpete at waikato dot ac dot nz)
-
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_HOSTNAMEthe default host.static intDEFAULT_MAXFAILURESthe default maximum number of send failures to accept.static intDEFAULT_PORTthe default port.protected intm_ConnectionFailedthe number of times the connection has failed.protected Stringm_Hostnamethe remote host.protected longm_LastFailureTimestampthe last connection failure timestamp (msec).protected intm_MaxFailuresthe maximum number of failures to accept before removing itself (-1 for infinite).protected longm_NextAttemptTimestampthe timestamp when next to attempt a connect.protected intm_Portthe remote port.protected Socketm_Socketthe socket in use.static intMAX_DOUBLE_ATTEMPT_INTERVALthe maximum number of times doubling up the attempt interval (7: 2^7 = 64s).-
Fields inherited from class adams.core.logging.AbstractLogHandler
m_LoggingListeners, m_LogUsed
-
-
Constructor Summary
Constructors Constructor Description RemoteSendHandler()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close the Handler and free all associated resources.intcompareTo(Handler o)Compares the handler with itself.protected voiddoPublish(LogRecord record)Publish a LogRecord.StringgetHostname()Returns the host to send the logging data to.intgetMaxFailures()Returns the maximum number of failures to accept.intgetPort()Returns the port to send the logging data to.protected voidinitialize()Initializes the members.static voidmain(String[] args)Just for testing.protected voidopen()Tries to open the socket.protected voidreset()Resets the scheme.voidsetHostname(String value)Sets the host to send the logging data to.voidsetMaxFailures(int value)Sets the maximum number of failures to accept.voidsetPort(int value)Sets the port to send the logging data to.-
Methods inherited from class adams.core.logging.AbstractLogHandler
addLoggingListener, equals, flush, isSetUp, iterator, loggingListeners, notifyLoggingListeners, postPublish, publish, removeLoggingListener, removeLoggingListeners, setUp
-
Methods inherited from class java.util.logging.Handler
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError, setEncoding, setErrorManager, setFilter, setFormatter, setLevel
-
-
-
-
Field Detail
-
DEFAULT_HOSTNAME
public static final String DEFAULT_HOSTNAME
the default host.- See Also:
- Constant Field Values
-
DEFAULT_PORT
public static final int DEFAULT_PORT
the default port.- See Also:
- Constant Field Values
-
DEFAULT_MAXFAILURES
public static final int DEFAULT_MAXFAILURES
the default maximum number of send failures to accept.- See Also:
- Constant Field Values
-
MAX_DOUBLE_ATTEMPT_INTERVAL
public static final int MAX_DOUBLE_ATTEMPT_INTERVAL
the maximum number of times doubling up the attempt interval (7: 2^7 = 64s).- See Also:
- Constant Field Values
-
m_Hostname
protected String m_Hostname
the remote host.
-
m_Port
protected int m_Port
the remote port.
-
m_MaxFailures
protected int m_MaxFailures
the maximum number of failures to accept before removing itself (-1 for infinite).
-
m_Socket
protected Socket m_Socket
the socket in use.
-
m_ConnectionFailed
protected int m_ConnectionFailed
the number of times the connection has failed.
-
m_LastFailureTimestamp
protected long m_LastFailureTimestamp
the last connection failure timestamp (msec).
-
m_NextAttemptTimestamp
protected long m_NextAttemptTimestamp
the timestamp when next to attempt a connect.
-
-
Method Detail
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initializein classAbstractLogHandler
-
reset
protected void reset()
Resets the scheme.- Overrides:
resetin classAbstractLogHandler
-
setHostname
public void setHostname(String value)
Sets the host to send the logging data to.- Parameters:
value- the host
-
getHostname
public String getHostname()
Returns the host to send the logging data to.- Returns:
- the host
-
setPort
public void setPort(int value)
Sets the port to send the logging data to.- Parameters:
value- the port
-
getPort
public int getPort()
Returns the port to send the logging data to.- Returns:
- the port
-
setMaxFailures
public void setMaxFailures(int value)
Sets the maximum number of failures to accept.- Parameters:
value- the maximum, -1 for infinite tries
-
getMaxFailures
public int getMaxFailures()
Returns the maximum number of failures to accept.- Returns:
- the maximum, -1 for infinite tries
-
close
public void close() throws SecurityExceptionClose the Handler and free all associated resources.The close method will perform a flush and then close the Handler. After close has been called this Handler should no longer be used. Method calls may either be silently ignored or may throw runtime exceptions.
- Overrides:
closein classAbstractLogHandler- Throws:
SecurityException- if a security manager exists and if the caller does not have LoggingPermission("control").
-
open
protected void open()
Tries to open the socket.
-
doPublish
protected void doPublish(LogRecord record)
Publish a LogRecord.The logging request was made initially to a Logger object, which initialized the LogRecord and forwarded it here.
The Handler is responsible for formatting the message, when and if necessary. The formatting should include localization.
- Specified by:
doPublishin classAbstractLogHandler- Parameters:
record- description of the log event. A null record is silently ignored and is not published
-
compareTo
public int compareTo(Handler o)
Compares the handler with itself.- Specified by:
compareToin interfaceComparable<Handler>- Overrides:
compareToin classAbstractLogHandler- Parameters:
o- the other handler- Returns:
- less than 0, equal to 0, or greater than 0 if the handler is less, equal to, or greater than this one
-
main
public static void main(String[] args)
Just for testing.- Parameters:
args- optionally supply host and port
-
-