Class NetServerClient

java.lang.Object
cl.obcom.desktopfx.netserver.NetServerClient
All Implemented Interfaces:
AutoCloseable

public abstract class NetServerClient extends Object implements 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 Details

    • getTask

      public final DesktopTask getTask()
      Returns the DesktopTask of this NetServerClient.
      Returns:
      the DesktopTask or null if none defined.
    • getDescription

      public final String getDescription()
      Returns the description of this NetServerClient.
      Returns:
      the description of this NetServerClient.
    • isConnected

      public final boolean isConnected()
      Returns true if connected to the OBCOM NetServer.
      Returns:
      true if connected to the OBCOM NetServer.
    • isAlive

      public final boolean isAlive()
      Returns true if this NetServerClient is alive. A NetServerClient becomes dead when a System Operator executes the "kill client" command in an OBCOM NetServer console.
      Returns:
      true if this NetServerClient is alive.
    • getChannel

      public final NetServerChannel getChannel()
      Returns the NetServerChannel of this NetServerClient.
      Returns:
      the NetServerChannel of this NetServerClient.
      Throws:
      RuntimeException - if this client is not alive.
    • getEncryptAll

      public final boolean getEncryptAll()
      Returns true 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()
      Returns true 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()
      Returns true 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 - if true the signatures of downloaded layouts will be verified, otherwise the signatures will be assigned to layouts without verification.
    • getLayout

      public final Layout getLayout(String name) throws Exception
      Returns the Layout with the specified name. 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 if getVerifyLayoutSignatures() returns true, otherwise the signature will be assigned to the layout without verification.
      Parameters:
      name - name of the required Layout.
      Returns:
      the Layout with the specified name.
      Throws:
      NullPointerException - if name is null.
      Exception - if an error occurs while loading the layout.
    • getAutoAssignLayout

      public final boolean getAutoAssignLayout()
      Returns true if the assignLayout method is automatically applied to all reply or published messages received from the OBCOM NetServer.
      Returns:
      true if the assignLayout method is applied to all reply or published messages.
    • setAutoAssignLayout

      public final void setAutoAssignLayout(boolean value)
      Changes whether the assignLayout method is automatically applied to all reply or published messages received from the OBCOM NetServer.
      Parameters:
      value - if true the assignLayout method will be applied to all reply or published messages.
    • assignLayout

      public final void assignLayout(NetServerMessage message) throws Exception
      The message is assigned the layout identified by its LayoutName label. If the message has no such label, then nothing is done. If the message has a LayoutSignature 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 - if message is null.
      IllegalArgumentException - if the signatures of the message and the layout are not equal.
      Exception - if another error occurs.
    • getTimestamp

      public final String getTimestamp() throws Exception
      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

      public final NetServerMessage execute(String service, Object arguments) throws Exception
      Executes a service with arguments 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 is null.
      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 a service with arguments and returns a result message. If encrypted is true 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 - if true the communication will be encrypted.
      Returns:
      the service execution result message.
      Throws:
      NullPointerException - if an argument is null.
      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 a service with arguments and returns a result message. The service 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 optional HostName is not specified, then the OBCOM NetServer Default Host will be used. TranName is the name of the requested transaction, while TranCode is and alternative one-character identification of the same transaction. Either TranName or TranCode must be specified. The following are some examples of service names:
       ECUSER.[!]
       ACASER.ACA-TIME
       HUB.IMSER.AddContact
      The arguments object will be converted to a String using the standard toString method, hence any object can be used as argument for a service.

      If encrypted is true then all communication with the OBCOM NetServer will be encrypted.

      The timeout argument specifies the amount of milliseconds to wait for the result message. If timeout 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 - if true 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 is null.
      IllegalArgumentException - if an argument value is invalid.
      SocketTimeoutException - if timeout occurs.
      Exception - if another error occurs.
    • subscribe

      public final void subscribe(String name, EventHandler<MulticastEvent> handler) throws Exception
      Subscribes to messages published with the specified name. When someone publishes a message with the given name, the supplied handler is called. The name argument has the following format:
       {HostName.}MulticastName
      where optional items are shown within "{" and "}" brackets, and the character "." stands for itself. If the optional HostName is not specified, then the OBCOM NetServer Default Host will be used. The required MulticastName 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 is null.
      IllegalArgumentException - if name is invalid.
      Exception - if another error occurs.
    • unsubscribe

      public final void unsubscribe(String name, EventHandler<MulticastEvent> handler) throws Exception
      Unsubscribes from messages published with the specified name. The name argument has the following format:
       {HostName.}MulticastName
      where optional items are shown within "{" and "}" brackets, and the character "." stands for itself. If the optional HostName is not specified, then the OBCOM NetServer Default Host will be used. The required MulticastName has a minimum length of 1 and a maximum length of 10 characters. If MulticastName equals "*", this method disables the reception of all multicast messages enabled with the subscribe 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 is null.
      IllegalArgumentException - if name is invalid.
      Exception - if another error occurs.
    • close

      public final void close()
      Closes this NetServerClient, relinquishing any underlying resources. No other method of this NetServerClient 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 interface AutoCloseable