Class DesignerAgentConnection
java.lang.Object
com._1c.g5.v8.dt.internal.platform.services.core.runtimes.execution.DesignerAgentConnection
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.-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionDesignerAgentConnection
(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 ofDesignerAgentConnection
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(IDesignerAgentConnectionListener listener) Adds listener that will be notified about state changes.Returns the base directory of the connected 1C:Enterprise Designer agent session.Returns the base directory of the agent connection to use as base.Returns the type of the connected remote 1C:Enterprise development server.com._1c.g5.designer.ssh.client.IDesignerFileTransfer
Returns the connection file transfer.com._1c.g5.designer.ssh.client.IDesignerSession
Returns the internal (not transfering) connected 1C:Enterprise Designer agent session.com._1c.g5.designer.ssh.client.IDesignerSession
Returns the connected 1C:Enterprise Designer agent session.boolean
isAlive()
Returns whether the connection is alive.void
open()
Opens Designer agent connection.void
release
(boolean gracefully, boolean cleanDirectory) Release the connection.void
Removes previously registered state change listener.void
replace
(DesignerAgentConnection oldConnection) Configures this connection to replace other connection.void
resume()
Resumes connection after a previous call tosuspend()
.void
setConnectionTimeout
(Duration connectionTimeout) Sets connection timeout to use.void
setFileTransferEnabled
(boolean enabled) Sets the state of the file transfer whether it is enabled.void
suspend()
Suspends designer agent connection with the infobase.toString()
use
(DesignerAgentConnection.DesignerAgentConnectionAction<T, E1, E2> action) Executes action using the connection exclusively.
-
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 ofDesignerAgentConnection
.- Parameters:
designerClient
- the started 1C:Enterprise Designer client, cannot benull
designerSession
- the started 1C:Enterprise Designer session, cannot benull
agentProcess
- Designer agent process ornull
if none. If specified, the process will contribute toisAlive()
. Additionally, the process will be automatically terminated when this connection isrelease(boolean, boolean)
.agentBaseDirectory
- the base directory of the connected 1C:Enterprise Designer agent session, cannot benull
connectionDirectory
- the base directory of the agent connection to use as base ornull
in case the server is remoteuserName
- the user name to use ornull
if noneisLaunchedByIde
- whether the agent is run on this PC and was launched by current IDE processresolveUserDirectory
- 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
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
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
Suspends designer agent connection with the infobase. It is assumed that the connection is alreadyopen()
. 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 useresume()
. 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
Resumes connection after a previous call tosuspend()
. The connection is assumed to be alreadyopen()
but suspeneded viasuspend()
. 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
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
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 beenIDesignerAgentConnectionListener.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
Sets connection timeout to use.- Parameters:
timeout
- the connection timeout to use, cannot benull
-
addListener
Adds listener that will be notified about state changes. If listener outlives this connection, it should be removed usingremoveListener(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 benull
.
-
removeListener
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 benull
.
-
replace
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 benull
.
-
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, T useE2 extends Throwable> (DesignerAgentConnection.DesignerAgentConnectionAction<T, E1, throws E1, E2E2> action) 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
-