public class ClusterAwareReaderFailoverHandler extends java.lang.Object implements ReaderFailoverHandler
Reader Failover Process goal is to connect to any available reader. In order to connect faster, this implementation tries to connect to two readers at the same time. The first successfully connected reader is returned as the process result. If both readers are unavailable (i.e. could not be connected to), the process picks up another pair of readers and repeat. If no reader has been connected to, the process may consider a writer host, and other hosts marked down, to connect to.
| Modifier and Type | Class and Description |
|---|---|
protected static class |
ClusterAwareReaderFailoverHandler.HostTuple
HostTuple class.
|
| Modifier and Type | Field and Description |
|---|---|
protected ConnectionProvider |
connProvider |
protected static int |
DEFAULT_FAILOVER_TIMEOUT |
protected Log |
log
The logger we're going to use.
|
protected static Log |
NULL_LOGGER
Null logger shared by all connections at startup.
|
protected int |
timeoutMs |
protected TopologyService |
topologyService |
| Constructor and Description |
|---|
ClusterAwareReaderFailoverHandler(TopologyService topologyService,
ConnectionProvider connProvider,
int timeoutMs,
Log log)
ClusterAwareReaderFailoverHandler constructor.
|
ClusterAwareReaderFailoverHandler(TopologyService topologyService,
ConnectionProvider connProvider,
Log log) |
| Modifier and Type | Method and Description |
|---|---|
ConnectionAttemptResult |
failover(java.util.List<HostInfo> hosts,
HostInfo currentHost)
Called to start Reader Failover Process.
|
ConnectionAttemptResult |
getReaderConnection(java.util.List<HostInfo> hostList)
Called to get any available reader connection.
|
protected void |
setTimeoutMs(int timeoutMs)
Set process timeout in millis.
|
protected static final int DEFAULT_FAILOVER_TIMEOUT
protected static final Log NULL_LOGGER
protected transient Log log
protected int timeoutMs
protected final ConnectionProvider connProvider
protected final TopologyService topologyService
public ClusterAwareReaderFailoverHandler(TopologyService topologyService, ConnectionProvider connProvider, Log log)
public ClusterAwareReaderFailoverHandler(TopologyService topologyService, ConnectionProvider connProvider, int timeoutMs, Log log)
protected void setTimeoutMs(int timeoutMs)
timeoutMs - Process timeout in millispublic ConnectionAttemptResult failover(java.util.List<HostInfo> hosts, HostInfo currentHost) throws java.sql.SQLException
failover in interface ReaderFailoverHandlerhosts - Cluster current topologycurrentHost - The currently connected host that has failed.ConnectionAttemptResult The results of this process. May return null, which is
considered an unsuccessful result.java.sql.SQLExceptionpublic ConnectionAttemptResult getReaderConnection(java.util.List<HostInfo> hostList) throws java.sql.SQLException
getReaderConnection in interface ReaderFailoverHandlerhostList - Cluster current topologyConnectionAttemptResult The results of this process. May return null, which is
considered an unsuccessful result.java.sql.SQLException