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 authorize it with valid D2000 user account.java.util.concurrent.Future<CreateSessionResponse>
createSessionWithSpnego(D2SessionParameters sessionParams, D2SessionEventsListener eventsListener, java.util.Set<SharedResourceType> interestSet)
Create new session object, connect it to D2000 and authorize it with valid D2000 user account.java.util.List<D2Connector>
getConnectorsSnapshot()
Get snapshot of list of current connectors.RedundantConnectionEventListener
getRedundantConnectionEventListener()
Get reference to the connection event listener.boolean
isClosed()
Gettrue
afterD2SessionFactory.close()
has been called.void
setAutonomousWatchdog(boolean value)
Set autonomousWatchdog statevalue
to all managed connectors.-
Methods inherited from interface sk.ipesoft.d2000.d2japi.D2SessionFactory
createSessionWithSpnego
-
-
-
-
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
-
getConnectorsSnapshot
public java.util.List<D2Connector> getConnectorsSnapshot()
Description copied from interface:RedundantConnectionManager
Get snapshot of list of current connectors.- Specified by:
getConnectorsSnapshot
in interfaceRedundantConnectionManager
- Returns:
-
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;
-
setAutonomousWatchdog
public void setAutonomousWatchdog(boolean value)
Description copied from interface:RedundantConnectionManager
Set autonomousWatchdog statevalue
to all managed connectors.- Specified by:
setAutonomousWatchdog
in interfaceRedundantConnectionManager
- Parameters:
value
-true
to activate orfalse
do deactivate
-
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. Get the session asynchronously via returnedFuture
object.Note: Do not use in combination with SPNEGO authentication mechanism if you intend to obtain result from returned future.
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 authorize it with valid D2000 user account. Get the session asynchronously via returnedFuture
object.Note: Do not use in combination with SPNEGO authentication mechanism if you intend to obtain result from returned future.
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
-
createSessionWithSpnego
public java.util.concurrent.Future<CreateSessionResponse> createSessionWithSpnego(D2SessionParameters sessionParams, D2SessionEventsListener eventsListener, java.util.Set<SharedResourceType> interestSet)
Description copied from interface:D2SessionFactory
Create new session object, connect it to D2000 and authorize it with valid D2000 user account.Note: You should prefer
D2SessionFactory.createSession(sk.ipesoft.d2000.d2japi.D2SessionParameters, sk.ipesoft.d2000.d2japi.D2SessionEventsListener, java.util.Set)
when you don't use SPNEGO or when you obtain new session througheventsListener
.Note 2: Keep implementation of
SpnegoHandler.handleTokenFromServer(byte[], sk.ipesoft.d2000.d2japi.SpnegoHandler.ResponseHandler)
blank, because you will obtain SPNEGO response via returned future.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:
createSessionWithSpnego
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
-
-