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 static int |
DEFAULT_READER_CONNECT_TIMEOUT |
protected java.util.Map<java.lang.String,java.lang.String> |
initialConnectionProps |
protected Log |
log
The logger we're going to use.
|
protected int |
maxFailoverTimeoutMs |
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,
java.util.Map<java.lang.String,java.lang.String> initialConnectionProps,
int failoverTimeoutMs,
int timeoutMs,
Log log)
ClusterAwareReaderFailoverHandler constructor.
|
ClusterAwareReaderFailoverHandler(TopologyService topologyService,
ConnectionProvider connProvider,
java.util.Map<java.lang.String,java.lang.String> initialConnectionProps,
Log log) |
| Modifier and Type | Method and Description |
|---|---|
ReaderFailoverResult |
failover(java.util.List<HostInfo> hosts,
HostInfo currentHost)
Called to start Reader Failover Process.
|
protected ReaderFailoverResult |
failoverInternal(java.util.List<HostInfo> hosts,
HostInfo currentHost) |
ReaderFailoverResult |
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 int DEFAULT_READER_CONNECT_TIMEOUT
protected static final Log NULL_LOGGER
protected transient Log log
protected java.util.Map<java.lang.String,java.lang.String> initialConnectionProps
protected int maxFailoverTimeoutMs
protected int timeoutMs
protected final ConnectionProvider connProvider
protected final TopologyService topologyService
public ClusterAwareReaderFailoverHandler(TopologyService topologyService, ConnectionProvider connProvider, java.util.Map<java.lang.String,java.lang.String> initialConnectionProps, Log log)
public ClusterAwareReaderFailoverHandler(TopologyService topologyService, ConnectionProvider connProvider, java.util.Map<java.lang.String,java.lang.String> initialConnectionProps, int failoverTimeoutMs, int timeoutMs, Log log)
protected void setTimeoutMs(int timeoutMs)
timeoutMs - Process timeout in millispublic ReaderFailoverResult 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.ReaderFailoverResult The results of this process.java.sql.SQLExceptionprotected ReaderFailoverResult failoverInternal(java.util.List<HostInfo> hosts, HostInfo currentHost) throws java.sql.SQLException
java.sql.SQLExceptionpublic ReaderFailoverResult getReaderConnection(java.util.List<HostInfo> hostList) throws java.sql.SQLException
getReaderConnection in interface ReaderFailoverHandlerhostList - Cluster current topologyReaderFailoverResult The results of this process.java.sql.SQLException