public class RCServer extends cMsgDomainAdapter
Modifier and Type | Field and Description |
---|---|
(package private) int |
localUdpPort
UDP port on which to receive messages from the rc client.
|
(package private) java.util.concurrent.ConcurrentHashMap<java.lang.Integer,cMsgGetHelper> |
sendAndGets
Collection of all of this client's
sendAndGet(cMsgMessage, int)
calls currently in execution. |
(package private) java.util.concurrent.ConcurrentHashMap<java.lang.Integer,cMsgSubscription> |
subscribeAndGets
Collection of all of this client's
subscribeAndGet(String, String, int)
calls currently in execution. |
(package private) java.util.Set<cMsgSubscription> |
subscriptions
Collection of all of this client's message subscriptions which are
cMsgSubscription objects. |
connected, debug, description, domain, host, name, receiving, shutdownHandler, UDL, UDLremainder
Constructor and Description |
---|
RCServer()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
This method results in this object
becoming functionally useless.
|
void |
connect()
Method to connect to the rc client from this server.
|
void |
disconnect()
Method to close the connection to the rc client.
|
java.lang.String |
getString()
Returns a string back to the top level API user indicating the host
and port of the client that this server is communicating with.
|
static void |
main(java.lang.String[] args)
Run as a stand-alone RC server to test incoming messages.
|
void |
send(cMsgMessage message)
Method to send a message/command to the rc client.
|
cMsgMessage |
sendAndGet(cMsgMessage message,
int timeout)
The message is sent as it would be in the
send(org.jlab.coda.cMsg.cMsgMessage) method except that the
senderToken and creator are set. |
void |
setUDL(java.lang.String UDL)
Set the UDL of the client which may be a semicolon separated
list of (sub)UDLs in this domain.
|
cMsgSubscriptionHandle |
subscribe(java.lang.String subject,
java.lang.String type,
cMsgCallbackInterface cb,
java.lang.Object userObj)
This is a method to subscribe to receive messages of a subject and type from the rc client.
|
cMsgMessage |
subscribeAndGet(java.lang.String subject,
java.lang.String type,
int timeout)
This method is like a one-time subscribe.
|
int |
syncSend(cMsgMessage message,
int timeout)
Method to send a "ping" command to the rc client.
|
void |
testConnect()
Method for testing rc client communications with this test server.
|
cMsgSubscriptionHandle |
testSubscribe(java.lang.String subject,
java.lang.String type,
cMsgCallbackInterface cb,
java.lang.Object userObj)
This is a method to subscribe to receive messages
of a subject and type from the test rc client.
|
void |
unsubscribe(cMsgSubscriptionHandle obj)
Method to unsubscribe a previous subscription.
|
flush, getCurrentUDL, getDebug, getDescription, getDomain, getHost, getInfo, getName, getServerHost, getServerPort, getShutdownHandler, getUDL, getUDLRemainder, isConnected, isReceiving, monitor, setDebug, setDescription, setName, setShutdownHandler, setUDLRemainder, shutdownClients, shutdownServers, start, stop
int localUdpPort
java.util.Set<cMsgSubscription> subscriptions
cMsgSubscription
objects. This set is synchronized.java.util.concurrent.ConcurrentHashMap<java.lang.Integer,cMsgSubscription> subscribeAndGets
subscribeAndGet(String, String, int)
calls currently in execution.
SubscribeAndGets are very similar to subscriptions and can be thought of as
one-shot subscriptions.
Key is receiverSubscribeId object, value is cMsgSubscription
object.java.util.concurrent.ConcurrentHashMap<java.lang.Integer,cMsgGetHelper> sendAndGets
sendAndGet(cMsgMessage, int)
calls currently in execution.
Key is senderToken object, value is cMsgGetHelper
object.public RCServer() throws cMsgException
cMsgException
- if cannot find host name.public java.lang.String getString()
public void setUDL(java.lang.String UDL) throws cMsgException
setUDL
in interface cMsgDomainInterface
setUDL
in class cMsgDomainAdapter
UDL
- UDL of clientcMsgException
- if UDL is null or no valid UDL existspublic void connect() throws cMsgException
connect
in interface cMsgDomainInterface
connect
in class cMsgDomainAdapter
cMsgException
- if there are problems parsing the UDL,
communication problems with the client,
or cannot start up a TCP listening threadpublic void testConnect()
public static void main(java.lang.String[] args)
args
- arguments.public cMsgSubscriptionHandle testSubscribe(java.lang.String subject, java.lang.String type, cMsgCallbackInterface cb, java.lang.Object userObj)
subject
- type
- cb
- userObj
- public void close()
public void disconnect()
disconnect
in interface cMsgDomainInterface
disconnect
in class cMsgDomainAdapter
public void send(cMsgMessage message) throws cMsgException
send
in interface cMsgDomainInterface
send
in class cMsgDomainAdapter
message
- message to sendcMsgException
- if there are communication problems with the server;
text is null or blankpublic int syncSend(cMsgMessage message, int timeout) throws cMsgException
syncSend
in interface cMsgDomainInterface
syncSend
in class cMsgDomainAdapter
message
- message to sendtimeout
- ignoredcMsgException
- if there is a timeoutpublic cMsgSubscriptionHandle subscribe(java.lang.String subject, java.lang.String type, cMsgCallbackInterface cb, java.lang.Object userObj) throws cMsgException
subscribe
in interface cMsgDomainInterface
subscribe
in class cMsgDomainAdapter
subject
- message subjecttype
- message typecb
- callback object whose single method is called upon receiving a message
of subject and typeuserObj
- any user-supplied object to be given to the callback method as an argumentcMsgException
- if the subject, type, or callback is null;
an identical subscription already exists;
if not connected to an rc clientpublic void unsubscribe(cMsgSubscriptionHandle obj) throws cMsgException
unsubscribe
in interface cMsgDomainInterface
unsubscribe
in class cMsgDomainAdapter
obj
- the object returned from a subscribe callcMsgException
- if there is no connection with the rc client; obj is nullpublic cMsgMessage subscribeAndGet(java.lang.String subject, java.lang.String type, int timeout) throws cMsgException, java.util.concurrent.TimeoutException
subscribeAndGet
in interface cMsgDomainInterface
subscribeAndGet
in class cMsgDomainAdapter
subject
- subject of message desired from servertype
- type of message desired from servertimeout
- time in milliseconds to wait for a messagecMsgException
- if there are communication problems with rc client;
subject and/or type is null or blankjava.util.concurrent.TimeoutException
- if timeout occurspublic cMsgMessage sendAndGet(cMsgMessage message, int timeout) throws cMsgException, java.util.concurrent.TimeoutException
send(org.jlab.coda.cMsg.cMsgMessage)
method except that the
senderToken and creator are set. A marked response can be received from a client
regardless of its subject or type.
NOTE: Disconnecting when one thread is in the waiting part of a sendAndGet may cause that
thread to block forever. It is best to always use a timeout with sendAndGet so the thread
is assured of eventually resuming execution.sendAndGet
in interface cMsgDomainInterface
sendAndGet
in class cMsgDomainAdapter
message
- message sent to clienttimeout
- time in milliseconds to wait for a response message, zero means wait forever.cMsgException
- if there are communication problems with the client;
subject and/or type is null or blankjava.util.concurrent.TimeoutException
- if timeout occurs