public class DmhServer extends DmhClient implements DmhServerItf, Runnable, DmhReceiveItf
Multiple DMH clients may connect to the server for the purpose of sending and receiving messages using named mailboxes. The client only needs to know the hostname or IP address of the server, and the DMH message groupname in order to connect and exchange messages. Various DMH client software libraries are available which allows for connecting applications that run on different computer systems and that use different programming languages.
It is common for clients to connect and disconnect during the lifetime of the server. For example, user interfaces and equipment connections are likely to come and go.
A software architect takes advantage of the ability for message system participants to directly process SQL, SQL eval commands, and to use SQL table subscriptions. This provides the rich coupling needed between participants without having to write message parsing code or having to limit interaction to a fixed set of compiled procedure calls declared with IDL.
Class DmhServer implements the DMH message system client API, DmhClientItf, along with DMH server API, DmhServerItf. You may want to use only a DmhClientItf reference in your application to insure that the application can be run as either a DMH client or a DMH server. The DmhServer overloads the DmhClient init() so that it can be used to initialize as a server either by specifying a hostname or IP served on your computer, or by passing null to imply the default interface(s) for a server on your computer.
For example:
DmhClientItf dmh = new DmhServer(); dmh.init(null, groupname);
STATE_CLOSING, STATE_COMM_ERROR, STATE_CONNECTED, STATE_DISCONNECTED, STATE_NAME_RESOLUTION, STATE_SETUP_IN_PROGRESS| Constructor and Description |
|---|
DmhServer() |
| Modifier and Type | Method and Description |
|---|---|
void |
addAlias(String groupname)
Use the uncommon feature of adding a DMH groupname alias so that
sending to mailbox@groupname is recognized as sending
within the server's own DMH group.
|
void |
clientDisconnect(String id)
close the client's socket connection
|
String |
clientIdentify(String id)
ask the client to provide his hostname, command line, and DISPLAY name
as a String result
|
void |
clientPing(String id)
Exercise the network connection which causes an error closure
if the client is gone.
|
void |
clientTerminate(String id)
tell the client to exit, which is honored by Tcl and Java clients,
and by VB clients if the developer codes the Shutdown() callback.
|
void |
close(String boxname)
Stop using a mailbox - disarm receiving if listening, discard any pending messages,
and remove from existence if it exists.
|
int[] |
count(String boxname)
Obtain mailbox message counts.
|
void |
dmhReceive(DmhClientItf dmh,
String data,
String Dest,
String Reply) |
String[] |
getAliases()
An alias array is used to implement the concept of
of virtual DMH groups in a single physical server.
|
String |
getMhMsgs(String boxname)
Tcl virtual data mh_msgs.
|
String |
getVersion()
Obtain the DMH compatibility version.
|
String |
init(int port)
Initialize using a specified socket port number.
|
String |
init(String groupname)
Initialize the DMH server, usually on the default network
interface.
|
String |
init(String hostname,
int port)
Initialize and connect to a DMH server.
|
String |
lastRead(String boxname)
To support debugging, the DMH server keeps a copy of the last message
sent to each mailbox.
|
static void |
main(String[] argv)
Run a DMH server as a standalone application.
|
void |
put(String mailbox,
String message)
Send a message to a named mailbox.
|
void |
putr(String destbox,
String replybox,
String message)
Send a message to a mailbox with a reply mailbox indicated.
|
void |
run()
Run is public for Thread start to call, not for applications to call.
|
DmhLostClientItf |
setLostClient(DmhLostClientItf handler)
register to receive notification of disconnected clients.
|
DmhReceiveItf |
setTraceMsg(DmhReceiveItf traceReceive)
Register to receive the messages that are sent to the TRACE mailbox.
|
void |
shutdown()
shutdown the listening socket and close all existing client
connections
|
String |
toString() |
disarm, disarm, disconnect, doXact, doXact, doXact, doXact, flush, getClientID, getDefaultTimeout, getDescription, getGroupname, getHostname, getMhGroup, getProduct, getState, getTraceBits, groupnamePort, init, serverStatus, setDefaultTimeout, setDescription, setLostServer, setTrace, setTraceBits, timedReceive, whenMsg, whenMsgAgain, whenMsgDumppublic void addAlias(String groupname)
DmhServerItfaddAlias in interface DmhServerItfpublic void clientDisconnect(String id)
DmhServerItfclientDisconnect in interface DmhServerItfid - the client handle from the serverStatus listpublic String clientIdentify(String id)
DmhServerItfclientIdentify in interface DmhServerItfid - the client handle from the serverStatus listpublic void clientPing(String id)
DmhServerItfclientPing in interface DmhServerItfid - the client handle from the serverStatus listpublic void clientTerminate(String id)
DmhServerItfclientTerminate in interface DmhServerItfid - the client handle from the serverStatus listpublic void close(String boxname)
throws Exception
DmhClientItfclose in interface DmhClientItfclose in class DmhClientboxname - The name of the mailbox that is to be closed.Exception - if there is no connectionpublic int[] count(String boxname)
throws Exception
DmhClientItfcount in interface DmhClientItfcount in class DmhClientboxname - The mailbox name.
Exception - if there is no connectionpublic void dmhReceive(DmhClientItf dmh, String data, String Dest, String Reply) throws Exception
dmhReceive in interface DmhReceiveItfdmh - the DMH connection instancedata - received message dataDest - the destination mailbox nameReply - the message sender may optionally provide a mailbox name.
The usual purpose of the name is to provide a destination to send a reply message.
The value is an empty string when not specified.Exception - - If your receiving logic throws an exception,
a stack backtrace is printed to stdout and a warning
message is passed to the DmhTraceItf callback if error tracing is enabled.public String[] getAliases()
DmhServerItfgetAliases in interface DmhServerItfpublic String getMhMsgs(String boxname)
DmhServerItf
"{{hello world message} MY_REPLYBOX} {{sent w/o replybox} {}}"
getMhMsgs in interface DmhServerItfpublic String getVersion()
DmhClientItfgetVersion in interface DmhClientItfgetVersion in class DmhClientpublic String init(int port)
throws Exception
DmhServerItfinit in interface DmhServerItfport - socket portException - on failurepublic String init(String groupname)
throws Exception
DmhServerItfinit in interface DmhServerItfgroupname - the name of the DMH message group.
Group names are usually hashed to an integer
port number. The init() method can also be
called directly with an integer port number.Exception - on failurepublic String init(String hostname,
int port)
throws Exception
DmhClientItfinit in interface DmhClientItfinit in class DmhClienthostname - the TCP/IP hostname of the DMH server,
may also be the IP number as a string.
May be null to represent your own system.port - the socket port number for the serverException - if the connection attempt failspublic String lastRead(String boxname)
DmhServerItflastRead in interface DmhServerItfpublic static void main(String[] argv)
The server listens to mailbox "DMH" for the following command messages:
argv - optional command line arguments:[dmhGroupname [traceBits]
public void put(String mailbox,
String message)
throws Exception
DmhClientItfput in interface DmhClientItfput in class DmhClientmailbox - The destination mailbox name.message - The message string. String characters are converted to
UTF-8 encoding, so that you can safely send
International characters.Exceptionpublic void putr(String destbox,
String replybox,
String message)
throws Exception
DmhClientItfputr in interface DmhClientItfputr in class DmhClientdestbox - The destination mailbox name.replybox - The reply mailbox.message - The message string. String characters are converted to
UTF-8 encoding, so that you can safely send
International characters.Exceptionpublic void run()
DmhClientpublic DmhLostClientItf setLostClient(DmhLostClientItf handler)
DmhServerItfsetLostClient in interface DmhServerItfpublic DmhReceiveItf setTraceMsg(DmhReceiveItf traceReceive)
DmhServerItfsetTraceMsg in interface DmhServerItfpublic void shutdown()
DmhServerItfshutdown in interface DmhServerItf