Class JMapSrvConnection

All Implemented Interfaces:
KSchedulerClient

public final class JMapSrvConnection extends JMapBaseNetworkConnection
A JMapSrvConnection object is responsible for handling all communications between a JMap application (client) and JMapServer (server). It provides some high level services for executing specific requests like user authentication and geographic data requests. It also provides general services for executing any other type of requests.

All communications between the client and the server follow a simple request-response pattern where the request contains informations about the requested resources and the response contains the execution status (success, failure, etc.), an optional status message and any data that may result from the execution of the request.

By default, all requests are placed in a queue (FIFO) and executed sequentially in the order they were placed in the queue. When a request is executed and a response is received by the server, the initiator of the request is notified by calling its callback method. It can then process the response and do any useful work with it.

See Also:
  • Field Details

  • Constructor Details

    • JMapSrvConnection

      public JMapSrvConnection()
    • JMapSrvConnection

      public JMapSrvConnection(int initialPoolSize, int maxPoolSize)
  • Method Details

    • open

      public void open(String host, int port) throws Exception
      Opens an direct connection to JMapServer.
      Specified by:
      open in class JMapBaseNetworkConnection
      Parameters:
      host - the name or IP address of the server to connect to
      port - the direct connection port
      Throws:
      Exception
    • open

      public void open(String host, int httpPort, String proxyPath, String serverId) throws Exception
      Opens an HTTP connection to JMapServer through JMapProxy servlet.
      Specified by:
      open in class JMapBaseNetworkConnection
      Parameters:
      host - the name or IP address of the server to connect to
      httpPort - the httpPort used by the proxy
      proxyPath - the proxy servlet path to use (e.g. /servlet/jmapproxy)
      serverId - the id of the server to connect to
      Throws:
      Exception
    • open

      public void open(String host, int port, int httpPort, String proxyPath, String serverId, int connectionMode) throws Exception
      Opens an HTTP connection to JMapServer through JMapProxy servlet.
      Specified by:
      open in class JMapBaseNetworkConnection
      Parameters:
      host - the name or IP address of the server to connect to
      port - the direct port used for a direct connection to the server
      httpPort - the httpPort used by the proxy
      proxyPath - the proxy servlet path to use (e.g. /servlet/jmapproxy)
      serverId - the id of the server to connect to
      connectionMode - the type of connection to open
      Throws:
      Exception
    • open

      public void open(ConnectionConfig config) throws IOException
      Opens a new connection to JMapServer using the specified connection configuration.
      Parameters:
      config - the connection configuration to use
      Throws:
      Exception
      IOException
    • open

      public void open(String protocol, String host, int port, int httpPort, String proxyPath, String serverId, int connectionMode) throws IOException
      Opens a new connection to JMapServer. The connection mode (direct or through JMapProxy) is determined by the connectionMode value specified.
      Specified by:
      open in class JMapBaseNetworkConnection
      Parameters:
      protocol - the proxy connection protocol to use (http ou https)
      host - the name or IP address of the server to connect to
      port - the direct port used for a direct connection to the server
      httpPort - the httpPort used by the proxy
      proxyPath - the proxy servlet path to use if directPort is -1
      serverId - the id of the server to connect to
      connectionMode - the type of connection to open
      Throws:
      Exception
      IOException
    • getProductManager

      public ProductManager getProductManager()
    • getProjectionManager

      public ProjectionManager getProjectionManager()
    • openSession

      public int openSession(String username, String password)
      Opens a new desktop session on JMapServer for the specified user. The username must correspond to a valid user and the password must be match that user's password. The username is not case-sensitive but the password is case-sensitive.
      Parameters:
      username - the username used to open the session
      password - the password of the user
      Returns:
      the id of the new session if successful or -1 otherwise
    • openSession

      public int openSession(String username, String password, SessionType sessionType)
    • openSession

      public int openSession(AuthenticationToken authenticationToken, SessionType sessionType)
    • openSession

      public int openSession(int sessionId)
      Opens a new desktop session on JMapServer using the information related to the specified valid session id.
      Parameters:
      sessionId - the owner's session id.
      Returns:
      the id of the new session if successful or -1 otherwise
    • openSession

      public int openSession(int sessionId, boolean closeSession, SessionType sessionType)
      Opens a new session on JMapServer using the information related to the specified valid session id.
      Parameters:
      sessionId - the owner's session id.
      closeSession - specified whether to close the JMap session related the specified session id before opening the new session.
      sessionType - the session type to open.
      Returns:
      the id of the new session if successful or -1 otherwise
    • useExistingSession

      public int useExistingSession(int sessionId)
      Attach to an existing session using the specified session id. The corresponding session must be already open on JMapServer.
      Parameters:
      sessionId - the session id to attach to
      Returns:
      the same session id if successful or -1 otherwise
    • closeSession

      public void closeSession()
      Closes the session on JMapServer. The session should always be closed when the application exists to free resources on JMapServer.
    • getCurrentUserInfo

      public UserInfo getCurrentUserInfo()
      Returns the current authenticated user info.
      Returns:
      the current authenticated user info
    • getSessionId

      public int getSessionId()
      Returns the session token for the current authenticated user.
      Returns:
      the session token for the current authenticated user or -1 if user is anonymous
    • getServerId

      public String getServerId()
      Returns the current server id.
      Returns:
      the current server id.
    • getUserInfo

      public List<UserInfo> getUserInfo()
      Returns information about the users present in JMapServer. This information includes full name, e-mail address and description.
      Returns:
      a vector containing UserInfo instances
    • getSessionInfo

      public SessionInfo getSessionInfo()
      Returns the current session info.
      Returns:
      a session info
    • getLogos

      public final Object[] getLogos()
      Returns:
      the map logo and the expiration logo that appears if JMap version is expired
    • getJMSUID

      public String getJMSUID()
      Get the UID from the currently connected JMapServer
      Returns:
      the JMapServer Unique ID (Serial Number)
    • getServerTimeAdjustment

      public long getServerTimeAdjustment()
    • getServerVersion

      public String getServerVersion()
    • getExternalAuthenticator

      public ExternalAuthenticator<?> getExternalAuthenticator()
    • executeRequest

      public JMapResponse executeRequest(JMapRequest request)
      Sends the specified request and waits for the response from JMapServer. This method is blocking. If another request is already executing when this method is called, the specified request will be executed as soon as the other request terminates.
      Specified by:
      executeRequest in class JMapConnection
      Parameters:
      request - the request to execute
      Returns:
      the response from JMapServer
      See Also:
    • executeRequest

      public <T extends JMapResponse> T executeRequest(JMapRequest req, Class<T> resType)
      Execute JMapServer request and return a generic response.
      Returns:
      JMapResponse generic instance
      Since:
      7.0 Funafuti
    • close

      public void close()
      Closes all opened resources used by the connection. Also calls closeSession().
      Specified by:
      close in class JMapConnection
    • finalize

      protected void finalize() throws Throwable
      Overrides:
      finalize in class JMapBaseNetworkConnection
      Throws:
      Throwable
    • destroy

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

      public String getLastMessage()
      Returns the message of the last request made to JMapServer.
      Returns:
      the message of the last request made to JMapServer.
    • getLastStatus

      public int getLastStatus()
      Returns the status of the last request made to JMapServer.
      Returns:
      the status of the last request made to JMapServer.
      See Also:
    • executePendingRequests

      public void executePendingRequests()
      Executes all pending requests of the current logged user.
    • deleteAllPendingRequests

      public void deleteAllPendingRequests()
      Deletes all pending requests of the current logged user.
    • getPassword

      public String getPassword()
      Returns the password passed to the last openSession(String, String) method.
      Returns:
      the current user password
    • isMaxSessionExceeded

      public boolean isMaxSessionExceeded()
    • isServerLicenseExpired

      public boolean isServerLicenseExpired()
    • addSrvConnectionListener

      public void addSrvConnectionListener(JMapSrvConnectionListener listener)
    • removeSrvConnectionListener

      public void removeSrvConnectionListener(JMapSrvConnectionListener listener)
    • getLayerInfo

      public LayerInfo getLayerInfo(String projectName, String layerName)
      Gets the layer info for a specific layer that is part of a specific project.
      Parameters:
      projectName - the name of the project
      layerName - the name of the layer
      Returns:
      the layer info for the specified layer if it exists; if it doesn't exist, null is returned
      See Also:
    • getLayersConfig

      public JMapSrvConnection.LayersConfig getLayersConfig(int projectId)
    • getUnavailableLayers

      public int getUnavailableLayers()
    • readFromByteArray

      public static JMapSrvConnection.LayersConfig readFromByteArray(byte[] byteArray)
    • getOfflineRequestHandler

      public OfflineRequestHandler getOfflineRequestHandler()
    • getLastUsername

      public String getLastUsername()
    • goOffline

      public boolean goOffline()
      Force the offline mode on all pool connections.
      Specified by:
      goOffline in class JMapBaseNetworkConnection
      Returns:
      true if successful, false if the connection is already in offline mode
    • goOnline

      public boolean goOnline()
      Force the online mode on all pool connections.
      Specified by:
      goOnline in class JMapBaseNetworkConnection
      Returns:
      true if successful
    • executeRequest

      public byte[] executeRequest(byte[] requestBytes) throws IOException
      Non-blocking method that sends a pre-serialized request (byte array) to JMapServer and returns the serialized response object (byte array) obtained from JMapServer. Execute the request using a pool of network connections.
      Specified by:
      executeRequest in class JMapConnection
      Parameters:
      requestBytes - the request bytes to send to JMapServer
      Returns:
      the response from JMapServer
      Throws:
      IOException
    • pushRequest

      public void pushRequest(JMapRequest request)
      Non-blocking method that push the request execution on a separate thread. Requests are not placed in a queue here. When the response is returned from JMapServer, the client is notified through its callback.
      Specified by:
      pushRequest in class JMapConnection
      Parameters:
      request - the request to send to JMapServer
      See Also:
    • isConnected

      public boolean isConnected()
      Monitor the connection status.
      Specified by:
      isConnected in class JMapConnection
      Returns:
      true if at least one connection is connected
    • getNbPendingRequests

      public int getNbPendingRequests()
      Returns the number of pending requests.
      Returns:
      number of pending requests
    • setReadTimeout

      public void setReadTimeout(int readTimeout)