public class DmhClient extends Object implements DmhClientItf, Runnable
Use the class only for a constructor call. Use the interface classname in your application. For example:
DmhClientItf dmh = new DmhClient();
STATE_CLOSING, STATE_COMM_ERROR, STATE_CONNECTED, STATE_DISCONNECTED, STATE_NAME_RESOLUTION, STATE_SETUP_IN_PROGRESS
Constructor and Description |
---|
DmhClient()
An implementation of interface DmhClientItf.
|
Modifier and Type | Method and Description |
---|---|
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 |
disarm()
Cancel all mailbox receiving for the connection.
|
void |
disarm(String boxname)
Un-register the listener from a mailbox.
|
void |
disconnect()
Clean-up resources such as network connections that are being
used by this interface.
|
String |
doXact(String destbox,
String msg)
Send a message and wait for a reply.
|
String |
doXact(String destbox,
String msg,
int secs_timeout)
Send a message and wait for a reply.
|
String |
doXact(String destbox,
String msg,
String replybox)
Send a message and wait for a reply.
|
String |
doXact(String destbox,
String msg,
String replybox,
int secs_timeout)
Send a message and wait for a reply.
|
void |
flush(String boxname)
Empty a mailbox of any pending messages.
|
String |
getClientID()
Get the server's unique ID string for the client connection.
|
int |
getDefaultTimeout()
Get the current default timeout that is used on DoXact calls.
|
String |
getDescription()
returns the client description
|
String |
getGroupname()
return the DMH Groupname as provided to the init() method.
|
String |
getHostname()
Return the TCP/IP hostname of the local computer
|
String |
getMhGroup()
If you have a connection, getMhgroup() returns hostname:port
of the DMH server else an empty string
|
String |
getProduct()
Obtain the vendor product id.
|
int |
getState()
Obtain an integer code representing communication status.
|
int |
getTraceBits()
get the trace bitfield settings
|
String |
getVersion()
Obtain the DMH compatibility version.
|
int |
groupnamePort(String Groupname)
Return the socket port that a DMH groupname is mapped to.
|
String |
init(String hostname,
int port)
Initialize and connect to a DMH server.
|
String |
init(String hostname,
String groupname)
Initialize and connect to a DMH server.
|
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.
|
String |
serverStatus()
Obtain the current message system status as a text list.
|
int |
setDefaultTimeout(int secs_timeout)
Set the default timeout that is used on DoXact calls.
|
void |
setDescription(String description)
Set the description for the client that is shown by the
"Identify" button from the DMH Status window.
|
DmhLostServerItf |
setLostServer(DmhLostServerItf handler)
Register a handler that gets called if the connection to the
DMH server is lost.
|
DmhTraceItf |
setTrace(DmhTraceItf handler)
set the Trace output handler, return the previous value
|
int |
setTraceBits(int tracebits)
Control the output of trace information.
|
String |
timedReceive(String boxname,
int secs_timeout)
Wait for a message to be received.
|
String |
toString() |
void |
whenMsg(String boxname,
DmhReceiveItf handler)
Register a callback object to receive the next
message available in mailbox boxname.
|
void |
whenMsgAgain()
This method is called by the logic of your dmhReceive() method
to specify that the current
handler object should be used to process the next message
received in the same destination mailbox.
|
String[][] |
whenMsgDump()
Dump the list of active mailbox listeners.
|
public DmhClient()
Use the class only for a constructor call. Use the interface classname in your application. For example:
DmhClientItf dmh = new DmhClient();
public void close(String boxname) throws Exception
DmhClientItf
close
in interface DmhClientItf
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
boxname
- The mailbox name.
Exception
- if there is no connectionpublic void disarm() throws Exception
DmhClientItf
disarm
in interface DmhClientItf
Exception
public void disarm(String boxname) throws Exception
DmhClientItf
disarm
in interface DmhClientItf
boxname
- The name of the mailbox that is serving as the destination for the sender(s) of the message(s).Exception
- if there is no connectionpublic void disconnect()
DmhClientItf
disconnect
in interface DmhClientItf
public String doXact(String destbox, String msg) throws Exception
DmhClientItf
doXact
in interface DmhClientItf
destbox
- The mailbox name of the server to which the message is sent.msg
- The message string.Exception
- for improper arguments or a broken connectionpublic String doXact(String destbox, String msg, int secs_timeout) throws Exception
DmhClientItf
doXact
in interface DmhClientItf
destbox
- The mailbox name of the server to which the message is sent.msg
- The message string.secs_timeout
- The maximum time to wait for the reply in seconds.Exception
- for improper arguments or a broken connectionpublic String doXact(String destbox, String msg, String replybox) throws Exception
DmhClientItf
doXact
in interface DmhClientItf
destbox
- The mailbox name of the server to which the message is sent.msg
- The message string.replybox
- A mailbox name specified for receiving the reply message.Exception
- for improper arguments or a broken connectionpublic String doXact(String destbox, String msg, String replybox, int secs_timeout) throws Exception
DmhClientItf
doXact
in interface DmhClientItf
destbox
- The mailbox name of the server to which the message is sent.msg
- The message string.replybox
- A mailbox name specified for receiving the reply message.secs_timeout
- The maximum time to wait for the reply in seconds.Exception
- for improper arguments or a broken connectionpublic void flush(String boxname) throws Exception
DmhClientItf
flush
in interface DmhClientItf
boxname
- The name of the mailbox that is to be emptied.Exception
- if no connection.public String getClientID()
DmhClientItf
getClientID
in interface DmhClientItf
public int getDefaultTimeout()
DmhClientItf
getDefaultTimeout
in interface DmhClientItf
public String getDescription()
DmhClientItf
getDescription
in interface DmhClientItf
public String getGroupname()
DmhClientItf
getGroupname
in interface DmhClientItf
public String getHostname()
DmhClientItf
getHostname
in interface DmhClientItf
public String getMhGroup()
DmhClientItf
getMhGroup
in interface DmhClientItf
public String getProduct()
DmhClientItf
A proprietary or competitive version of this interface should return a different value.
getProduct
in interface DmhClientItf
public int getState()
DmhClientItf
getState
in interface DmhClientItf
public int getTraceBits()
DmhClientItf
getTraceBits
in interface DmhClientItf
public String getVersion()
DmhClientItf
getVersion
in interface DmhClientItf
public int groupnamePort(String Groupname)
DmhClientItf
groupnamePort
in interface DmhClientItf
public String init(String hostname, int port) throws Exception
DmhClientItf
init
in interface DmhClientItf
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 init(String hostname, String groupname) throws Exception
DmhClientItf
init
in interface DmhClientItf
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.groupname
- the name of the DMH message group.
Group names are hashed to an integer
port number. The init() method can also be
called directly with an integer port number.Exception
- if the connection attempt failspublic void put(String mailbox, String message) throws Exception
DmhClientItf
put
in interface DmhClientItf
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
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()
run
in interface Runnable
public String serverStatus() throws Exception
DmhClientItf
serverStatus
in interface DmhClientItf
Exception
public int setDefaultTimeout(int secs_timeout) throws Exception
DmhClientItf
setDefaultTimeout
in interface DmhClientItf
secs_timeout
- The default maximum time to wait for reply messages.
The value must be >= 1 and < 86400Exception
public void setDescription(String description)
DmhClientItf
setDescription
in interface DmhClientItf
description
- A user supplied description of the application
process.public DmhLostServerItf setLostServer(DmhLostServerItf handler)
DmhClientItf
setLostServer
in interface DmhClientItf
handler
- An object that implements the DmhLostServerItf interfacepublic DmhTraceItf setTrace(DmhTraceItf handler)
DmhClientItf
setTrace
in interface DmhClientItf
public int setTraceBits(int tracebits)
DmhClientItf
setTraceBits
in interface DmhClientItf
tracebits
- Treated as a bitfieldpublic String timedReceive(String boxname, int secs_timeout) throws Exception
DmhClientItf
timedReceive
in interface DmhClientItf
boxname
- The mailbox name.secs_timeout
- The maximum time to wait in seconds.Exception
public String toString()
toString
in class Object
public void whenMsg(String boxname, DmhReceiveItf handler) throws Exception
DmhClientItf
An application should insure that the dmhReceive() call completes execution in due course - the application should not try to "live" in a dmhReceive() call.
The message is removed (consumed) from the mailbox by the action of receiving it. There should not be more than one receiver per mailbox.
whenMsg
in interface DmhClientItf
boxname
- The name of the mailbox that is serving as the destination for sent messages.handler
- An object that implements the DmhReceiveItf interface.Exception
- if no connectionpublic void whenMsgAgain() throws Exception
DmhClientItf
whenMsgAgain
in interface DmhClientItf
Exception
public String[][] whenMsgDump()
DmhClientItf
whenMsgDump
in interface DmhClientItf