Package adams.core.logging
Class RemoteReceiveHandler
- java.lang.Object
-
- java.util.logging.Handler
-
- adams.core.logging.AbstractLogHandler
-
- adams.core.logging.AbstractEnhancingSingleHandler
-
- adams.core.logging.RemoteReceiveHandler
-
- All Implemented Interfaces:
EnhancingSingleHandler
,Comparable<Handler>
public class RemoteReceiveHandler extends AbstractEnhancingSingleHandler
Waits for log records from a remote sender.- Author:
- FracPete (fracpete at waikato dot ac dot nz)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RemoteReceiveHandler.AbstractRemoteListenerRunnable
Ancestor for remote listeners.static class
RemoteReceiveHandler.RemoteListenerRunnableUsingHandler
Publishes the logging records using the supplied handler.
-
Field Summary
Fields Modifier and Type Field Description protected int
m_Port
the port to listen to.protected RemoteReceiveHandler.AbstractRemoteListenerRunnable
m_Runnable
the runnable in use.protected int
m_TimeOut
the timeout to use (msec).-
Fields inherited from class adams.core.logging.AbstractEnhancingSingleHandler
m_Handler
-
Fields inherited from class adams.core.logging.AbstractLogHandler
m_LoggingListeners, m_LogUsed
-
-
Constructor Summary
Constructors Constructor Description RemoteReceiveHandler()
-
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.protected Handler
getDefaultHandler()
Returns the default handler.int
getPort()
Returns the port to listen for data.int
getTimeOut()
Returns the timeout (in msec) for accepting connections.protected void
initialize()
Initializes the members.static void
main(String[] args)
Just for testing.void
setPort(int value)
Sets the port to listen for data.void
setTimeOut(int value)
Sets the timeout (in msec) for accepting connections.boolean
startListening()
Tries to start listing to the port.void
stopListening()
Stops the listening.-
Methods inherited from class adams.core.logging.AbstractEnhancingSingleHandler
getHandler, setHandler
-
Methods inherited from class adams.core.logging.AbstractLogHandler
addLoggingListener, equals, flush, iterator, loggingListeners, notifyLoggingListeners, postPublish, publish, removeLoggingListener, removeLoggingListeners, reset, setUp
-
Methods inherited from class java.util.logging.Handler
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError, setEncoding, setErrorManager, setFilter, setFormatter, setLevel
-
-
-
-
Field Detail
-
m_Port
protected int m_Port
the port to listen to.
-
m_TimeOut
protected int m_TimeOut
the timeout to use (msec).
-
m_Runnable
protected RemoteReceiveHandler.AbstractRemoteListenerRunnable m_Runnable
the runnable in use.
-
-
Method Detail
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in classAbstractEnhancingSingleHandler
-
getDefaultHandler
protected Handler getDefaultHandler()
Returns the default handler.- Specified by:
getDefaultHandler
in classAbstractEnhancingSingleHandler
- Returns:
- the default
-
setPort
public void setPort(int value)
Sets the port to listen for data.- Parameters:
value
- the port
-
getPort
public int getPort()
Returns the port to listen for data.- Returns:
- the port
-
setTimeOut
public void setTimeOut(int value)
Sets the timeout (in msec) for accepting connections.- Parameters:
value
- the timeout (in msec)
-
getTimeOut
public int getTimeOut()
Returns the timeout (in msec) for accepting connections.- Returns:
- the timeout (in msec)
-
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").
-
startListening
public boolean startListening()
Tries to start listing to the port.- Returns:
- true if successfully started
-
stopListening
public void stopListening()
Stops the listening.- See Also:
close()
-
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 supplying port and timeout
-
-