The Connection object that represents a live connection. There must be only a single Connection object instance per connection. The connection instances are stored in ConnectionRepository.
@Component @Qualifier(value = "connection") @Scope(value = "prototype") public class Connection { /* * Some third party client which enables the communications between * vRO and the third party system. Can be a http client, SSH client etc. */ private ThirdPartyClient thirdPartyClient; /* * The connectionInfo which stands behind this live connection. */ private ConnectionInfo connectionInfo; /* * There is no default constructor, the Connection must be * initialized only with a connection info argument. */ public Connection(ConnectionInfo info) { init(info); } public synchronized ConnectionInfo getConnectionInfo() { return connectionInfo; } public String getDisplayName() { return getConnectionInfo().getName() + " [" + getConnectionInfo().getSubscriptionId() + "]"; } /* * Updates this connection with the provided info. This operation will * destroy the existing third party client, causing all associated operations to fail. */ public synchronized void update(ConnectionInfo connectionInfo) { if (this.connectionInfo != null && !connectionInfo.getId().equals(this.connectionInfo.getId())) { throw new IllegalArgumentException("Cannot update using different id"); } destroy(); init(connectionInfo); } private void init(ConnectionInfo connectionInfo) { this.connectionInfo = connectionInfo; } /* * Lazy-initializes the ThirdPartyClient instance */ public synchronized ThirdPartyClient getThirdPartyClient() { if (thirdPartyClient == null) { thirdPartyClient = new ThirdPartyClient(); //Use the connectionInfo to setup the ThirdPartyClient properties //thirdPartyClient.set(..); } return thirdPartyClient; } public synchronized void destroy() { //Destroy the client, releasing all current connections and //possibly cleaning the resources. thirdPartyClient.close(); //Set the client to null so that it can be reinitialized by the //getThirdPartyClient() method thirdPartyClient = null; } }