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, whenMsgDump
public void addAlias(String groupname)
DmhServerItf
addAlias
in interface DmhServerItf
public void clientDisconnect(String id)
DmhServerItf
clientDisconnect
in interface DmhServerItf
id
- the client handle from the serverStatus listpublic String clientIdentify(String id)
DmhServerItf
clientIdentify
in interface DmhServerItf
id
- the client handle from the serverStatus listpublic void clientPing(String id)
DmhServerItf
clientPing
in interface DmhServerItf
id
- the client handle from the serverStatus listpublic void clientTerminate(String id)
DmhServerItf
clientTerminate
in interface DmhServerItf
id
- the client handle from the serverStatus listpublic void close(String boxname) throws Exception
DmhClientItf
close
in interface DmhClientItf
close
in class DmhClient
boxname
- The name of the mailbox that is to be closed.Exception
- if there is no connectionpublic int[] count(String boxname) throws Exception
DmhClientItf
count
in interface DmhClientItf
count
in class DmhClient
boxname
- The mailbox name.
Exception
- if there is no connectionpublic void dmhReceive(DmhClientItf dmh, String data, String Dest, String Reply) throws Exception
dmhReceive
in interface DmhReceiveItf
dmh
- 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()
DmhServerItf
getAliases
in interface DmhServerItf
public String getMhMsgs(String boxname)
DmhServerItf
"{{hello world message} MY_REPLYBOX} {{sent w/o replybox} {}}"
getMhMsgs
in interface DmhServerItf
public String getVersion()
DmhClientItf
getVersion
in interface DmhClientItf
getVersion
in class DmhClient
public String init(int port) throws Exception
DmhServerItf
init
in interface DmhServerItf
port
- socket portException
- on failurepublic String init(String groupname) throws Exception
DmhServerItf
init
in interface DmhServerItf
groupname
- 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
DmhClientItf
init
in interface DmhClientItf
init
in class DmhClient
hostname
- 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)
DmhServerItf
lastRead
in interface DmhServerItf
public 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
DmhClientItf
put
in interface DmhClientItf
put
in class DmhClient
mailbox
- The destination mailbox name.message
- The message string. String characters are converted to
UTF-8 encoding, so that you can safely send
International characters.Exception
public void putr(String destbox, String replybox, String message) throws Exception
DmhClientItf
putr
in interface DmhClientItf
putr
in class DmhClient
destbox
- 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.Exception
public void run()
DmhClient
public DmhLostClientItf setLostClient(DmhLostClientItf handler)
DmhServerItf
setLostClient
in interface DmhServerItf
public DmhReceiveItf setTraceMsg(DmhReceiveItf traceReceive)
DmhServerItf
setTraceMsg
in interface DmhServerItf
public void shutdown()
DmhServerItf
shutdown
in interface DmhServerItf