3.3.3: 2014-11-17
net.sf.basedb.core.signal

Class SocketSignalReceiver

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class and Description
      private class  SocketSignalReceiver.ListenerThread
      This class is used for listening to the specified socket for incoming connections.
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      private java.util.Set<java.net.InetAddress> allow 
      private boolean allowAll 
      private boolean allowForward 
      private java.net.InetAddress ip 
      private java.lang.Thread listener 
      private static org.slf4j.Logger logger
      Log signals processing.
      private int port 
      private java.lang.String proxy 
    • Constructor Summary

      Constructors 
      Constructor and Description
      SocketSignalReceiver()
      Create a new socket signal receiver.
    • Field Detail

      • logger

        private static final org.slf4j.Logger logger
        Log signals processing.
      • ip

        private java.net.InetAddress ip
      • listener

        private java.lang.Thread listener
      • port

        private int port
      • proxy

        private java.lang.String proxy
      • allowForward

        private boolean allowForward
      • allow

        private java.util.Set<java.net.InetAddress> allow
      • allowAll

        private boolean allowAll
    • Constructor Detail

      • SocketSignalReceiver

        public SocketSignalReceiver()
        Create a new socket signal receiver. Before it can be used it must be initialised with init(String).
    • Method Detail

      • init

        public void init(java.lang.String params)
        Initialise the receiver. The given parameter should be the port number the receiver should listen on. If the parameter can't be parsed as a numeric value, a random free port will be used. This method will open the socket and start a separate thread that listens for incoming signals.
        Specified by:
        init in interface SignalReceiver
        Overrides:
        init in class AbstractSignalReceiver
        Parameters:
        params - The ID of the signal receiver, needed if the default ID generation should be used
      • getSignalTransporterClass

        public java.lang.Class<? extends SignalTransporter> getSignalTransporterClass()
        Description copied from interface: SignalReceiver
        Get the signal transporter class that should be used to send signals to this receiver.
        Returns:
        SocketSignalTransporter
      • close

        public void close(int wait)
        Close this receiver and the socket it is listening on.
        Specified by:
        close in interface SignalReceiver
        Overrides:
        close in class AbstractSignalReceiver
        Parameters:
        wait - Number of milliseconds to wait for registered jobs to abort, use a negative value to disable notification, and 0 to disable waiting
      • getGlobalSignalId

        protected java.lang.String getGlobalSignalId(SignalHandler handler)
        Override ID generation so we can add proxy information if needed.
        Overrides:
        getGlobalSignalId in class AbstractSignalReceiver
        Parameters:
        handler - The signal handler to generate the ID for
        Returns:
        The signal handler ID
      • processSignalMessage

        protected void processSignalMessage(java.lang.String message)
        Process the incoming message. This class will check if the message contains any forwarding information. If so, the message will be forwarde to the new destination. Otherwise, the message will be processed as normal.
        Overrides:
        processSignalMessage in class AbstractSignalReceiver
        Parameters:
        message - The message to process, the format of the message must be compatible with the message that AbstractSignalTransporter.generateSignalMessage(Signal) generates
      • parseInitParameters

        protected void parseInitParameters(java.lang.String params)
        Parse the initialisation parameters. Called from the init(String) method.
        Parameters:
        params - Parameter string passed to init(String) method
      • listenOnSocket

        protected void listenOnSocket()
        Start listening for incoming signals.
      • forwardSignalMessageIfNeeded

        protected boolean forwardSignalMessageIfNeeded(java.lang.String message)
        If the message has forwarding information, forward the message to the other host.
        Returns:
        TRUE if the message was forwarded, FALSE otherwise
      • isAllowedHost

        protected boolean isAllowedHost(java.net.InetAddress remoteHost)
        Checks if the specified remote host is allowed to send signals to this receiver.
        Parameters:
        remoteHost - The remote host that is sending the signal
        Returns:
        TRUE if the host is allowed, FALSE otherwise
3.3.3: 2014-11-17