|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.core.signal.AbstractSignalReceiver net.sf.basedb.core.signal.SocketSignalReceiver
public class SocketSignalReceiver
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:
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.
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.
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:
Before the message is forwarded it is re-built like this:
If no signal://handlerID@host:port/?SIGNAL#forward.to.host:port
signal://handlerId@forward.to.host:port/?SIGNAL
allow
parts are the ip name or numbers of hosts that are
allowed to send signals to the receiver. Except for the special case
allow=*
, which allows any remote host to send signals an
exact match is required. The local host is always allowed to send signals.
allow
tags are given only allow connections from the
local host (and the proxy if given) are allowed.
Nested Class Summary | |
---|---|
private class |
SocketSignalReceiver.ListenerThread
This class is used for listening to the specified socket for incoming connections. |
Field Summary | |
---|---|
private Set<InetAddress> |
allow
|
private boolean |
allowAll
|
private boolean |
allowForward
|
private InetAddress |
ip
|
private Thread |
listener
|
private static Logger |
logger
Log signals processing. |
private int |
port
|
private String |
proxy
|
Constructor Summary | |
---|---|
SocketSignalReceiver()
Create a new socket signal receiver. |
Method Summary | |
---|---|
void |
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> |
getSignalTransporterClass()
Get the signal transporter class that should be used to send signals to this receiver. |
void |
init(String params)
Initialise the receiver. |
protected boolean |
isAllowedHost(InetAddress remoteHost)
Checks if the specified remote host is allowed to send signals to this receiver. |
protected void |
listenOnSocket()
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, sendToAll, unregisterSignalHandler |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final Logger logger
private InetAddress ip
private Thread listener
private int port
private String proxy
private boolean allowForward
private Set<InetAddress> allow
private boolean allowAll
Constructor Detail |
---|
public SocketSignalReceiver()
init(String)
.
Method Detail |
---|
public void init(String params)
init
in interface SignalReceiver
init
in class AbstractSignalReceiver
params
- The ID of the signal receiver, needed if the default
ID generation should be usedpublic Class<? extends SignalTransporter> getSignalTransporterClass()
SignalReceiver
SocketSignalTransporter
public void close(int wait)
close
in interface SignalReceiver
close
in class AbstractSignalReceiver
wait
- Number of milliseconds to wait for registered jobs to abort,
use a negative value to disable notification, and 0 to disable waitingprotected String getGlobalSignalId(SignalHandler handler)
getGlobalSignalId
in class AbstractSignalReceiver
handler
- The signal handler to generate the ID for
protected void processSignalMessage(String message)
processSignalMessage
in class AbstractSignalReceiver
message
- The message to process, the format of the message
must be compatible with the message that AbstractSignalTransporter.generateSignalMessage(Signal)
generatesprotected void parseInitParameters(String params)
init(String)
method.
params
- Parameter string passed to init(String)
methodprotected void listenOnSocket()
protected boolean forwardSignalMessageIfNeeded(String message)
protected boolean isAllowedHost(InetAddress remoteHost)
remoteHost
- The remote host that is sending the signal
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |