Package cl.obcom.desktopfx.netserver
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 TypeMethodDescriptionfinal void
assignLayout
(NetServerMessage message) Themessage
is assigned the layout identified by itsLayoutName
label.final void
close()
Closes thisNetServerClient
, relinquishing any underlying resources.final NetServerMessage
Executes aservice
witharguments
and returns a result message.final NetServerMessage
Executes aservice
witharguments
and returns a result message.final NetServerMessage
Executes aservice
witharguments
and returns a result message.final boolean
Returnstrue
if theassignLayout
method is automatically applied to all reply or published messages received from the OBCOM NetServer.final boolean
Returnstrue
if login is performed after connecting to OBCOM NetServer.final NetServerChannel
Returns theNetServerChannel
of thisNetServerClient
.final String
Returns the description of thisNetServerClient
.final boolean
Returnstrue
if all messages are sent encrypted to OBCOM NetServer.final Layout
Returns theLayout
with the specifiedname
.final DesktopTask
getTask()
Returns theDesktopTask
of thisNetServerClient
.final String
Returns an OBCOM NetServer timestamp.final boolean
Returnstrue
if the signatures of downloaded layouts are verified.final boolean
isAlive()
Returnstrue
if thisNetServerClient
is alive.final boolean
Returnstrue
if connected to the OBCOM NetServer.final void
setAutoAssignLayout
(boolean value) Changes whether theassignLayout
method is automatically applied to all reply or published messages received from the OBCOM NetServer.final void
setVerifyLayoutSignatures
(boolean value) Changes whether the signatures of downloaded layouts are verified.final void
subscribe
(String name, EventHandler<MulticastEvent> handler) Subscribes to messages published with the specifiedname
.final void
unsubscribe
(String name, EventHandler<MulticastEvent> handler) Unsubscribes from messages published with the specifiedname
.
-
Method Details
-
getTask
Returns theDesktopTask
of thisNetServerClient
.- Returns:
- the
DesktopTask
ornull
if none defined.
-
getDescription
Returns the description of thisNetServerClient
.- Returns:
- the description of this
NetServerClient
.
-
isConnected
public final boolean isConnected()Returnstrue
if connected to the OBCOM NetServer.- Returns:
true
if connected to the OBCOM NetServer.
-
isAlive
public final boolean isAlive()Returnstrue
if thisNetServerClient
is alive. ANetServerClient
becomes dead when a System Operator executes the "kill client
" command in an OBCOM NetServer console.- Returns:
true
if this NetServerClient is alive.
-
getChannel
Returns theNetServerChannel
of thisNetServerClient
.- Returns:
- the
NetServerChannel
of thisNetServerClient
. - Throws:
RuntimeException
- if this client is not alive.
-
getEncryptAll
public final boolean getEncryptAll()Returnstrue
if all messages are sent encrypted to OBCOM NetServer.- Returns:
true
if all messages are sent encrypted to OBCOM NetServer.
-
getAutoLogin
public final boolean getAutoLogin()Returnstrue
if login is performed after connecting to OBCOM NetServer.- Returns:
true
if login is performed after connecting to OBCOM NetServer.
-
getVerifyLayoutSignatures
public final boolean getVerifyLayoutSignatures()Returnstrue
if the signatures of downloaded layouts are verified.- Returns:
true
if the signatures of downloaded layouts are verified.
-
setVerifyLayoutSignatures
public final void setVerifyLayoutSignatures(boolean value) Changes whether the signatures of downloaded layouts are verified.- Parameters:
value
- iftrue
the signatures of downloaded layouts will be verified, otherwise the signatures will be assigned to layouts without verification.
-
getLayout
Returns theLayout
with 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
Layout
with the specifiedname
. - Throws:
NullPointerException
- ifname
isnull
.Exception
- if an error occurs while loading the layout.
-
getAutoAssignLayout
public final boolean getAutoAssignLayout()Returnstrue
if theassignLayout
method is automatically applied to all reply or published messages received from the OBCOM NetServer.- Returns:
true
if theassignLayout
method is applied to all reply or published messages.
-
setAutoAssignLayout
public final void setAutoAssignLayout(boolean value) Changes whether theassignLayout
method is automatically applied to all reply or published messages received from the OBCOM NetServer.- Parameters:
value
- iftrue
theassignLayout
method will be applied to all reply or published messages.
-
assignLayout
Themessage
is assigned the layout identified by itsLayoutName
label. If themessage
has no such label, then nothing is done. If themessage
has aLayoutSignature
label, 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
- ifmessage
isnull
.IllegalArgumentException
- if the signatures of themessage
and 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 aservice
witharguments
and 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 final NetServerMessage execute(String service, Object arguments, boolean encrypted) throws Exception Executes aservice
witharguments
and returns a result message. Ifencrypted
istrue
the 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
- iftrue
the 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 final NetServerMessage execute(String service, Object arguments, boolean encrypted, long timeout) throws Exception Executes aservice
witharguments
and returns a result message. Theservice
name 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 optionalHostName
is not specified, then the OBCOM NetServer Default Host will be used.TranName
is the name of the requested transaction, whileTranCode
is and alternative one-character identification of the same transaction. EitherTranName
orTranCode
must be specified. The following are some examples of service names:ECUSER.[!] ACASER.ACA-TIME HUB.IMSER.AddContact
Thearguments
object will be converted to aString
using the standardtoString
method, hence any object can be used as argument for a service.If
encrypted
istrue
then all communication with the OBCOM NetServer will be encrypted.The
timeout
argument specifies the amount of milliseconds to wait for the result message. Iftimeout
is 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
- iftrue
the 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 suppliedhandler
is called. Thename
argument has the following format:{HostName.}MulticastName
where optional items are shown within "{" and "}" brackets, and the character "." stands for itself. If the optionalHostName
is not specified, then the OBCOM NetServer Default Host will be used. The requiredMulticastName
has 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
- ifname
is invalid.Exception
- if another error occurs.
-
unsubscribe
Unsubscribes from messages published with the specifiedname
. Thename
argument has the following format:{HostName.}MulticastName
where optional items are shown within "{" and "}" brackets, and the character "." stands for itself. If the optionalHostName
is not specified, then the OBCOM NetServer Default Host will be used. The requiredMulticastName
has a minimum length of 1 and a maximum length of 10 characters. IfMulticastName
equals"*"
, this method disables the reception of all multicast messages enabled with thesubscribe
method.- 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
- ifname
is invalid.Exception
- if another error occurs.
-
close
public final void close()Closes thisNetServerClient
, relinquishing any underlying resources. No other method of thisNetServerClient
can 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:
close
in interfaceAutoCloseable
-