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 |
static ReaderFailoverResult |
FAILED_READER_FAILOVER_RESULT |
protected java.util.Properties |
initialConnectionProps |
protected boolean |
isStrictReaderRequired |
protected int |
maxFailoverTimeoutMs |
protected PluginService |
pluginService |
protected int |
timeoutMs |
| Constructor and Description |
|---|
ClusterAwareReaderFailoverHandler(PluginService pluginService,
java.util.Properties initialConnectionProps)
ClusterAwareReaderFailoverHandler constructor.
|
ClusterAwareReaderFailoverHandler(PluginService pluginService,
java.util.Properties initialConnectionProps,
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.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 void |
setTimeoutMs(int timeoutMs)
Set process timeout in millis.
|
protected static final int DEFAULT_FAILOVER_TIMEOUT
protected static final int DEFAULT_READER_CONNECT_TIMEOUT
public static final ReaderFailoverResult FAILED_READER_FAILOVER_RESULT
protected java.util.Properties initialConnectionProps
protected int maxFailoverTimeoutMs
protected int timeoutMs
protected boolean isStrictReaderRequired
protected final PluginService pluginService
public ClusterAwareReaderFailoverHandler(PluginService pluginService, java.util.Properties initialConnectionProps)
pluginService - A provider for creating new connections.initialConnectionProps - The initial connection properties to copy over to the new reader.public ClusterAwareReaderFailoverHandler(PluginService pluginService, java.util.Properties initialConnectionProps, int maxFailoverTimeoutMs, int timeoutMs, boolean isStrictReaderRequired)
pluginService - A provider for creating new connections.initialConnectionProps - 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 connectprotected void setTimeoutMs(int timeoutMs)
timeoutMs - Process timeout in millispublic ReaderFailoverResult failover(java.util.List<HostSpec> hosts, HostSpec 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.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.