org.jlab.coda.cMsg.cMsgDomain.client
Class cMsgServerClient

java.lang.Object
  extended by org.jlab.coda.cMsg.cMsgDomainAdapter
      extended by org.jlab.coda.cMsg.cMsgDomain.client.cMsg
          extended by org.jlab.coda.cMsg.cMsgDomain.client.cMsgServerClient
All Implemented Interfaces:
cMsgDomainInterface

public class cMsgServerClient
extends cMsg

This class implements a cMsg client which is created in a cMsg server for the purpose of communicating with other cMsg servers in the cMsg domain.

Version:
1.0
Author:
Carl Timmer

Field Summary
 
Fields inherited from class org.jlab.coda.cMsg.cMsgDomain.client.cMsg
monitorXML, subscriptions
 
Fields inherited from class org.jlab.coda.cMsg.cMsgDomainAdapter
connected, description, domain, host, name, receiving, shutdownHandler, UDL, UDLremainder
 
Constructor Summary
cMsgServerClient(cMsgNameServer nameServer)
          Constructor.
 
Method Summary
 void cleanup()
          Method to clean up after this object.
 boolean cloudLock(int delay)
          Lock the server (in cMsg subdomain) so that no other servers may simultaneously join the cMsg subdomain server cloud or register a client.
 void cloudUnlock()
          Unlock the server enabling other servers to join the cMsg subdomain server cloud or register a client.
 java.util.HashSet<java.lang.String> connect(int fromNameServerPort, boolean isOriginator, java.lang.String cloudPassword)
          Method to connect to the domain server from a cMsg server acting as a bridge.
 java.lang.String[] getClientNamesAndNamespaces()
          This method gets the names and namespaces of all the local clients (not servers) of another cMsg domain server.
 void printSizes()
          This method prints sizes of maps for debugging purposes.
 boolean registrationLock(int delay)
          Grab the registration lock (for adding a client) of another cMsg domain server.
 void registrationUnlock()
          Release the registration lock (when adding a client) of another cMsg domain server.
 int serverSendAndGet(cMsgMessage message, java.lang.String namespace, cMsgCallbackInterface cb)
          The message is sent by a server client to another server as it would be in the cMsg.send(org.jlab.coda.cMsg.cMsgMessage) method.
 void serverShutdown()
          Method to shutdown the server connected to.
 void serverShutdownClients(java.lang.String client, boolean includeMe)
          Method to shutdown the given clients.
 void serverSubscribe(java.lang.String subject, java.lang.String type, java.lang.String namespace, cMsgCallbackInterface cb, java.lang.Object userObj)
          Method for a server to subscribe to receive messages of a subject and type from another domain server.
 void serverUnSendAndGet(int id)
          Method to remove a previous serverSendAndGet.
 void serverUnsubscribe(java.lang.String subject, java.lang.String type, java.lang.String namespace, cMsgCallbackInterface cb, java.lang.Object userObj)
          Method for a server to unsubscribe a previous subscription to receive messages of a subject and type from another domain server.
 void thisServerCloudStatus(int status)
          This method tells the server this server is connected to, what cloud status this server has.
 
Methods inherited from class org.jlab.coda.cMsg.cMsgDomain.client.cMsg
connect, disconnect, flush, monitor, send, sendAndGet, shutdownClients, shutdownServers, subscribe, subscribeAndGet, syncSend, unsubscribe
 
Methods inherited from class org.jlab.coda.cMsg.cMsgDomainAdapter
getDescription, getDomain, getHost, getName, getShutdownHandler, getString, getUDL, getUDLRemainder, isConnected, isReceiving, setDescription, setName, setShutdownHandler, setUDL, setUDLRemainder, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

cMsgServerClient

public cMsgServerClient(cMsgNameServer nameServer)
                 throws cMsgException
Constructor.

Parameters:
nameServer - nameServer this client is running in
Throws:
cMsgException - if local host name cannot be found
Method Detail

printSizes

public void printSizes()
This method prints sizes of maps for debugging purposes.


cleanup

public void cleanup()
Method to clean up after this object.


connect

public java.util.HashSet<java.lang.String> connect(int fromNameServerPort,
                                                   boolean isOriginator,
                                                   java.lang.String cloudPassword)
                                            throws cMsgException
Method to connect to the domain server from a cMsg server acting as a bridge. This method is only called by the bridge object cMsgServerBridge. Unfortunately, this is a method largely duplicated from the base class but with a few small changes.

Parameters:
fromNameServerPort - port of name server calling this method
isOriginator - true if originating the connection between the 2 servers and false if this is the response or reciprocal connection
cloudPassword - password for connecting to a server in a particular cloud
Returns:
set of servers (names of form "host:port") that the server we're connecting to is already connected with
Throws:
cMsgException - if there are problems parsing the UDL or communication problems with the server

serverSendAndGet

public int serverSendAndGet(cMsgMessage message,
                            java.lang.String namespace,
                            cMsgCallbackInterface cb)
                     throws java.io.IOException
The message is sent by a server client to another server as it would be in the cMsg.send(org.jlab.coda.cMsg.cMsgMessage) method. The receiving 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.

Parameters:
message - message sent to server
namespace - namespace of message sent
cb - callback to run on receipt of response message
Returns:
the receiverSubscribe id number of the sendAndGet
Throws:
java.io.IOException - if there are communication problems with the server

serverUnSendAndGet

public void serverUnSendAndGet(int id)
                        throws java.io.IOException
Method to remove a previous serverSendAndGet. This method is only called when a serverSendAndGet times out and the server must be told to forget about the serverSendAndGet.

Parameters:
id - unique id of serverSendAndGet request to delete
Throws:
java.io.IOException - if there are communication problems with the server

serverSubscribe

public void serverSubscribe(java.lang.String subject,
                            java.lang.String type,
                            java.lang.String namespace,
                            cMsgCallbackInterface cb,
                            java.lang.Object userObj)
                     throws java.io.IOException
Method for a server to subscribe to receive messages of a subject and type from another 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.

Parameters:
subject - message subject
type - message type
namespace - message namespace
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
Throws:
java.io.IOException - there are communication problems with the server

serverUnsubscribe

public void serverUnsubscribe(java.lang.String subject,
                              java.lang.String type,
                              java.lang.String namespace,
                              cMsgCallbackInterface cb,
                              java.lang.Object userObj)
                       throws java.io.IOException
Method for a server to unsubscribe a previous subscription to receive messages of a subject and type from another domain server. Since many subscriptions may be made to the same subject and type values, but with different callbacks and user objects, the callback and user object must be specified so the correct subscription can be removed.

Parameters:
subject - message subject
type - message type
namespace - message namespace
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
Throws:
java.io.IOException - there are communication problems with the server

serverShutdownClients

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

Parameters:
client - client(s) to be shutdown
includeMe - if true, it is permissible to shutdown calling client
Throws:
java.io.IOException - if there are communication problems with the server

serverShutdown

public void serverShutdown()
                    throws java.io.IOException
Method to shutdown the server connected to.

Throws:
java.io.IOException - if there are communication problems with the server

cloudLock

public boolean cloudLock(int delay)
                  throws java.io.IOException
Lock the server (in cMsg subdomain) so that no other servers may simultaneously join the cMsg subdomain server cloud or register a client.

Parameters:
delay - time in milliseconds to wait for locked to be grabbed before timing out
Returns:
true if successful, else false
Throws:
java.io.IOException - if there are communication problems with the name server

cloudUnlock

public void cloudUnlock()
                 throws java.io.IOException
Unlock the server enabling other servers to join the cMsg subdomain server cloud or register a client.

Throws:
java.io.IOException - if there are communication problems with the name server

registrationLock

public boolean registrationLock(int delay)
                         throws java.io.IOException
Grab the registration lock (for adding a client) of another cMsg domain server.

Parameters:
delay - time in milliseconds to wait for the lock before timing out
Returns:
true if successful, else false
Throws:
java.io.IOException - if there are communication problems with the name server

registrationUnlock

public void registrationUnlock()
                        throws java.io.IOException
Release the registration lock (when adding a client) of another cMsg domain server.

Throws:
java.io.IOException - if communication error with server

thisServerCloudStatus

public void thisServerCloudStatus(int status)
                           throws java.io.IOException
This method tells the server this server is connected to, what cloud status this server has.

Parameters:
status - cMsgNameServer.INCLOUD, .NONCLOUD, or .BECOMINGCLOUD
Throws:
java.io.IOException - if communication error with server

getClientNamesAndNamespaces

public java.lang.String[] getClientNamesAndNamespaces()
                                               throws java.io.IOException
This method gets the names and namespaces of all the local clients (not servers) of another cMsg domain server.

Returns:
array of client names and namespaces
Throws:
java.io.IOException - if communication error with server