Class NetServerClient
java.lang.Object
cl.obcom.desktopfx.netserver.NetServerClient
- All Implemented Interfaces:
AutoCloseable
Subchannel of a
NetServerChannel communication channel. A client
application uses a NetServerClient to send transactions, receive
published messages, or request services from the OBCOM NetServer or
other custom made servers. A NetServerClient can only be created
using the createClient method.-
Method Summary
Modifier and TypeMethodDescriptionvoidassignLayout(NetServerMessage message) Themessageis assigned the layout identified by itsLayoutNamelabel.voidclose()Closes thisNetServerClient, relinquishing any underlying resources.Executes aservicewithargumentsand returns a result message.Executes aservicewithargumentsand returns a result message.Executes aservicewithargumentsand returns a result message.booleanReturnstrueif theassignLayoutmethod is automatically applied to all reply or published messages received from the OBCOM NetServer.booleanReturnstrueif login is performed after connecting to OBCOM NetServer.Returns theNetServerChannelof thisNetServerClient.Returns the description of thisNetServerClient.booleanReturnstrueif all messages are sent encrypted to OBCOM NetServer.Returns theLayoutwith the specifiedname.getTask()Returns theDesktopTaskof thisNetServerClient.Returns an OBCOM NetServer timestamp.booleanReturnstrueif the signatures of downloaded layouts are verified.booleanisAlive()Returnstrueif thisNetServerClientis alive.booleanReturnstrueif connected to the OBCOM NetServer.voidsetAutoAssignLayout(boolean value) Changes whether theassignLayoutmethod is automatically applied to all reply or published messages received from the OBCOM NetServer.voidsetVerifyLayoutSignatures(boolean value) Changes whether the signatures of downloaded layouts are verified.voidsubscribe(String name, EventHandler<MulticastEvent> handler) Subscribes to messages published with the specifiedname.voidunsubscribe(String name, EventHandler<MulticastEvent> handler) Unsubscribes from messages published with the specifiedname.
-
Method Details
-
getTask
Returns theDesktopTaskof thisNetServerClient.- Returns:
- the
DesktopTaskornullif none defined.
-
getDescription
Returns the description of thisNetServerClient.- Returns:
- the description of this
NetServerClient.
-
isConnected
public boolean isConnected()Returnstrueif connected to the OBCOM NetServer.- Returns:
trueif connected to the OBCOM NetServer.
-
isAlive
public boolean isAlive()Returnstrueif thisNetServerClientis alive. ANetServerClientbecomes dead when a System Operator executes the "kill client" command in an OBCOM NetServer console.- Returns:
trueif this NetServerClient is alive.
-
getChannel
Returns theNetServerChannelof thisNetServerClient.- Returns:
- the
NetServerChannelof thisNetServerClient. - Throws:
RuntimeException- if this client is not alive.
-
getEncryptAll
public boolean getEncryptAll()Returnstrueif all messages are sent encrypted to OBCOM NetServer.- Returns:
trueif all messages are sent encrypted to OBCOM NetServer.
-
getAutoLogin
public boolean getAutoLogin()Returnstrueif login is performed after connecting to OBCOM NetServer.- Returns:
trueif login is performed after connecting to OBCOM NetServer.
-
getVerifyLayoutSignatures
public boolean getVerifyLayoutSignatures()Returnstrueif the signatures of downloaded layouts are verified.- Returns:
trueif the signatures of downloaded layouts are verified.
-
setVerifyLayoutSignatures
public void setVerifyLayoutSignatures(boolean value) Changes whether the signatures of downloaded layouts are verified.- Parameters:
value- iftruethe signatures of downloaded layouts will be verified, otherwise the signatures will be assigned to layouts without verification.
-
getLayout
Returns theLayoutwith the specifiedname. If the layout is not available in the cache, it is downloaded, compiled, stored in the cache and returned to the caller of this method. The signature of the downloaded layout will be verified ifgetVerifyLayoutSignatures()returnstrue, otherwise the signature will be assigned to the layout without verification.- Parameters:
name- name of the requiredLayout.- Returns:
- the
Layoutwith the specifiedname. - Throws:
NullPointerException- ifnameisnull.Exception- if an error occurs while loading the layout.
-
getAutoAssignLayout
public boolean getAutoAssignLayout()Returnstrueif theassignLayoutmethod is automatically applied to all reply or published messages received from the OBCOM NetServer.- Returns:
trueif theassignLayoutmethod is applied to all reply or published messages.
-
setAutoAssignLayout
public void setAutoAssignLayout(boolean value) Changes whether theassignLayoutmethod is automatically applied to all reply or published messages received from the OBCOM NetServer.- Parameters:
value- iftruetheassignLayoutmethod will be applied to all reply or published messages.
-
assignLayout
Themessageis assigned the layout identified by itsLayoutNamelabel. If themessagehas no such label, then nothing is done. If themessagehas aLayoutSignaturelabel, it is compared with the signature of the assigned layout, and an exception if thrown if the signatures are not equal.- Parameters:
message- the message that will be assigned a layout.- Throws:
NullPointerException- ifmessageisnull.IllegalArgumentException- if the signatures of themessageand the layout are not equal.Exception- if another error occurs.
-
getTimestamp
Returns an OBCOM NetServer timestamp. An OBCOM NetServer timestamp is a string that identifies a unique point in time. Each time a OBCOM NetServer returns a timestamp, it's value is guaranteed to be different (bigger) than the previous timestamp returned. A OBCOM NetServer timestamp is a string that contains 26 characters with the following format:yyyy-MM-dd:HH:mm:ss.cccccc
- Returns:
- the OBCOM NetServer timestamp string.
- Throws:
Exception- if another error occurs.
-
execute
Executes aservicewithargumentsand returns a result message. This is just a convenience method implemented by the following trivial call statement:execute(service, arguments, false, 0);
- Parameters:
service- the name of the service.arguments- the arguments of the service (can be null).- Returns:
- the service execution result message.
- Throws:
NullPointerException- if an argument isnull.IllegalArgumentException- if an argument value is invalid.Exception- if another error occurs.
-
execute
public NetServerMessage execute(String service, Object arguments, boolean encrypted) throws Exception Executes aservicewithargumentsand returns a result message. Ifencryptedistruethe communication with the OBCOM NetServer will be encrypted. This is just a convenience method implemented by the following trivial call statement:execute(service, arguments, encrypted, 0);
- Parameters:
service- the name of the service.arguments- the arguments of the service (can be null).encrypted- iftruethe communication will be encrypted.- Returns:
- the service execution result message.
- Throws:
NullPointerException- if an argument isnull.IllegalArgumentException- if an argument value is invalid.Exception- if another error occurs.
-
execute
public NetServerMessage execute(String service, Object arguments, boolean encrypted, long timeout) throws Exception Executes aservicewithargumentsand returns a result message. Theservicename has one of the following formats:{HostName.}ServerName.TranName {HostName.}ServerName.[TranCode]where optional items are shown within "{" and "}" brackets, and the characters ".", "[" and "]" stand for themselves. If the optionalHostNameis not specified, then the OBCOM NetServer Default Host will be used.TranNameis the name of the requested transaction, whileTranCodeis and alternative one-character identification of the same transaction. EitherTranNameorTranCodemust be specified. The following are some examples of service names:ECUSER.[!] ACASER.ACA-TIME HUB.IMSER.AddContact
Theargumentsobject will be converted to aStringusing the standardtoStringmethod, hence any object can be used as argument for a service.If
encryptedistruethen all communication with the OBCOM NetServer will be encrypted.The
timeoutargument specifies the amount of milliseconds to wait for the result message. Iftimeoutis zero, the call will wait forever for the result.- Parameters:
service- the name of the service.arguments- the arguments of the service (can be null).encrypted- iftruethe communication will be encrypted.timeout- the maximum time to wait for the reply (milliseconds).- Returns:
- the service execution result message.
- Throws:
NullPointerException- if an argument isnull.IllegalArgumentException- if an argument value is invalid.SocketTimeoutException- if timeout occurs.Exception- if another error occurs.
-
subscribe
Subscribes to messages published with the specifiedname. When someone publishes a message with the givenname, the suppliedhandleris called. Thenameargument has the following format:{HostName.}MulticastNamewhere optional items are shown within "{" and "}" brackets, and the character "." stands for itself. If the optionalHostNameis not specified, then the OBCOM NetServer Default Host will be used. The requiredMulticastNamehas a minimum length of 1 and a maximum length of 10 characters.- Parameters:
name- name of the multicast messages to enable.handler- the handler called when a multicast message arrives.- Throws:
NullPointerException- if a required argument isnull.IllegalArgumentException- ifnameis invalid.Exception- if another error occurs.
-
unsubscribe
Unsubscribes from messages published with the specifiedname. Thenameargument has the following format:{HostName.}MulticastNamewhere optional items are shown within "{" and "}" brackets, and the character "." stands for itself. If the optionalHostNameis not specified, then the OBCOM NetServer Default Host will be used. The requiredMulticastNamehas a minimum length of 1 and a maximum length of 10 characters. IfMulticastNameequals"*", this method disables the reception of all multicast messages enabled with thesubscribemethod.- Parameters:
name- name of the multicast messages to disable.handler- the handler called when a multicast message arrives.- Throws:
NullPointerException- if a required argument isnull.IllegalArgumentException- ifnameis invalid.Exception- if another error occurs.
-
close
public void close()Closes thisNetServerClient, relinquishing any underlying resources. No other method of thisNetServerClientcan be used after this method has been issued. Calling this method more than once is allowed but has no effect after the first invocation.- Specified by:
closein interfaceAutoCloseable
-