Class RedundantConnectionManagerImpl
- java.lang.Object
-
- sk.ipesoft.d2000.d2japi.connector.RedundantConnectionManagerImpl
-
- All Implemented Interfaces:
D2SessionFactory,RedundantConnectionManager
public class RedundantConnectionManagerImpl extends java.lang.Object implements RedundantConnectionManager
Default implementation of RedundantConnectionManager.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close connection to D2000.static RedundantConnectionManagercreate(java.lang.String localInterface, int localPort, java.lang.String certificatePath, java.util.List<java.lang.String> allowedHosts, RedundantConnectionEventListener listener, long retryTime, java.util.concurrent.TimeUnit retryUnit, boolean disconnectStandBySessions)Create new instance of RedundantConnectionManager for handling reverse connections using TLS socket.static RedundantConnectionManagercreate(java.util.List<ConnectionParameters> connectionParameters, RedundantConnectionEventListener listener, long retryTime, java.util.concurrent.TimeUnit retryUnit, boolean disconnectStandBySessions)Create new instance of RedundantConnectionManager for handling direct connections.java.util.concurrent.Future<D2Session>createSession(D2SessionParameters sessionParams, D2SessionEventsListener eventsListener)Create new session object, connect it to D2000 and authorize it with valid D2000 user account.java.util.concurrent.Future<D2Session>createSession(D2SessionParameters sessionParams, D2SessionEventsListener eventsListener, java.util.Set<SharedResourceType> interestSet)Create new session object, connect it to D2000 and authorise it with valid D2000 user account.java.util.List<D2Connector>getConnectorsSnapshot()Get snapshot of list of current connectors.RedundantConnectionEventListenergetRedundantConnectionEventListener()Get reference to the connection event listener.booleanisClosed()GettrueafterD2SessionFactory.close()has been called.voidsetAutonomousWatchdog(boolean value)Set autonomousWatchdog statevalueto all managed connectors.
-
-
-
Method Detail
-
create
public static RedundantConnectionManager create(java.util.List<ConnectionParameters> connectionParameters, RedundantConnectionEventListener listener, long retryTime, java.util.concurrent.TimeUnit retryUnit, boolean disconnectStandBySessions)
Create new instance of RedundantConnectionManager for handling direct connections.Instance runs background job that tries to keep opened
D2Connectorinstances for each item ofconnectionParameterslist.When request for new
D2Sessionoccurs, it tries to create a new session with each of opened connector and returns the one connected to HOT kernel. Other sessions are closed. It repeats its attempts until HOT session is obtained with(retryTime, retryUnit)sleep interval.- Parameters:
connectionParameters- list of address:port pairs with optional path to certificate file.listener- optional listener that receives events about underlying D2Connectors.retryTime- sleep period sizeretryUnit- sleep period time unitdisconnectStandBySessions- automatically disconnects all active sessions when attached- Returns:
- new instance of RedundantConnectionManager
-
create
public static RedundantConnectionManager create(java.lang.String localInterface, int localPort, java.lang.String certificatePath, java.util.List<java.lang.String> allowedHosts, RedundantConnectionEventListener listener, long retryTime, java.util.concurrent.TimeUnit retryUnit, boolean disconnectStandBySessions) throws ConnectorException
Create new instance of RedundantConnectionManager for handling reverse connections using TLS socket.Instance opens socket for listening at specified address and waits for incoming connections. It compares each incoming connection address with list of
allowedHosts(resolves the list to IP addresses) and accepts one that is found in the list. Other connections are rejected.When request for new
D2Sessionoccurs, it tries to create a new session with each of opened connector and returns the one connected to HOT kernel. Other sessions are closed. It repeats its attempts until HOT session is obtained with(retryTime, retryUnit)sleep interval.- Parameters:
localInterface- address of specific interface ornullfor all interfaceslocalPort- number of port for listening socket from range 1 .. 0xFFFF.certificatePath- optional path to file with certificate for TLS connectionallowedHosts- list of host names or IP addresses that are allowed to connectlistener- optional listener that receives events about underlying D2Connectors.retryTime- sleep period sizeretryUnit- sleep period time unitdisconnectStandBySessions- automatically disconnects all active sessions when attached- Returns:
- new instance of RedundantConnectionManager
- Throws:
ConnectorException- when unable to open listening socket
-
getConnectorsSnapshot
public java.util.List<D2Connector> getConnectorsSnapshot()
Description copied from interface:RedundantConnectionManagerGet snapshot of list of current connectors.- Specified by:
getConnectorsSnapshotin interfaceRedundantConnectionManager- Returns:
-
getRedundantConnectionEventListener
public RedundantConnectionEventListener getRedundantConnectionEventListener()
Description copied from interface:RedundantConnectionManagerGet reference to the connection event listener.- Specified by:
getRedundantConnectionEventListenerin interfaceRedundantConnectionManager- Returns:
- reference to the connection event listener
-
isClosed
public boolean isClosed()
Description copied from interface:D2SessionFactoryGettrueafterD2SessionFactory.close()has been called. Indicates that no new session can be created and all created sessions has been terminated.- Specified by:
isClosedin interfaceD2SessionFactory- Returns:
truewhen closed;
-
setAutonomousWatchdog
public void setAutonomousWatchdog(boolean value)
Description copied from interface:RedundantConnectionManagerSet autonomousWatchdog statevalueto all managed connectors.- Specified by:
setAutonomousWatchdogin interfaceRedundantConnectionManager- Parameters:
value-trueto activate orfalsedo deactivate
-
createSession
public java.util.concurrent.Future<D2Session> createSession(D2SessionParameters sessionParams, D2SessionEventsListener eventsListener)
Description copied from interface:D2SessionFactoryCreate new session object, connect it to D2000 and authorize it with valid D2000 user account.Operation is executed in background thread and goes through following steps:
- Create new instance.
- Connect session to the D2000 kernel.
- Logon to the D2000 kernel with provided user account.
- Future result may throw
ExecutionExceptionwithcause: ConnectSessionException- when kernel refused connection of the sessionLoginFailedException- when kernel refused to logon with provided user account
- Specified by:
createSessionin interfaceD2SessionFactory- Parameters:
sessionParams- authentication informationeventsListener- instance of event listener object to receive asynchronous events from D2000 session- Returns:
- upcoming session object in form of future
-
createSession
public java.util.concurrent.Future<D2Session> createSession(D2SessionParameters sessionParams, D2SessionEventsListener eventsListener, java.util.Set<SharedResourceType> interestSet)
Description copied from interface:D2SessionFactoryCreate new session object, connect it to D2000 and authorise it with valid D2000 user account.Operation is executed in background thread and goes through following steps:
- Create new instance.
- Report current state of shared resources to the
sharedResourcesListener. - Connect session to the D2000 kernel.
- Logon to the D2000 kernel with provided user account.
- Future result may throw
ExecutionExceptionwithcause: ConnectSessionException- when kernel refused connection of the sessionLoginFailedException- when kernel refused to logon with provided user account
- Specified by:
createSessionin interfaceD2SessionFactory- Parameters:
sessionParams- authentication informationeventsListener- instance of event listener object to receive asynchronous events from D2000 sessioninterestSet- interesting shared resource types- Returns:
- upcoming session object in form of future
-
close
public void close()
Description copied from interface:D2SessionFactoryClose connection to D2000.- Specified by:
closein interfaceD2SessionFactory
-
-