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 String
DEFAULT_HOSTNAME
the default host.static int
DEFAULT_MAXFAILURES
the default maximum number of send failures to accept.static int
DEFAULT_PORT
the default port.protected int
m_ConnectionFailed
the number of times the connection has failed.protected String
m_Hostname
the remote host.protected long
m_LastFailureTimestamp
the last connection failure timestamp (msec).protected int
m_MaxFailures
the maximum number of failures to accept before removing itself (-1 for infinite).protected long
m_NextAttemptTimestamp
the timestamp when next to attempt a connect.protected int
m_Port
the remote port.protected Socket
m_Socket
the socket in use.static int
MAX_DOUBLE_ATTEMPT_INTERVAL
the 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 void
close()
Close the Handler and free all associated resources.int
compareTo(Handler o)
Compares the handler with itself.protected void
doPublish(LogRecord record)
Publish a LogRecord.String
getHostname()
Returns the host to send the logging data to.int
getMaxFailures()
Returns the maximum number of failures to accept.int
getPort()
Returns the port to send the logging data to.protected void
initialize()
Initializes the members.static void
main(String[] args)
Just for testing.protected void
open()
Tries to open the socket.protected void
reset()
Resets the scheme.void
setHostname(String value)
Sets the host to send the logging data to.void
setMaxFailures(int value)
Sets the maximum number of failures to accept.void
setPort(int value)
Sets the port to send the logging data to.-
Methods inherited from class adams.core.logging.AbstractLogHandler
addLoggingListener, equals, flush, 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:
initialize
in classAbstractLogHandler
-
reset
protected void reset()
Resets the scheme.- Overrides:
reset
in 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 SecurityException
Close 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:
close
in 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:
doPublish
in 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:
compareTo
in interfaceComparable<Handler>
- Overrides:
compareTo
in 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
-
-