org.jlab.coda.cMsg
Class cMsgDomainAdapter

java.lang.Object
  extended by org.jlab.coda.cMsg.cMsgDomainAdapter
All Implemented Interfaces:
cMsgDomainInterface
Direct Known Subclasses:
CA, cMsg, File, RCBroadcast, RCServer, RunControl, TCPS

public class cMsgDomainAdapter
extends java.lang.Object
implements cMsgDomainInterface

This class provides a very basic (non-functional, dummy) implementation of the cMsgDomainInterface interface. Its non-getter/setter methods throw a cMsgException saying that the method is not implemented. It is like the swing Adapter classes.

Version:
1.0
Author:
Carl Timmer

Field Summary
protected  boolean connected
          Boolean indicating whether this client is connected to the domain server or not.
protected  java.lang.String description
          Description of the client.
protected  java.lang.String domain
          Domain being connected to.
protected  java.lang.String host
          Host the client is running on.
protected  java.lang.String name
          Name of this client.
protected  boolean receiving
          Boolean indicating whether this client's callbacks are active or not.
protected  cMsgShutdownHandlerInterface shutdownHandler
          Handler for client shutdown command sent by server.
protected  java.lang.String UDL
          The Uniform Domain Locator which tells the location of a name server.
protected  java.lang.String UDLremainder
          String containing the remainder part of the UDL.
 
Constructor Summary
cMsgDomainAdapter()
          Constructor which gives a default shutdown handler to this client.
 
Method Summary
 void connect()
          Method to connect to the domain server.
 void disconnect()
          Method to close the connection to the domain server.
 void flush(int timeout)
          Method to force cMsg client to send pending communications with domain server.
 java.lang.String getDescription()
          Get the client's description.
 java.lang.String getDomain()
          Get the name of the domain connected to.
 java.lang.String getHost()
          Get the host the client is running on.
 java.lang.String getName()
          Get the name of the client.
 cMsgShutdownHandlerInterface getShutdownHandler()
          Method to get the shutdown handler of the client.
 java.lang.String getString()
          Get a string that the implementing class wants to send back to the user.
 java.lang.String getUDL()
          Get the client's UDL.
 java.lang.String getUDLRemainder()
          Get the client's UDL remainder.
 boolean isConnected()
          Method to determine if this object is still connected to the domain server or not.
 boolean isReceiving()
          Method telling whether callbacks are activated or not.
 cMsgMessage monitor(java.lang.String command)
          This method is a synchronous call to receive a message containing monitoring data which describes the state of the cMsg domain the user is connected to.
 void send(cMsgMessage message)
          Method to send a message to the domain server for further distribution.
 cMsgMessage sendAndGet(cMsgMessage message, int timeout)
          The message is sent as it would be in the send(org.jlab.coda.cMsg.cMsgMessage) method.
 void setDescription(java.lang.String description)
          Set the description of the client.
 void setName(java.lang.String name)
          Set the name of the client.
 void setShutdownHandler(cMsgShutdownHandlerInterface handler)
          Method to set the shutdown handler of the client.
 void setUDL(java.lang.String UDL)
          Set the UDL of the client.
 void setUDLRemainder(java.lang.String UDLremainder)
          Set the UDL remainder of the client.
 void shutdownClients(java.lang.String client, boolean includeMe)
          Method to shutdown the given clients.
 void shutdownServers(java.lang.String server, boolean includeMyServer)
          Method to shutdown the given servers.
 void start()
          Method to start or activate the subscription callbacks.
 void stop()
          Method to stop or deactivate the subscription callbacks.
 java.lang.Object subscribe(java.lang.String subject, java.lang.String type, cMsgCallbackInterface cb, java.lang.Object userObj)
          Method to subscribe to receive messages of a subject and type from the domain server.
 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 message to the domain server for further distribution and wait for a response from the subdomain handler that got it.
 void unsubscribe(java.lang.Object obj)
          Method to unsubscribe a previous subscription to receive messages of a subject and type from the domain server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connected

protected volatile boolean connected
Boolean indicating whether this client is connected to the domain server or not.


receiving

protected boolean receiving
Boolean indicating whether this client's callbacks are active or not.


UDL

protected java.lang.String UDL
The Uniform Domain Locator which tells the location of a name server. It is of the form cMsg:://


UDLremainder

protected java.lang.String UDLremainder
String containing the remainder part of the UDL.


domain

protected java.lang.String domain
Domain being connected to.


name

protected java.lang.String name
Name of this client.


description

protected java.lang.String description
Description of the client.


host

protected java.lang.String host
Host the client is running on.


shutdownHandler

protected cMsgShutdownHandlerInterface shutdownHandler
Handler for client shutdown command sent by server.

Constructor Detail

cMsgDomainAdapter

public cMsgDomainAdapter()
Constructor which gives a default shutdown handler to this client.

Method Detail

isConnected

public boolean isConnected()
Method to determine if this object is still connected to the domain server or not.

Specified by:
isConnected in interface cMsgDomainInterface
Returns:
true if connected to domain server, false otherwise

connect

public void connect()
             throws cMsgException
Method to connect to the domain server.

Specified by:
connect in interface cMsgDomainInterface
Throws:
cMsgException - always throws an exception since this is a dummy implementation

disconnect

public void disconnect()
                throws cMsgException
Method to close the connection to the domain server. This method results in this object becoming functionally useless.

Specified by:
disconnect in interface cMsgDomainInterface
Throws:
cMsgException - always throws an exception since this is a dummy implementation

send

public void send(cMsgMessage message)
          throws cMsgException
Method to send a message to the domain server for further distribution.

Specified by:
send in interface cMsgDomainInterface
Parameters:
message - message
Throws:
cMsgException - always throws an exception since this is a dummy implementation

syncSend

public int syncSend(cMsgMessage message,
                    int timeout)
             throws cMsgException
Method to send a message to the domain server for further distribution and wait for a response from the subdomain handler that got it.

Specified by:
syncSend in interface cMsgDomainInterface
Parameters:
message - message
timeout - time in milliseconds to wait for a response
Returns:
response from subdomain handler
Throws:
cMsgException

flush

public void flush(int timeout)
           throws cMsgException
Method to force cMsg client to send pending communications with domain server.

Specified by:
flush in interface cMsgDomainInterface
Parameters:
timeout - time in milliseconds to wait for completion
Throws:
cMsgException - always throws an exception since this is a dummy implementation

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 server grabs the first incoming message of the requested subject and type and sends that to the caller. A return of null means a timeout has occurred.

Specified by:
subscribeAndGet in interface cMsgDomainInterface
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
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. The server notes the fact that a response to it is expected, and sends it to all subscribed to its subject and type. When a marked response is received from a client, it sends that first response back to the original sender regardless of its subject or type. The response may be null.

Specified by:
sendAndGet in interface cMsgDomainInterface
Parameters:
message - message sent to server
timeout - time in milliseconds to wait for a reponse message
Returns:
response message
Throws:
cMsgException
java.util.concurrent.TimeoutException - if timeout occurs

subscribe

public java.lang.Object subscribe(java.lang.String subject,
                                  java.lang.String type,
                                  cMsgCallbackInterface cb,
                                  java.lang.Object userObj)
                           throws cMsgException
Method to subscribe to receive messages of a subject and type from the domain server. 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.

Specified by:
subscribe in interface cMsgDomainInterface
Parameters:
subject - message subject
type - message type
cb - callback object whose cMsgCallbackInterface.callback(cMsgMessage, Object) 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 - always throws an exception since this is a dummy implementation

unsubscribe

public void unsubscribe(java.lang.Object obj)
                 throws cMsgException
Method to unsubscribe a previous subscription to receive messages of a subject and type from the domain server.

Specified by:
unsubscribe in interface cMsgDomainInterface
Parameters:
obj - the object "handle" returned from a subscribe call
Throws:
cMsgException - always throws an exception since this is a dummy implementation

monitor

public cMsgMessage monitor(java.lang.String command)
                    throws cMsgException
This method is a synchronous call to receive a message containing monitoring data which describes the state of the cMsg domain the user is connected to.

Specified by:
monitor in interface cMsgDomainInterface
Parameters:
command - directive for monitoring process
Returns:
response message containing monitoring information
Throws:
cMsgException

start

public void start()
Method to start or activate the subscription callbacks.

Specified by:
start in interface cMsgDomainInterface

stop

public void stop()
Method to stop or deactivate the subscription callbacks.

Specified by:
stop in interface cMsgDomainInterface

shutdownClients

public void shutdownClients(java.lang.String client,
                            boolean includeMe)
                     throws cMsgException
Method to shutdown the given clients. Wildcards used to match client names with the given string.

Specified by:
shutdownClients in interface cMsgDomainInterface
Parameters:
client - client(s) to be shutdown
includeMe - if true, it is permissible to shutdown calling client
Throws:
cMsgException

shutdownServers

public void shutdownServers(java.lang.String server,
                            boolean includeMyServer)
                     throws cMsgException
Method to shutdown the given servers. Wildcards used to match server names with the given string.

Specified by:
shutdownServers in interface cMsgDomainInterface
Parameters:
server - server(s) to be shutdown
includeMyServer - if true, it is permissible to shutdown calling client's cMsg server
Throws:
cMsgException

setShutdownHandler

public void setShutdownHandler(cMsgShutdownHandlerInterface handler)
Method to set the shutdown handler of the client.

Specified by:
setShutdownHandler in interface cMsgDomainInterface
Parameters:
handler - shutdown handler

getShutdownHandler

public cMsgShutdownHandlerInterface getShutdownHandler()
Method to get the shutdown handler of the client.

Specified by:
getShutdownHandler in interface cMsgDomainInterface
Returns:
shutdown handler object

getDomain

public java.lang.String getDomain()
Get the name of the domain connected to.

Specified by:
getDomain in interface cMsgDomainInterface
Returns:
domain name

getName

public java.lang.String getName()
Get the name of the client.

Specified by:
getName in interface cMsgDomainInterface
Returns:
client's name

setName

public void setName(java.lang.String name)
Set the name of the client.

Specified by:
setName in interface cMsgDomainInterface
Parameters:
name - name of client

getDescription

public java.lang.String getDescription()
Get the client's description.

Specified by:
getDescription in interface cMsgDomainInterface
Returns:
client's description

setDescription

public void setDescription(java.lang.String description)
Set the description of the client.

Specified by:
setDescription in interface cMsgDomainInterface
Parameters:
description - description of client

getUDLRemainder

public java.lang.String getUDLRemainder()
Get the client's UDL remainder.

Specified by:
getUDLRemainder in interface cMsgDomainInterface
Returns:
client's DUL remainder

setUDLRemainder

public void setUDLRemainder(java.lang.String UDLremainder)
Set the UDL remainder of the client. The cMsg class parses the UDL and strips off the beginning domain information. The remainder is passed on to the domain implementations (implementors of this interface).

Specified by:
setUDLRemainder in interface cMsgDomainInterface
Parameters:
UDLremainder - UDL remainder of client UDL

getUDL

public java.lang.String getUDL()
Get the client's UDL.

Specified by:
getUDL in interface cMsgDomainInterface
Returns:
client's DUL

setUDL

public void setUDL(java.lang.String UDL)
Set the UDL of the client.

Specified by:
setUDL in interface cMsgDomainInterface
Parameters:
UDL - UDL of client UDL

getHost

public java.lang.String getHost()
Get the host the client is running on.

Specified by:
getHost in interface cMsgDomainInterface
Returns:
client's host

getString

public java.lang.String getString()
Get a string that the implementing class wants to send back to the user.

Specified by:
getString in interface cMsgDomainInterface
Returns:
a string

isReceiving

public boolean isReceiving()
Method telling whether callbacks are activated or not. The start and stop methods activate and deactivate the callbacks.

Specified by:
isReceiving in interface cMsgDomainInterface
Returns:
true if callbacks are activated, false if they are not