java.lang.Object
com._1c.g5.v8.dt.internal.platform.services.core.runtimes.execution.DesignerAgentConnection

public class DesignerAgentConnection extends Object
Represents connection to the designer agent.

The connection must be initialized with a client that has already been IDesignerClient.connect(String, int, String, String) and a session obtained via IDesignerClient.openSession() from the same client. However, the connection takes ownership of the supplied client and session and will tie their lifecycle to its own lifecycle.

Before connection can be used, a client must call open(). To close the connection and release all associated resources including closing the supplied designer client, designer session, terminating designer agent process, deleting temporary files, closing the infobase, shutting down the agent via a command call release(boolean, boolean). To temporarily suspend the connection and unlock infobase use suspend() followed by resume().

Instance is not thread-safe. When working with the connection, clients should call use(DesignerAgentConnectionAction) to ensure exclusive access to it. The implementation tries to detect lock contention and logs a warning if wait time is too long.

  • Constructor Details

    • DesignerAgentConnection

      public DesignerAgentConnection(com._1c.g5.designer.ssh.client.IDesignerClient designerClient, com._1c.g5.designer.ssh.client.IDesignerSession designerSession, Process agentProcess, Path agentBaseDirectory, Path connectionDirectory, String userName, String password, String hostname, int port, boolean isLaunchedByIde, boolean resolveUserDirectory)
      Create a new instance of DesignerAgentConnection.
      Parameters:
      designerClient - the started 1C:Enterprise Designer client, cannot be null
      designerSession - the started 1C:Enterprise Designer session, cannot be null
      agentProcess - Designer agent process or null if none. If specified, the process will contribute to isAlive(). Additionally, the process will be automatically terminated when this connection is release(boolean, boolean).
      agentBaseDirectory - the base directory of the connected 1C:Enterprise Designer agent session, cannot be null
      connectionDirectory - the base directory of the agent connection to use as base or null in case the server is remote
      userName - the user name to use or null if none
      isLaunchedByIde - whether the agent is run on this PC and was launched by current IDE process
      resolveUserDirectory - the flag indicating whether user directory has to be resolved.
  • Method Details

    • getSession

      public com._1c.g5.designer.ssh.client.IDesignerSession getSession()
      Returns the connected 1C:Enterprise Designer agent session.
      Returns:
      the connected 1C:Enterprise Designer agent session, never null
    • getInternalSession

      public com._1c.g5.designer.ssh.client.IDesignerSession getInternalSession()
      Returns the internal (not transfering) connected 1C:Enterprise Designer agent session.
      Returns:
      the internal connected 1C:Enterprise Designer agent session, never null
    • setFileTransferEnabled

      public void setFileTransferEnabled(boolean enabled)
      Sets the state of the file transfer whether it is enabled.
      Parameters:
      enabled - the state of the file transfer whether it is enabled
    • getFileTransfer

      public com._1c.g5.designer.ssh.client.IDesignerFileTransfer getFileTransfer()
      Returns the connection file transfer.
      Returns:
      the connection file transfer, never null
    • getAgentBaseDirectory

      public Path getAgentBaseDirectory()
      Returns the base directory of the connected 1C:Enterprise Designer agent session.
      Returns:
      the base directory of the connected 1C:Enterprise Designer agent session, never null
    • getConnectionDirectory

      public Path getConnectionDirectory()
      Returns the base directory of the agent connection to use as base. May differ from agent directory.
      Returns:
      the base directory of the agent connection to use as base or null in case the server is remote
    • isAlive

      public boolean isAlive()
      Returns whether the connection is alive.
      Returns:
      whether the connection is alive
    • suspend

      public void suspend() throws RuntimeExecutionException
      Suspends designer agent connection with the infobase.

      It is assumed that the connection is already open(). The method neither disconnects SSH session, nor terminates designer agent. Designer agent just gets disconnected from the infobase via "common disconnect-ib" command. As a result, the infobase could be temporarily accessed through other means. To reconnect agent back to the infobase use resume().

      Any registered state change listeners will not be notified that connection has been closed.

      Throws:
      RuntimeExecutionException - If execuring "common disconnect-ib" command fails.
      See Also:
    • resume

      public void resume() throws RuntimeExecutionException
      Resumes connection after a previous call to suspend().

      The connection is assumed to be already open() but suspeneded via suspend(). The agent is just told to reconnect to the infobase. Any registered state change listeners will not be notified that connection has been resumed.

      Throws:
      RuntimeExecutionException - If agent fails to reconnect to the infobase or communication with the agent fails.
    • open

      public void open() throws RuntimeExecutionException
      Opens Designer agent connection.

      Any registered state change listeners will not be notified that connection has been (re)opened.

      Throws:
      RuntimeExecutionException - if execution fails
    • release

      public void release(boolean gracefully, boolean cleanDirectory) throws RuntimeExecutionException
      Release the connection.

      Connection is no longer valid to use after release. Release may be invoked multiple times: if connection is already released, method will do nothing.

      If client is connected, was started by IDE and is a designer agent (rather than standalone server) then "common shutdown" command will be sent to it. If agent process was specified then it is forcibly terminated.

      Registered state change listeners will be notified that this connection has been IDesignerAgentConnectionListener.closed().

      Parameters:
      gracefully - true if should gracefully disconnect agent from the infobase (if connected) by sending "common disconnect-ib" and "common shutdown" commands to designer agent. Otherwise, just release resources without sending any commands.
      cleanDirectory - whether need to clean base directory
      Throws:
      RuntimeExecutionException - if release fails
    • setConnectionTimeout

      public void setConnectionTimeout(Duration connectionTimeout)
      Sets connection timeout to use.
      Parameters:
      timeout - the connection timeout to use, cannot be null
    • addListener

      public void addListener(IDesignerAgentConnectionListener listener)
      Adds listener that will be notified about state changes.

      If listener outlives this connection, it should be removed using removeListener(com._1c.g5.v8.dt.platform.services.core.runtimes.execution.IDesignerAgentConnectionListener). Attempts to add already registered listeners are ignored.

      Parameters:
      listener - Listener to be registered for getting notifications about connection state changes. Must not be null.
    • removeListener

      public void removeListener(IDesignerAgentConnectionListener listener)
      Removes previously registered state change listener.

      Attempts to remove listeners that are not registered are ignored.

      Parameters:
      listener - Listener that is to be unregistered. Must not be null.
    • replace

      public void replace(DesignerAgentConnection oldConnection)
      Configures this connection to replace other connection.

      More specifically, state change listeners from the old connection are migrated to the new connection and are notified about reconnection. Old connection should not be used anymore to avoid misnotifying state change listeners.

      Parameters:
      oldConnection - Old connection that is being replaced. Must not be null.
    • getDevelopmentServerType

      public DevelopmentServerType getDevelopmentServerType()
      Returns the type of the connected remote 1C:Enterprise development server.
      Returns:
      the type of the connected remote 1C:Enterprise development server, never null
    • use

      public <T, E1 extends Throwable, E2 extends Throwable> T use(DesignerAgentConnection.DesignerAgentConnectionAction<T,E1,E2> action) throws E1, E2
      Executes action using the connection exclusively.

      Instances of the class are not thread safe and clients have to make sure they do not use the connection in a concurrent way. The method allows clients to ensure that they use the connection exclusively.

      Type Parameters:
      T - Type of value returned by action.
      E1 - Type of exception thrown by action.
      E2 - Type of exception thrown by action.
      Parameters:
      action - Action that uses the connection. Must not be .
      Returns:
      The same value as action returns.
      Throws:
      E1 - The same exception as action throws.
      E2 - The same exception as action throws.
    • toString

      public String toString()
      Overrides:
      toString in class Object