Package net.sf.basedb.core.signal
Class SocketSignalReceiver
java.lang.Object
net.sf.basedb.core.signal.AbstractSignalReceiver
net.sf.basedb.core.signal.SocketSignalReceiver
- All Implemented Interfaces:
SignalReceiver
- Direct Known Subclasses:
AgentSignalReceiver
A signal receiver implementation that listens on a socket for incoming signals.
Accordingly, this receiver supports sending signals between different virtual
machines running on different servers. The initialisation string for this
class should be of the format:
port=xx&proxy=host:port&forward=xx&allow=ip-address&allow=ip-address...
where:
-
The
port
is the port number the signal receiver will listen on. This is optional and if not given a random non-used port will be used. -
The
proxy
is the address of a proxy host that will route incoming messages to this signal receiver. The proxy will automatically be added to the list of allowed hosts. This value is optional. -
The
forward
attribute is a boolean option (1 or 0). If 1, this signal receiver will act as a proxy and forward signal messages which are of the form:signal://handlerID@host:port/?SIGNAL#forward.to.host:port
Before the message is forwarded it is re-built like this:
signal://handlerId@forward.to.host:port/?SIGNAL
-
The
allow
parts are the ip name or numbers of hosts that are allowed to send signals to the receiver. Except for the special caseallow=*
, which allows any remote host to send signals an exact match is required. The local host is always allowed to send signals.If no
allow
tags are given only allow connections from the local host (and the proxy if given) are allowed.
- Version:
- 2.6
- Author:
- nicklas
- Last modified
- $Date: 2015-05-12 11:27:08 +0200 (ti, 12 maj 2015) $
-
Nested Class Summary
Modifier and TypeClassDescriptionprivate class
This class is used for listening to the specified socket for incoming connections. -
Field Summary
Modifier and TypeFieldDescriptionprivate Set<InetAddress>
private boolean
private boolean
private InetAddress
private Thread
private static final Logger
Log signals processing.private int
private String
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close
(int wait) Close this receiver and the socket it is listening on.protected boolean
forwardSignalMessageIfNeeded
(String message) If the message has forwarding information, forward the message to the other host.protected String
getGlobalSignalId
(SignalHandler handler) Override ID generation so we can add proxy information if needed.Class<? extends SignalTransporter>
Get the signal transporter class that should be used to send signals to this receiver.void
Initialise the receiver.protected boolean
isAllowedHost
(InetAddress remoteHost) Checks if the specified remote host is allowed to send signals to this receiver.protected void
Start listening for incoming signals.protected void
parseInitParameters
(String params) Parse the initialisation parameters.protected void
processSignalMessage
(String message) Process the incoming message.Methods inherited from class net.sf.basedb.core.signal.AbstractSignalReceiver
getLocalSignalHandlerId, getReceiverId, getSignalHandler, registerSignalHandler, sendToAll, unregisterSignalHandler
-
Field Details
-
logger
Log signals processing. -
ip
-
listener
-
port
private int port -
proxy
-
allowForward
private boolean allowForward -
allow
-
allowAll
private boolean allowAll
-
-
Constructor Details
-
SocketSignalReceiver
public SocketSignalReceiver()Create a new socket signal receiver. Before it can be used it must be initialised withinit(String)
.
-
-
Method Details
-
init
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 interfaceSignalReceiver
- Overrides:
init
in classAbstractSignalReceiver
- Parameters:
params
- The ID of the signal receiver, needed if the default ID generation should be used
-
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 interfaceSignalReceiver
- Overrides:
close
in classAbstractSignalReceiver
- 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
Override ID generation so we can add proxy information if needed.- Overrides:
getGlobalSignalId
in classAbstractSignalReceiver
- Parameters:
handler
- The signal handler to generate the ID for- Returns:
- The signal handler ID
-
processSignalMessage
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 classAbstractSignalReceiver
- Parameters:
message
- The message to process, the format of the message must be compatible with the message thatAbstractSignalTransporter.generateSignalMessage(Signal)
generates
-
parseInitParameters
Parse the initialisation parameters. Called from theinit(String)
method.- Parameters:
params
- Parameter string passed toinit(String)
method
-
listenOnSocket
protected void listenOnSocket()Start listening for incoming signals. -
forwardSignalMessageIfNeeded
If the message has forwarding information, forward the message to the other host.- Returns:
- TRUE if the message was forwarded, FALSE otherwise
-
isAllowedHost
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
-