Class JMapNetworkConnection

All Implemented Interfaces:
KSchedulerClient

public class JMapNetworkConnection extends JMapBaseNetworkConnection
This class represents a network connection between a client application and JMapServer.
See Also:
  • Constructor Details

    • JMapNetworkConnection

      protected JMapNetworkConnection()
      Creates a raw network connection that won't be initialized until initConnection() is called.
  • Method Details

    • open

      public void open(String host, int port) throws IOException
      Opens a raw network connection with JMapServer using the specified host and port information.
      Specified by:
      open in class JMapBaseNetworkConnection
      Parameters:
      host - IP address or name of JMapServer host
      port - network port to use
      Throws:
      IOException
    • open

      public void open(String host, int port, String proxyPath, String serverId) throws IOException
      Opens a HTTP network connection with JMapServer using the specified host, port, proxy path and serverId. This will create a URL of the form http://host:port/proxyPath?serverId=serverId that will be used for communication between the client application and JMapServer.
      Specified by:
      open in class JMapBaseNetworkConnection
      Parameters:
      host - IP address or name of JMapServer host
      port - network port to use
      proxyPath - the path of the proxy servlet
      serverId - the server to connect to behind the proxy
      Throws:
      IOException
    • open

      public void open(String host, int port, int httpPort, String proxyPath, String serverId, int connectionMode) throws IOException
      Specified by:
      open in class JMapBaseNetworkConnection
      Throws:
      IOException
    • open

      public void open(String protocol, String host, int port, int httpPort, String proxyPath, String serverId, int connectionMode) throws IOException
      Specified by:
      open in class JMapBaseNetworkConnection
      Throws:
      IOException
    • isConnected

      public boolean isConnected()
      Specified by:
      isConnected in class JMapConnection
    • initConnection

      protected void initConnection() throws IOException
      Throws:
      IOException
    • goOffline

      public boolean goOffline()
      This function will force the offline mode.
      Specified by:
      goOffline in class JMapBaseNetworkConnection
      Returns:
      true if successful, false if the connection is already in offline mode
    • goOnline

      public boolean goOnline()
      This function will force the online mode.
      Specified by:
      goOnline in class JMapBaseNetworkConnection
      Returns:
      true if successful
    • pushRequest

      public void pushRequest(JMapRequest request)
      Non-blocking method that pushes a request in the queue. Requests placed in the queue are sent to JMapServer one after the other. When the response is obtained from JMapServer, the client specified in the request object is notified through its callback method.
      Specified by:
      pushRequest in class JMapConnection
      Parameters:
      request - the request to send to JMapServer
      See Also:
    • executeRequest

      public JMapResponse executeRequest(JMapRequest request) throws IOException
      Blocking method that sends a request to JMapServer and returns the response object obtained from JMapServer.

      Notes about the offline mode :
      - If working offline and the auto reconnect option is true, it will try to reconnect before sending the request;
      - If working offline, the OfflineRequestHandler will process the request;
      - If offline mode is not allowed and the connection is lost, a null response will be returned;
      Specified by:
      executeRequest in class JMapConnection
      Parameters:
      request - the request to send to JMapServer
      Returns:
      response from JMapServer (working online) or OfflineRequestHandler (worling offline). null will be return if disconnected and offline mode is not allowed
      Throws:
      IOException
    • cancelRequest

      public boolean cancelRequest(JMapRequest pushedRequest)
      Method that cancels a previously pushed request. The request will be cancelled ONLY if it is NOT currently in execution.
      Parameters:
      pushedRequest -
      Returns:
      true if the cancel was successful
    • executeRequest

      public byte[] executeRequest(byte[] requestBytes) throws IOException
      Blocking method that sends a pre-serialized request (byte array) to JMapServer and returns the serialized response object (byte array) obtained from JMapServer.
      Specified by:
      executeRequest in class JMapConnection
      Parameters:
      requestBytes - the request bytes to send to JMapServer
      Returns:
      the response from JMapServer
      Throws:
      IOException
    • rawSend

      public static void rawSend(byte[] bytes, DataOutputStream os) throws IOException
      Throws:
      IOException
    • rawReceive

      public static byte[] rawReceive(DataInputStream is) throws IOException
      Throws:
      IOException
    • close

      public void close()
      Closes the connection.
      Specified by:
      close in class JMapConnection
    • destroy

      public void destroy()
      Overrides:
      destroy in class JMapBaseNetworkConnection
    • getReadTimeout

      public int getReadTimeout()
    • setReadTimeout

      public void setReadTimeout(int readTimeout)