de.esprit.netsuite.client.netch

## Class ClientNetworkAdapter<C extends ClientContext>

- java.lang.Object
- - de.esprit.common.util.DumpableObject
  - - de.esprit.appsuite.launch.AbstractApplicationObject<C>
    - - de.esprit.netsuite.client.AbstractClientObject<C>
      - - de.esprit.netsuite.client.netch.ClientNetworkAdapter<C>

- All Implemented Interfaces:
    ApplicationObject<C>, SimpleLogSupport, Dumpable, ClientObject<C>, NetworkConnectionEvent.Source
  Direct Known Subclasses:
    IOClientNetworkAdapter

      public abstract class ClientNetworkAdapter<C extends ClientContext>
      extends AbstractClientObject<C>
      implements NetworkConnectionEvent.Source

  This class groups both `ClientRequestConnection` and `ClientMessageConnection` maintaining them together as a session. Note that the messageConnection is the reference for the connected-state. It is established AFTER the requestConnection and used as synchronization point for a disconnect. Furthermore it is the only connection that is able to detect a connection loss.
  Author:
    Rainer Buesch

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ClientNetworkAdapter(C clientCtx, ServerHost serverHost, StreamWrapper streamWrapper)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addNetworkConnectionListener(NetworkConnectionEvent.Listener l)`
    `void` | `checkConnected()`
    `void` | `confirmResponse()`
    `void` | `connect()`
    `protected abstract ClientMessageConnection` | `createMessageConnection(LogChannel logCh, ServerHost serverHost, StreamWrapper streamWrapper)`
    `protected abstract ClientRequestConnection` | `createRequestConnection(LogChannel logCh, ServerHost serverHost, StreamWrapper streamWrapper, VersionCheck versionCheck)`
    `boolean` | `disconnect()`
    `java.lang.String` | `getClientConnectionInfo()`
    `java.sql.Timestamp` | `getConnectedSinceTs()` Returns the timestamp of the last connection or null if the client is disconnected.
    `java.lang.String` | `getServerConnectionInfo()`
    `ServerHost` | `getServerHost()`
    `ServerId` | `getServerId()`
    `SessionId` | `getSessionId()`
    `boolean` | `isConnected()` Actually returns the state of the messageConnection, which is the reference for the connected-state.
    `boolean` | `isLoggedIn()`
    `boolean` | `isReceivingMessages()`
    `void` | `removeNetworkConnectionListener(NetworkConnectionEvent.Listener l)`
    `void` | `sendClientTimeoutTest()` For testing purposes only
    `NetResponse` | `sendRequest(NetRequest request)` Sends a `NetRequest` object to the server and returns the `NetResponse` object to the client.
    `void` | `setConnectionTimeout(int timeoutSeconds)`
    `void` | `setMessageDispatcher(ClientMessageHandler messageDispatcher)` Sets the handler `ClientMessageHandler` for dispatching incoming messages.
    `void` | `shutdown()` This method is called when a connection loss is discovered by the message receive thread.

    - ### Methods inherited from class de.esprit.netsuite.client.AbstractClientObject

      `getClientConfig, getClientContext`

    - ### Methods inherited from class de.esprit.appsuite.launch.AbstractApplicationObject

      `getApplicationContext, getLogChannel, isLogDebug, isLogVerbose, logDebug, logDump, logError, logError, logFatal, logInfo, logVerbose, logWarning, setLogChannel`

    - ### Methods inherited from class de.esprit.common.util.DumpableObject

      `configureDumpHeadlineLength, configureDumpMaxElementsPrinted, copyDumpStringValues, copyToStringValues, createDumpHeader, toDumpString, toDumpString, toString, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### ClientNetworkAdapter

          public ClientNetworkAdapter(C clientCtx,
                              ServerHost serverHost,
                              StreamWrapper streamWrapper)

  - ### Method Detail

    - #### setMessageDispatcher

          public void setMessageDispatcher(ClientMessageHandler messageDispatcher)

      Sets the handler `ClientMessageHandler` for dispatching incoming messages.
      Note
        Setting the messageDispatcher starts an inner task for processing the input queue, setting it to null will stop queue processing.

    - #### confirmResponse

          public final void confirmResponse()
                                     throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### getServerHost

          public final ServerHost getServerHost()

    - #### getServerId

          public final ServerId getServerId()

    - #### isConnected

          public final boolean isConnected()

      Actually returns the state of the messageConnection, which is the reference for the connected-state.

    - #### getSessionId

          public final SessionId getSessionId()

    - #### getClientConnectionInfo

          public final java.lang.String getClientConnectionInfo()

    - #### getServerConnectionInfo

          public final java.lang.String getServerConnectionInfo()

    - #### isLoggedIn

          public final boolean isLoggedIn()

    - #### connect

          public final void connect()
                             throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### setConnectionTimeout

          public final void setConnectionTimeout(int timeoutSeconds)

    - #### isReceivingMessages

          public final boolean isReceivingMessages()

    - #### disconnect

          public final boolean disconnect()

    - #### shutdown

          public final void shutdown()

      This method is called when a connection loss is discovered by the message receive thread. It enforces a DISCONNECTED event without trying to contact the server.

    - #### getConnectedSinceTs

          public final java.sql.Timestamp getConnectedSinceTs()

      Returns the timestamp of the last connection or null if the client is disconnected.

    - #### sendRequest

          public final NetResponse sendRequest(NetRequest request)
                                        throws java.lang.Exception

      Sends a `NetRequest` object to the server and returns the `NetResponse` object to the client. Note that the response object is guaranteed not to be null but it must be checked for errors with the hasError() method.
      Throws:
        `java.lang.Exception`

    - #### checkConnected

          public void checkConnected()
                              throws ClientNotConnectedException

      Throws:
        `ClientNotConnectedException`

    - #### sendClientTimeoutTest

          public final void sendClientTimeoutTest()
                                           throws java.lang.Exception

      For testing purposes only
      Throws:
        `java.lang.Exception`

    - #### addNetworkConnectionListener

          public final void addNetworkConnectionListener(NetworkConnectionEvent.Listener l)

      Specified by:
        `addNetworkConnectionListener` in interface `NetworkConnectionEvent.Source`

    - #### removeNetworkConnectionListener

          public final void removeNetworkConnectionListener(NetworkConnectionEvent.Listener l)

      Specified by:
        `removeNetworkConnectionListener` in interface `NetworkConnectionEvent.Source`

    - #### createRequestConnection

          protected abstract ClientRequestConnection createRequestConnection(LogChannel logCh,
                                                        ServerHost serverHost,
                                                        StreamWrapper streamWrapper,
                                                        VersionCheck versionCheck)

    - #### createMessageConnection

          protected abstract ClientMessageConnection createMessageConnection(LogChannel logCh,
                                                        ServerHost serverHost,
                                                        StreamWrapper streamWrapper)

Copyright © 2014 EsprIT-Systems. All Rights Reserved.