|
copyright The Portico Project 2008. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.portico.core.MulticastRegistry
public class MulticastRegistry
This class represents a registry containing information that is made available via a multicast
channel. Generally speaking, this is Bootstrap
subclass information that can be accessed
by remote clients through multicast, thus providing some sort of automatic discovery mechanism.
For example, the org.portico.binding.jsop
bindings register the bootstrap information
with the multicast registry so that clients using JSOP can automatically discover the ip address
and port information needed to contact it.
PorticoConstants.MRR_REQUEST
. Each request is also sent with a serial number that is
used in any response (so the client can recognize the response to its request and not confuse
other responses with the information it desires).
When a request is received, the prefix is stripped off, and then the serial number is also
removed and stored. The remainder of the string is assumed to be the key for the information
the client is looking for.
An example of an incoming request package is:
"drreq:123:jsop" (1) (2) (3)Where (1) is the request prefix from
PorticoConstants.MRR_REQUEST
, (2) is the serial
number to send back with the response, and (3) is the key that the client is trying to find
associated information for.
Responses
If there is a value for the received key in the registry, a new response packet containing
the response string is sent. The structure of this is as follows:
"drresp:123:192.168.0.30:20913" (1) (2) (3)Here, (1) is the response prefix held in
PorticoConstants.MRR_RESPONSE
. Second is the
serial number that was sent with the request (so that the client can identify the packet as
the response to its particular request). (3) is the value that was associated with the key
in the registry.
Error Responses
If there is an error (such as there being no information for the key in the request), an
error packet is sent back. This package is once again a string, and its structure is:
"drrerror:123:no value for key" (1) (2) (3)In this packet, (1) is the error response header and (2) is the serial number of the request. (3) is a textual description of the problem.
Field Summary | |
---|---|
private org.apache.log4j.Logger |
logger
|
private InetAddress |
multicastGroup
|
private int |
multicastPort
|
private MulticastSocket |
multicastSocket
|
private Map<String,String> |
registry
|
private boolean |
running
|
private Thread |
workerThread
|
Constructor Summary | |
---|---|
MulticastRegistry(RTIExec rtiexec)
Creates a new multicast registry that is to be stored in the given RTIExec . |
Method Summary | |
---|---|
private String |
getRequestKey(String request)
This method is much the same as getSerialNumber(String) except that it extracts
the key from the request, not the serial number. |
private String |
getSerialNumber(String request)
Extracts the serial number from the given request string. |
boolean |
isRegistered(String key)
Returns true if there is a value for the given key, false otherwise |
boolean |
register(String key,
String value)
Register the given information under the given name with the registry. |
void |
run()
Executes a loop listening for incoming requests and answering back with the appropriate information. |
void |
shutdown()
This method shuts down the multicast registry. |
void |
startup()
Start the multicast registry. |
String |
unregister(String key)
Unregister the information for the given key. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private org.apache.log4j.Logger logger
private volatile boolean running
private Map<String,String> registry
private int multicastPort
private InetAddress multicastGroup
private MulticastSocket multicastSocket
private Thread workerThread
Constructor Detail |
---|
public MulticastRegistry(RTIExec rtiexec)
RTIExec
. No
reference to the RTI is kept, it is just used to create a logger with the appropriate RTI
execution name in it.
Once created, the registry still needs to be started
and
stopped
.
Method Detail |
---|
public boolean register(String key, String value)
false
returned. If the
registration is successful, true
will be returned.
public String unregister(String key)
public boolean isRegistered(String key)
public void startup()
public void shutdown()
public void run()
MulticastRegistry
for a description
of the formatting involved in the various packets.
run
in interface Runnable
private String getSerialNumber(String request) throws IllegalArgumentException
IllegalArgumentException
private String getRequestKey(String request) throws IllegalArgumentException
getSerialNumber(String)
except that it extracts
the key from the request, not the serial number.
IllegalArgumentException
|
copyright The Portico Project 2008. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |