Class StandardConnectionHandlingPolicy
- java.lang.Object
-
- org.apache.curator.connection.StandardConnectionHandlingPolicy
-
- All Implemented Interfaces:
ConnectionHandlingPolicy
public class StandardConnectionHandlingPolicy extends java.lang.Object implements ConnectionHandlingPolicy
Curator's standard connection handling since 3.0.0- Since:
- 3.0.0
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.curator.connection.ConnectionHandlingPolicy
ConnectionHandlingPolicy.CheckTimeoutsResult
-
-
Constructor Summary
Constructors Constructor Description StandardConnectionHandlingPolicy()
StandardConnectionHandlingPolicy(int expirationPercent)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
callWithRetry(CuratorZookeeperClient client, java.util.concurrent.Callable<T> proc)
Called byRetryLoop.callWithRetry(CuratorZookeeperClient, Callable)
to do the work of retryingConnectionHandlingPolicy.CheckTimeoutsResult
checkTimeouts(java.util.concurrent.Callable<java.lang.String> hasNewConnectionString, long connectionStartMs, int sessionTimeoutMs, int connectionTimeoutMs)
Check timeouts.int
getSimulatedSessionExpirationPercent()
Prior to 3.0.0, Curator did not try to manage session expiration other than the functionality provided by ZooKeeper itself.
-
-
-
Method Detail
-
getSimulatedSessionExpirationPercent
public int getSimulatedSessionExpirationPercent()
Description copied from interface:ConnectionHandlingPolicy
Prior to 3.0.0, Curator did not try to manage session expiration other than the functionality provided by ZooKeeper itself. Starting with 3.0.0, Curator has the option of attempting to monitor session expiration above what is provided by ZooKeeper. The percentage returned by this method determines how and if Curator will check for session expiration.
If this method returns 0, Curator does not do any additional checking for session expiration.
If a positive number is returned, Curator will check for session expiration as follows: when ZooKeeper sends a Disconnect event, Curator will start a timer. If re-connection is not achieved before the elapsed time exceeds the negotiated session time multiplied by the session expiration percent, Curator will simulate a session expiration. Due to timing/network issues, it is not possible for a client to match the server's session timeout with complete accuracy. Thus, the need for a session expiration percentage.
- Specified by:
getSimulatedSessionExpirationPercent
in interfaceConnectionHandlingPolicy
- Returns:
- a percentage from 0 to 100 (0 implied no extra session checking)
-
callWithRetry
public <T> T callWithRetry(CuratorZookeeperClient client, java.util.concurrent.Callable<T> proc) throws java.lang.Exception
Description copied from interface:ConnectionHandlingPolicy
Called byRetryLoop.callWithRetry(CuratorZookeeperClient, Callable)
to do the work of retrying- Specified by:
callWithRetry
in interfaceConnectionHandlingPolicy
- Parameters:
client
- clientproc
- the procedure to retry- Returns:
- result
- Throws:
java.lang.Exception
- errors
-
checkTimeouts
public ConnectionHandlingPolicy.CheckTimeoutsResult checkTimeouts(java.util.concurrent.Callable<java.lang.String> hasNewConnectionString, long connectionStartMs, int sessionTimeoutMs, int connectionTimeoutMs) throws java.lang.Exception
Description copied from interface:ConnectionHandlingPolicy
Check timeouts. NOTE: this method is only called when an attempt to access to the ZooKeeper instances is made and the connection has not completed.- Specified by:
checkTimeouts
in interfaceConnectionHandlingPolicy
- Parameters:
hasNewConnectionString
- proc to call to check if there is a new connection string. Important: the internal state is cleared after this is called so you MUST handle the new connection string if non null is returnedconnectionStartMs
- the epoch/ms time that the connection was first initiatedsessionTimeoutMs
- the configured/negotiated session timeout in millisecondsconnectionTimeoutMs
- the configured connection timeout in milliseconds- Returns:
- result
- Throws:
java.lang.Exception
- errors
-
-