public class cMsg extends cMsgDomainAdapter
Modifier and Type | Class and Description |
---|---|
(package private) class |
cMsg.KeepAlive
Class that checks the health of the domain server by reading monitoring information.
|
(package private) class |
cMsg.Multicaster
This class defines a thread to multicast a UDP packet to the
cMsg name server every second.
|
(package private) class |
cMsg.ParsedUDL
This class simply holds information obtained from parsing a UDL or
information about an available cMsg server in a server cloud.
|
(package private) class |
cMsg.UdpReceiver
This class gets any response to our UDP multicast.
|
(package private) class |
cMsg.UpdateServer
Class that periodically sends statistical info to the domain server.
|
Modifier and Type | Field and Description |
---|---|
(package private) java.util.ArrayList<java.lang.String> |
broadList
Domain server's broadcast/subnet addresses.
|
(package private) java.util.concurrent.locks.Lock |
connectLock
Lock for calling
connect() or disconnect() . |
(package private) cMsg.ParsedUDL |
currentParsedUDL
The parsed form of the single UDL the client is currently connected to.
|
(package private) java.io.DataOutputStream |
domainOut
Socket output stream associated with domainOutChannel - sends info to server.
|
(package private) java.net.Socket |
domainOutSocket
Channel for talking to domain server.
|
(package private) java.lang.String |
domainServerHost
Domain server's host.
|
(package private) int |
domainServerPort
Domain server's TCP port.
|
(package private) boolean |
hasSend
The subdomain server object or client handler implements
send(org.jlab.coda.cMsg.cMsgMessage) . |
(package private) boolean |
hasSendAndGet
The subdomain server object or client handler implements
sendAndGet(org.jlab.coda.cMsg.cMsgMessage, int) . |
(package private) boolean |
hasShutdown
The subdomain server object or client handler implements
shutdownClients(String, boolean) . |
(package private) boolean |
hasSubscribe
The subdomain server object or client handler implements
subscribe(String, String, org.jlab.coda.cMsg.cMsgCallbackInterface, Object) . |
(package private) boolean |
hasSubscribeAndGet
The subdomain server object or client handler implements
subscribeAndGet(String, String, int) . |
(package private) boolean |
hasSyncSend
The subdomain server object or client handler implements
syncSend(org.jlab.coda.cMsg.cMsgMessage, int) . |
(package private) boolean |
hasUnsubscribe
The subdomain server object or client handler implements
unsubscribe(org.jlab.coda.cMsg.cMsgSubscriptionHandle) . |
(package private) java.util.ArrayList<java.lang.String> |
ipList
Domain server's IP addresses.
|
(package private) java.net.Socket |
keepAliveSocket
Socket for checking to see that the domain server is still alive.
|
(package private) cMsg.KeepAlive |
keepAliveThread
Thread for sending keep alive commands to domain server to check its health.
|
(package private) cMsgClientListeningThread |
listeningThread
Thread listening for messages and responding to domain server commands.
|
java.lang.String |
monitorXML
String containing monitor data received from a cMsg server as a keep alive response.
|
(package private) java.util.concurrent.locks.Lock |
notConnectLock
Lock for calling methods other than
connect() or disconnect() . |
(package private) java.util.concurrent.ConcurrentHashMap<java.lang.Integer,cMsgGetHelper> |
sendAndGets
Collection of all of this client's
sendAndGet(org.jlab.coda.cMsg.cMsgMessage, int)
calls currently in execution. |
(package private) java.util.concurrent.locks.Lock |
socketLock
Lock to ensure that methods using the socket, write in sequence.
|
(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.concurrent.locks.Lock |
subscribeLock
Lock to ensure
subscribe(String, String, org.jlab.coda.cMsg.cMsgCallbackInterface, Object)
and unsubscribe(org.jlab.coda.cMsg.cMsgSubscriptionHandle)
calls are sequential. |
java.util.concurrent.ConcurrentHashMap<cMsgSubscription,java.lang.String> |
subscriptions
Collection of all of this client's message subscriptions which are
cMsgSubscription objects (value of map is dummy so we can use
concurrent hashmap). |
(package private) java.util.concurrent.ConcurrentHashMap<java.lang.Integer,cMsgGetHelper> |
syncSends
Collection of all of this client's
syncSend(org.jlab.coda.cMsg.cMsgMessage, int)
calls currently in execution. |
(package private) int |
uniqueClientKey
Unique id sent by server to use in our responses.
|
(package private) java.util.concurrent.atomic.AtomicInteger |
uniqueId
Used to create unique id numbers associated with a specific message subject/type pair.
|
(package private) cMsg.UpdateServer |
updateServerThread
Thread for sending periodic monitoring info to domain server to check this client's health.
|
(package private) boolean |
useFailovers
If more than one viable failover UDL is given or failover to a cloud is
indicated, then this is true, meaning
if any request to the server is interrupted, that method will wait a short
while for the failover to complete before throwing an exception or continuing
on.
|
connected, debug, description, domain, host, name, receiving, shutdownHandler, UDL, UDLremainder
Constructor and Description |
---|
cMsg()
Constructor which does NOT automatically try to connect to the name server specified.
|
Modifier and Type | Method and Description |
---|---|
void |
connect()
Method to connect to the domain server from this client.
|
protected void |
connectWithMulticast()
Method to multicast in order to find the domain server from this client.
|
void |
disconnect()
Method to close the connection to the domain server.
|
void |
flush(int timeout)
This method does nothing.
|
java.lang.String |
getCurrentUDL()
Get the UDL the client is currently connected to or null if no connection.
|
java.lang.String |
getInfo(java.lang.String cmd)
Get a string of information dependent upon the argument.
|
java.lang.String |
getServerHost()
Get the host of the cMsg server that this client is connected to.
|
int |
getServerPort()
Get the TCP port of the cMsg server that this client is connected to.
|
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.
|
(package private) cMsg.ParsedUDL |
parseUDL(java.lang.String udl)
Method to parse the Universal Domain Locator (UDL) into its various components.
|
void |
send(cMsgMessage message)
Method to send a message to the domain for further distribution.
|
cMsgMessage |
sendAndGet(cMsgMessage message,
int timeout)
The message is sent as it would be in the
cMsgDomainInterface.send(org.jlab.coda.cMsg.cMsgMessage) method and a single synchronous
response is received. |
void |
setUDL(java.lang.String UDL)
Set the UDL of the client which may be a semicolon separated list of UDLs in this domain.
|
void |
shutdownClients(java.lang.String client,
boolean includeMe)
Method to shutdown the given client(s).
|
void |
shutdownServers(java.lang.String server,
boolean includeMyServer)
Method to shutdown the given server(s).
|
cMsgSubscriptionHandle |
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.
|
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 for further distribution
and wait for a response from the subdomain handler that got it.
|
(package private) void |
talkToNameServerFromClient(java.net.Socket socket)
This method gets the host and port of the domain server from the name server.
|
void |
unsubscribe(cMsgSubscriptionHandle obj)
Method to unsubscribe a previous subscription to receive messages of a subject and type
from the domain.
|
getDebug, getDescription, getDomain, getHost, getName, getShutdownHandler, getUDL, getUDLRemainder, isConnected, isReceiving, setDebug, setDescription, setName, setShutdownHandler, setUDLRemainder, start, stop
cMsg.ParsedUDL currentParsedUDL
volatile boolean useFailovers
java.util.ArrayList<java.lang.String> ipList
java.util.ArrayList<java.lang.String> broadList
java.lang.String domainServerHost
int domainServerPort
java.net.Socket domainOutSocket
java.io.DataOutputStream domainOut
java.net.Socket keepAliveSocket
public java.lang.String monitorXML
cMsgClientListeningThread listeningThread
cMsg.KeepAlive keepAliveThread
cMsg.UpdateServer updateServerThread
public java.util.concurrent.ConcurrentHashMap<cMsgSubscription,java.lang.String> subscriptions
cMsgSubscription
objects (value of map is dummy so we can use
concurrent hashmap). A concurrent map is needed so that:
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(org.jlab.coda.cMsg.cMsgMessage, int)
calls currently in execution.
Key is senderToken object, value is cMsgGetHelper
object.java.util.concurrent.ConcurrentHashMap<java.lang.Integer,cMsgGetHelper> syncSends
syncSend(org.jlab.coda.cMsg.cMsgMessage, int)
calls currently in execution.
Key is senderToken object, value is cMsgGetHelper
object.java.util.concurrent.locks.Lock connectLock
connect()
or disconnect()
.java.util.concurrent.locks.Lock notConnectLock
connect()
or disconnect()
.java.util.concurrent.locks.Lock subscribeLock
subscribe(String, String, org.jlab.coda.cMsg.cMsgCallbackInterface, Object)
and unsubscribe(org.jlab.coda.cMsg.cMsgSubscriptionHandle)
calls are sequential.java.util.concurrent.locks.Lock socketLock
java.util.concurrent.atomic.AtomicInteger uniqueId
int uniqueClientKey
boolean hasSend
send(org.jlab.coda.cMsg.cMsgMessage)
.boolean hasSyncSend
syncSend(org.jlab.coda.cMsg.cMsgMessage, int)
.boolean hasSubscribeAndGet
subscribeAndGet(String, String, int)
.boolean hasSendAndGet
sendAndGet(org.jlab.coda.cMsg.cMsgMessage, int)
.boolean hasSubscribe
subscribe(String, String, org.jlab.coda.cMsg.cMsgCallbackInterface, Object)
.boolean hasUnsubscribe
unsubscribe(org.jlab.coda.cMsg.cMsgSubscriptionHandle)
.boolean hasShutdown
shutdownClients(String, boolean)
.public cMsg() throws cMsgException
cMsgException
- if local host name cannot be foundpublic void setUDL(java.lang.String UDL) throws cMsgException
setUDL
in interface cMsgDomainInterface
setUDL
in class cMsgDomainAdapter
UDL
- UDL of clientcMsgException
- if UDL is null, no beginning cmsg://, no host given, unknown hostpublic java.lang.String getCurrentUDL()
getCurrentUDL
in interface cMsgDomainInterface
getCurrentUDL
in class cMsgDomainAdapter
public java.lang.String getServerHost()
getServerHost
in interface cMsgDomainInterface
getServerHost
in class cMsgDomainAdapter
public int getServerPort()
getServerPort
in interface cMsgDomainInterface
getServerPort
in class cMsgDomainAdapter
public java.lang.String getInfo(java.lang.String cmd)
getInfo
in interface cMsgDomainInterface
getInfo
in class cMsgDomainAdapter
cmd
- input stringpublic void connect() throws cMsgException
connectDirect(java.util.List<java.lang.String>)
.connect
in interface cMsgDomainInterface
connect
in class cMsgDomainAdapter
cMsgException
- if there are problems parsing the UDL or
communication problems with the server(s)protected void connectWithMulticast() throws cMsgException
cMsgException
- if there are problems parsing the UDL or
communication problems with the server.public void flush(int timeout)
flush
in interface cMsgDomainInterface
flush
in class cMsgDomainAdapter
timeout
- ignoredpublic 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;
subject and/or type is null; message is too big for
UDP packet size if doing UDP sendpublic int syncSend(cMsgMessage message, int timeout) throws cMsgException
syncSend
in interface cMsgDomainInterface
syncSend
in class cMsgDomainAdapter
message
- message to sendtimeout
- ignoredcMsgException
- if there are communication problems with the server;
subject and/or type is nullpublic 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 callback, subject and/or type is null or blank;
an identical subscription already exists; there are
communication problems with the serverpublic void unsubscribe(cMsgSubscriptionHandle obj) throws cMsgException
unsubscribe
in interface cMsgDomainInterface
unsubscribe
in class cMsgDomainAdapter
obj
- the object returned from a subscribe callcMsgException
- if there are communication problems with the server; object arg 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 the server;
server dies; 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
cMsgDomainInterface.send(org.jlab.coda.cMsg.cMsgMessage)
method and a single synchronous
response is received. The domain 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.
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 servertimeout
- time in milliseconds to wait for a response message, zero means wait forever.cMsgException
- if there are communication problems with the server;
server died; subject and/or type is nulljava.util.concurrent.TimeoutException
- if timeout occurspublic cMsgMessage monitor(java.lang.String command)
Any non-null value of the argument is used as an XML fragment which is appended to the keep alive packet this client sends to the server. A value of "" will remove it (null is just ignored).
monitor
in interface cMsgDomainInterface
monitor
in class cMsgDomainAdapter
command
- xml fragment appended to the keep alive packetpublic void shutdownClients(java.lang.String client, boolean includeMe) throws cMsgException
shutdownClients
in interface cMsgDomainInterface
shutdownClients
in class cMsgDomainAdapter
client
- client(s) to be shutdownincludeMe
- if true, it is permissible to shutdown calling clientcMsgException
- if there are communication problems with the serverpublic void shutdownServers(java.lang.String server, boolean includeMyServer) throws cMsgException
shutdownServers
in interface cMsgDomainInterface
shutdownServers
in class cMsgDomainAdapter
server
- server(s) to be shutdownincludeMyServer
- if true, it is permissible to shutdown calling client's
cMsg servercMsgException
- if server arg is not in the correct form (host:port),
the host is unknown, client not connected to server,
or IO error.void talkToNameServerFromClient(java.net.Socket socket) throws java.io.IOException, cMsgException
socket
- socket to serverjava.io.IOException
- if there are communication problems with the name servercMsgException
- if the name server's domain does not match the UDL's domain;
the client cannot be registered; the domain server cannot
open a listening socket or find a port to listen on; or
the name server cannot establish a connection to the clientcMsg.ParsedUDL parseUDL(java.lang.String udl) throws cMsgException
Method to parse the Universal Domain Locator (UDL) into its various components. The general cMsg domain UDL is of the form:
cMsg:cMsg://<host>:<port>/<subdomainType>/<subdomain remainder>?tag=value&tag2=value2 ...
port is not necessary to specify but is the name server's TCP port if connecting directly
or the server's UDP port if multicasting. If not specified, defaults are
cMsgNetworkConstants.nameServerTcpPort
if connecting directly, else
cMsgNetworkConstants.nameServerUdpPort
if multicasting
host can be "localhost" and may also be in dotted form (129.57.35.21), but may not contain a colon. It can also be "multicast"
if domainType is cMsg, subdomainType is automatically set to cMsg if not given. if subdomainType is not cMsg, it is required
the domain name is case insensitive as is the subdomainType
remainder is passed on to the subdomain plug-in
client's password is in tag=value part of UDL as cmsgpassword=<password>
domain server port is in tag=value part of UDL as domainPort=<port>
multicast timeout is in tag=value part of UDL as multicastTO=<time out in seconds>
subnet is in tag=value part of UDL as subnet=<preferred subnet in dot-decimal>
failover is in tag=value part of UDL as failover=<cloud, cloudonly, or any>
cloud is in tag=value part of UDL as failover=<local or any>
the tag=value part of UDL parsed here as regime=low or regime=high means:
low message/data throughput client if regime=low, meaning many clients are serviced by a single server thread and all msgs retain time order
high message/data throughput client if regime=high, meaning each client is serviced by multiple threads to maximize throughput. Msgs are NOT guaranteed to be handled in time order
if regime is not specified (default), it is assumed to be medium, where a single thread is dedicated to a single client and msgs are guaranteed to be handled in time order
udl
- UDL to parsecMsgException
- if UDL is null, no beginning cmsg://, no host given, unknown host