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 void
close()
Close connection to D2000.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)
Create new instance of RedundantConnectionManager for handling reverse connections using TLS socket.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.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.RedundantConnectionEventListener
getRedundantConnectionEventListener()
Get reference to the connection event listener.boolean
isClosed()
Gettrue
afterD2SessionFactory.close()
has been called.
-
-
-
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
D2Connector
instances for each item ofconnectionParameters
list.When request for new
D2Session
occurs, 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
D2Session
occurs, 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 ornull
for 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
-
getRedundantConnectionEventListener
public RedundantConnectionEventListener getRedundantConnectionEventListener()
Description copied from interface:RedundantConnectionManager
Get reference to the connection event listener.- Specified by:
getRedundantConnectionEventListener
in interfaceRedundantConnectionManager
- Returns:
- reference to the connection event listener
-
isClosed
public boolean isClosed()
Description copied from interface:D2SessionFactory
Gettrue
afterD2SessionFactory.close()
has been called. Indicates that no new session can be created and all created sessions has been terminated.- Specified by:
isClosed
in interfaceD2SessionFactory
- Returns:
true
when closed;
-
createSession
public java.util.concurrent.Future<D2Session> createSession(D2SessionParameters sessionParams, D2SessionEventsListener eventsListener)
Description copied from interface:D2SessionFactory
Create 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
ExecutionException
withcause
: ConnectSessionException
- when kernel refused connection of the sessionLoginFailedException
- when kernel refused to logon with provided user account
- Specified by:
createSession
in 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:D2SessionFactory
Create 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
ExecutionException
withcause
: ConnectSessionException
- when kernel refused connection of the sessionLoginFailedException
- when kernel refused to logon with provided user account
- Specified by:
createSession
in 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:D2SessionFactory
Close connection to D2000.- Specified by:
close
in interfaceD2SessionFactory
-
-