|
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.lrc.LRCConnection
org.portico.binding.jsop.lrc.JSOPClientConnection
public class JSOPClientConnection
This class is responsible for creating and managing a connection between the LRC and RTI using the JSOP "protocol".
The JSOP protocol isn't anything special. It stands for "Java Serialized Object Protocol" and basically just consists of throwing serialized objects back-and-forth over a socket connection. When the connection is asked to send a message, it extracts the request portion and writes it down the socket (seesendMessage(MessageContext)
). The entire context isn't written
for efficiency reasons.
This connection will also start a listener thread, that will sit and wait for any communication
the RTI has to give. See the run()
method for more information on this process.
Information about the location of the RTI can be either automatically discovered, or provided
through the PROP_HOST
system property.
Field Summary | |
---|---|
private Socket |
daemonSocket
|
private static String |
DEFAULT_HOST
|
private ObjectInputStream |
fromRTI
|
private BlockingQueue<com.lbf.commons.messaging.ResponseMessage> |
handoffQueue
|
private String |
host
|
private Thread |
listenerThread
|
private static String |
PROP_HOST
The sys property that will be used to find the RTI-host to connect to. |
private ObjectOutputStream |
toRTI
|
Fields inherited from class org.portico.lrc.LRCConnection |
---|
logger, lrc |
Constructor Summary | |
---|---|
JSOPClientConnection()
|
Method Summary | |
---|---|
void |
close()
This method will close the connection to the RTI and kill the active thread that is processing incoming messages. |
void |
configure(com.lbf.commons.utils.Bag<String,?> properties)
Extracts the host it should connect to from the PROP_HOST key
in the properties (with a default of DEFAULT_HOST ). |
private Socket |
connectToHost(String theHost)
This method will attempt to open a JSOP connection to an RTI using the information in the given parameter. |
private Socket |
directConnect(String host,
int port)
Create a direct socket connection to the appropriate bootstrap running on the RTI-side. |
private Socket |
discoverRTI(int port)
Discovers the location and port of the RTI using the MulticastLookup class. |
void |
run()
As messages could come in from the RTI at any point, this method should be started in a new Thread to sit and listen for any communications. |
void |
sendMessage(com.lbf.commons.messaging.MessageContext message)
Sends the message to the RTI by writing the request to the outgoing stream. |
void |
startup()
This method will connect to the RTI and set up the input and output streams that communication will flow over. |
Methods inherited from class org.portico.lrc.LRCConnection |
---|
receiveCallback, receiveCallback |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final String PROP_HOST
private static final String DEFAULT_HOST
private String host
private Socket daemonSocket
private ObjectOutputStream toRTI
private ObjectInputStream fromRTI
private Thread listenerThread
private BlockingQueue<com.lbf.commons.messaging.ResponseMessage> handoffQueue
Constructor Detail |
---|
public JSOPClientConnection()
Method Detail |
---|
public void configure(com.lbf.commons.utils.Bag<String,?> properties) throws com.lbf.commons.config.ConfigurationException
PROP_HOST
key
in the properties (with a default of DEFAULT_HOST
).
configure
in class LRCConnection
com.lbf.commons.config.ConfigurationException
public void startup() throws JRTIinternalError
run()
method for information on what
happens inside it.
startup
in class LRCConnection
JRTIinternalError
public void close() throws JRTIinternalError
close
in class LRCConnection
JRTIinternalError
public void run()
run
in interface Runnable
public void sendMessage(com.lbf.commons.messaging.MessageContext message) throws JRTIinternalError
run()
for more info). When it has the response, it throws it into the
context and returns.
sendMessage
in class LRCConnection
JRTIinternalError
private Socket connectToHost(String theHost) throws JRTIinternalError
null
: The location of the RTI will be discovered via a multicast request
on the default port (as defined in JSOPConstants.DEFAULT_PORT
.1234
: 1234 is assumed to be the port number to use when sending a
multicast discovery request. This can be any number (not just 1234) as long as you are
expecting an RTI to be listening for multicast requests on that port.192.168.0.1
: Where the value is an IP address, it is assumed to be the
address of the RTI. A direct connection to the JSOP listener running in the RTI will be
made on the default port (as defined in JSOPConstants.DEFAULT_PORT
.192.168.0.1:1234
: Attempt to make a direct connection to the RTI via
JSOP on the given IP and port.
JRTIinternalError
private Socket discoverRTI(int port) throws JRTIinternalError
MulticastLookup
class. It will
then connect to the RTI and return a socket ready for use. The actual connection is made by
the directConnect(String, int)
method once the relevant location has been found.
Discovers the location and port of the RTI using the JSOP multicast discovery mechanism.
JRTIinternalError
private Socket directConnect(String host, int port) throws JRTIinternalError
JRTIinternalError
|
copyright The Portico Project 2008. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |