Class 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 Detail

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

      • RemoteSendHandler

        public RemoteSendHandler()
    • Method Detail

      • 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 class AbstractLogHandler
        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 class AbstractLogHandler
        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 interface Comparable<Handler>
        Overrides:
        compareTo in class AbstractLogHandler
        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