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 | Field and Description |
|---|---|
protected static int |
DEFAULT_FAILOVER_TIMEOUT |
protected static int |
DEFAULT_READER_CONNECT_TIMEOUT |
protected static ReaderFailoverResult |
FAILED_READER_FAILOVER_RESULT |
protected java.util.Map<java.lang.String,HostAvailability> |
hostAvailabilityMap |
protected boolean |
isStrictReaderRequired |
protected int |
maxFailoverTimeoutMs |
protected PluginService |
pluginService |
protected java.util.Properties |
props |
protected FullServicesContainer |
servicesContainer |
protected int |
timeoutMs |
| Constructor and Description |
|---|
ClusterAwareReaderFailoverHandler(FullServicesContainer servicesContainer,
java.util.Properties props)
ClusterAwareReaderFailoverHandler constructor.
|
ClusterAwareReaderFailoverHandler(FullServicesContainer servicesContainer,
java.util.Properties props,
int maxFailoverTimeoutMs,
int timeoutMs,
boolean isStrictReaderRequired)
ClusterAwareReaderFailoverHandler constructor.
|
| Modifier and Type | Method and Description |
|---|---|
ReaderFailoverResult |
failover(java.util.List<HostSpec> hosts,
HostSpec currentHost)
Called to start Reader Failover Process.
|
protected ReaderFailoverResult |
failoverInternal(java.util.List<HostSpec> hosts,
HostSpec currentHost) |
java.util.Map<java.lang.String,HostAvailability> |
getHostAvailabilityMap()
Get the host availability map for the failover handler.
|
java.util.List<HostSpec> |
getHostsByPriority(java.util.List<HostSpec> hosts) |
ReaderFailoverResult |
getReaderConnection(java.util.List<HostSpec> hostList)
Called to get any available reader connection.
|
java.util.List<HostSpec> |
getReaderHostsByPriority(java.util.List<HostSpec> hosts) |
protected FullServicesContainer |
newServicesContainer() |
protected void |
setTimeoutMs(int timeoutMs)
Set process timeout in millis.
|
protected static final ReaderFailoverResult FAILED_READER_FAILOVER_RESULT
protected static final int DEFAULT_FAILOVER_TIMEOUT
protected static final int DEFAULT_READER_CONNECT_TIMEOUT
protected final java.util.Map<java.lang.String,HostAvailability> hostAvailabilityMap
protected final FullServicesContainer servicesContainer
protected final PluginService pluginService
protected java.util.Properties props
protected int maxFailoverTimeoutMs
protected int timeoutMs
protected boolean isStrictReaderRequired
public ClusterAwareReaderFailoverHandler(FullServicesContainer servicesContainer, java.util.Properties props)
servicesContainer - the service container for the services required by this class.props - the initial connection properties to copy over to the new reader.public ClusterAwareReaderFailoverHandler(FullServicesContainer servicesContainer, java.util.Properties props, int maxFailoverTimeoutMs, int timeoutMs, boolean isStrictReaderRequired)
servicesContainer - the service container for the services required by this class.props - the initial connection properties to copy over to the new reader.maxFailoverTimeoutMs - maximum allowed time for the entire reader failover process.timeoutMs - maximum allowed time in milliseconds for each reader connection attempt during
the reader failover process.isStrictReaderRequired - when true, it disables adding a writer to a list of nodes to connectpublic java.util.Map<java.lang.String,HostAvailability> getHostAvailabilityMap()
ReaderFailoverHandlergetHostAvailabilityMap in interface ReaderFailoverHandlerprotected void setTimeoutMs(int timeoutMs)
timeoutMs - Process timeout in millispublic ReaderFailoverResult failover(java.util.List<HostSpec> hosts, HostSpec currentHost) throws java.sql.SQLException
ReaderFailoverHandlerfailover in interface ReaderFailoverHandlerhosts - Cluster current topology.currentHost - The currently connected host that has failed.ReaderFailoverResult The results of this process.java.sql.SQLException - indicating whether the failover attempt was successful.protected ReaderFailoverResult failoverInternal(java.util.List<HostSpec> hosts, HostSpec currentHost) throws java.sql.SQLException
java.sql.SQLExceptionpublic java.util.List<HostSpec> getHostsByPriority(java.util.List<HostSpec> hosts)
public ReaderFailoverResult getReaderConnection(java.util.List<HostSpec> hostList) throws java.sql.SQLException
getReaderConnection in interface ReaderFailoverHandlerhostList - Cluster current topologyReaderFailoverResult The results of this process.java.sql.SQLException - if any error occurred while attempting a reader connection.public java.util.List<HostSpec> getReaderHostsByPriority(java.util.List<HostSpec> hosts)
protected FullServicesContainer newServicesContainer() throws java.sql.SQLException
java.sql.SQLException