public class ClusterAwareReaderFailoverHandler extends java.lang.Object implements IReaderFailoverHandler
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 |
|---|---|
static class |
ClusterAwareReaderFailoverHandler.HostTuple
HostTuple class.
|
| Modifier and Type | Field and Description |
|---|---|
protected IConnectionProvider |
connProvider |
protected static int |
DEFAULT_FAILOVER_TIMEOUT |
protected static int |
DEFAULT_READER_CONNECT_TIMEOUT |
protected boolean |
enableFailoverStrictReader |
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 ITopologyService |
topologyService |
| Constructor and Description |
|---|
ClusterAwareReaderFailoverHandler(ITopologyService topologyService,
IConnectionProvider connProvider,
java.util.Map<java.lang.String,java.lang.String> initialConnectionProps,
int failoverTimeoutMs,
int timeoutMs,
boolean enableFailoverStrictReader,
Log log)
ClusterAwareReaderFailoverHandler constructor.
|
ClusterAwareReaderFailoverHandler(ITopologyService topologyService,
IConnectionProvider connProvider,
java.util.Map<java.lang.String,java.lang.String> initialConnectionProps,
Log log)
ClusterAwareReaderFailoverHandler constructor.
|
| 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) |
java.util.List<ClusterAwareReaderFailoverHandler.HostTuple> |
getHostTuplesByPriority(java.util.List<HostInfo> hosts,
java.util.Set<java.lang.String> downHosts) |
ReaderFailoverResult |
getReaderConnection(java.util.List<HostInfo> hostList)
Called to get any available reader connection.
|
java.util.List<ClusterAwareReaderFailoverHandler.HostTuple> |
getReaderTuplesByPriority(java.util.List<HostInfo> hostList,
java.util.Set<java.lang.String> downHosts) |
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 boolean enableFailoverStrictReader
protected final IConnectionProvider connProvider
protected final ITopologyService topologyService
public ClusterAwareReaderFailoverHandler(ITopologyService topologyService, IConnectionProvider connProvider, java.util.Map<java.lang.String,java.lang.String> initialConnectionProps, Log log)
topologyService - An implementation of ITopologyService that obtains and
caches a cluster's topology.connProvider - A provider for creating new connections.initialConnectionProps - The initial connection properties to copy over to the
new reader.public ClusterAwareReaderFailoverHandler(ITopologyService topologyService, IConnectionProvider connProvider, java.util.Map<java.lang.String,java.lang.String> initialConnectionProps, int failoverTimeoutMs, int timeoutMs, boolean enableFailoverStrictReader, Log log)
topologyService - An implementation of ITopologyService that obtains and
caches a cluster's topology.connProvider - A provider for creating new connections.initialConnectionProps - The initial connection properties to copy over to the
new reader.failoverTimeoutMs - Maximum allowed time in milliseconds to attempt reconnecting
to a new reader instance after a cluster failover is initiated.timeoutMs - Maximum allowed time for the entire reader failover process.log - An implementation of 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 IReaderFailoverHandlerhosts - 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 java.util.List<ClusterAwareReaderFailoverHandler.HostTuple> getHostTuplesByPriority(java.util.List<HostInfo> hosts, java.util.Set<java.lang.String> downHosts)
public ReaderFailoverResult getReaderConnection(java.util.List<HostInfo> hostList) throws java.sql.SQLException
getReaderConnection in interface IReaderFailoverHandlerhostList - Cluster current topologyReaderFailoverResult The results of this process.java.sql.SQLExceptionpublic java.util.List<ClusterAwareReaderFailoverHandler.HostTuple> getReaderTuplesByPriority(java.util.List<HostInfo> hostList, java.util.Set<java.lang.String> downHosts)