org.jlab.coda.cMsg.RCServerDomain
Class RCServer

java.lang.Object
  extended by org.jlab.coda.cMsg.cMsgDomainAdapter
      extended by org.jlab.coda.cMsg.RCServerDomain.RCServer
All Implemented Interfaces:
cMsgDomainInterface

public class RCServer
extends cMsgDomainAdapter

This class implements the runcontrol server (rcs) domain.

Version:
1.0
Author:
Carl Timmer

Field Summary
 
Fields inherited from class org.jlab.coda.cMsg.cMsgDomainAdapter
connected, description, domain, host, name, receiving, shutdownHandler, UDL, UDLremainder
 
Constructor Summary
RCServer()
          Constructor.
 
Method Summary
 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 name of the client that this server is communicating with.
 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.
 java.lang.Object 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.
 void unsubscribe(java.lang.Object obj)
          Method to unsubscribe a previous subscription.
 
Methods inherited from class org.jlab.coda.cMsg.cMsgDomainAdapter
flush, getDescription, getDomain, getHost, getName, getShutdownHandler, getUDL, getUDLRemainder, isConnected, isReceiving, monitor, setDescription, setName, setShutdownHandler, setUDL, setUDLRemainder, shutdownClients, shutdownServers, start, stop, syncSend
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RCServer

public RCServer()
         throws cMsgException
Constructor.

Throws:
cMsgException
Method Detail

getString

public java.lang.String getString()
Returns a string back to the top level API user indicating the name of the client that this server is communicating with.

Specified by:
getString in interface cMsgDomainInterface
Overrides:
getString in class cMsgDomainAdapter
Returns:
name of client

connect

public void connect()
             throws cMsgException
Method to connect to the rc client from this server.

Specified by:
connect in interface cMsgDomainInterface
Overrides:
connect in class cMsgDomainAdapter
Throws:
cMsgException - if there are problems parsing the UDL, communication problems with the client, or cannot start up a TCP listening thread

disconnect

public void disconnect()
Method to close the connection to the rc client. This method results in this object becoming functionally useless.

Specified by:
disconnect in interface cMsgDomainInterface
Overrides:
disconnect in class cMsgDomainAdapter

send

public void send(cMsgMessage message)
          throws cMsgException
Method to send a message/command to the rc client. The command is sent as a string in the message's text field.

Specified by:
send in interface cMsgDomainInterface
Overrides:
send in class cMsgDomainAdapter
Parameters:
message - message to send
Throws:
cMsgException - if there are communication problems with the server; text is null or blank

subscribe

public java.lang.Object subscribe(java.lang.String subject,
                                  java.lang.String type,
                                  cMsgCallbackInterface cb,
                                  java.lang.Object userObj)
                           throws cMsgException
This is a method to subscribe to receive messages of a subject and type from the rc client. The combination of arguments must be unique. In other words, only 1 subscription is allowed for a given set of subject, type, callback, and userObj. If the subject and type are both null, a "default" subscription is made, meaning any received messages which do not match any other subscription are given to the default subscription.

Specified by:
subscribe in interface cMsgDomainInterface
Overrides:
subscribe in class cMsgDomainAdapter
Parameters:
subject - message subject
type - message type
cb - callback object whose single method is called upon receiving a message of subject and type
userObj - any user-supplied object to be given to the callback method as an argument
Returns:
handle object to be used for unsubscribing
Throws:
cMsgException - if the callback is null; an identical subscription already exists; if not connected to an rc client

unsubscribe

public void unsubscribe(java.lang.Object obj)
                 throws cMsgException
Method to unsubscribe a previous subscription.

Specified by:
unsubscribe in interface cMsgDomainInterface
Overrides:
unsubscribe in class cMsgDomainAdapter
Parameters:
obj - the object "handle" returned from a subscribe call
Throws:
cMsgException - if there is no connection with the rc client; obj is null

subscribeAndGet

public cMsgMessage subscribeAndGet(java.lang.String subject,
                                   java.lang.String type,
                                   int timeout)
                            throws cMsgException,
                                   java.util.concurrent.TimeoutException
This method is like a one-time subscribe. The rc server grabs the first incoming message of the requested subject and type and sends that to the caller. NOTE: Disconnecting when one thread is in the waiting part of a subscribeAndGet may cause that thread to block forever. It is best to always use a timeout with subscribeAndGet so the thread is assured of eventually resuming execution.

Specified by:
subscribeAndGet in interface cMsgDomainInterface
Overrides:
subscribeAndGet in class cMsgDomainAdapter
Parameters:
subject - subject of message desired from server
type - type of message desired from server
timeout - time in milliseconds to wait for a message
Returns:
response message
Throws:
cMsgException - if there are communication problems with rc client; subject and/or type is null or blank
java.util.concurrent.TimeoutException - if timeout occurs

sendAndGet

public cMsgMessage sendAndGet(cMsgMessage message,
                              int timeout)
                       throws cMsgException,
                              java.util.concurrent.TimeoutException
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. 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.

Specified by:
sendAndGet in interface cMsgDomainInterface
Overrides:
sendAndGet in class cMsgDomainAdapter
Parameters:
message - message sent to client
timeout - time in milliseconds to wait for a reponse message
Returns:
response message
Throws:
cMsgException - if there are communication problems with the client; subject and/or type is null or blank
java.util.concurrent.TimeoutException - if timeout occurs