public class RdsHostListProvider extends java.lang.Object implements DynamicHostListProvider
| Modifier and Type | Class and Description |
|---|---|
static class |
RdsHostListProvider.ClusterSuggestedResult |
protected static class |
RdsHostListProvider.FetchTopologyResult |
| Modifier and Type | Field and Description |
|---|---|
static AwsWrapperProperty |
CLUSTER_ID |
static AwsWrapperProperty |
CLUSTER_INSTANCE_HOST_PATTERN |
static AwsWrapperProperty |
CLUSTER_TOPOLOGY_REFRESH_RATE_MS |
protected java.lang.String |
clusterId |
protected HostSpec |
clusterInstanceTemplate |
protected static ConnectionUrlParser |
connectionUrlParser |
protected static int |
defaultTopologyQueryTimeoutMs |
protected java.util.List<HostSpec> |
hostList |
protected HostListProviderService |
hostListProviderService |
protected java.util.List<HostSpec> |
initialHostList |
protected HostSpec |
initialHostSpec |
protected boolean |
isInitialized |
protected boolean |
isPrimaryClusterId |
protected java.lang.String |
isReaderQuery |
protected java.util.concurrent.locks.ReentrantLock |
lock |
protected static java.util.concurrent.Executor |
networkTimeoutExecutor |
protected java.lang.String |
nodeIdQuery |
protected java.lang.String |
originalUrl |
protected static CacheMap<java.lang.String,java.lang.Boolean> |
primaryClusterIdCache |
protected java.util.Properties |
properties |
protected static RdsUtils |
rdsHelper |
protected RdsUrlType |
rdsUrlType |
protected long |
refreshRateNano |
protected FullServicesContainer |
servicesContainer |
protected static long |
suggestedClusterIdRefreshRateNano |
protected static CacheMap<java.lang.String,java.lang.String> |
suggestedPrimaryClusterIdCache |
protected java.lang.String |
topologyQuery |
| Constructor and Description |
|---|
RdsHostListProvider(java.util.Properties properties,
java.lang.String originalUrl,
FullServicesContainer servicesContainer,
java.lang.String topologyQuery,
java.lang.String nodeIdQuery,
java.lang.String isReaderQuery) |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clear topology cache for the current cluster.
|
static void |
clearAll()
Clear topology cache for all clusters.
|
protected void |
clusterIdChanged(java.lang.String oldClusterId) |
protected HostSpec |
createHost(java.sql.ResultSet resultSet)
Creates an instance of HostSpec which captures details about a connectable host.
|
protected HostSpec |
createHost(java.lang.String host,
boolean isWriter,
long weight,
java.sql.Timestamp lastUpdateTime) |
java.util.List<HostSpec> |
forceRefresh() |
java.util.List<HostSpec> |
forceRefresh(java.sql.Connection connection) |
java.lang.String |
getClusterId() |
protected java.lang.String |
getHostEndpoint(java.lang.String nodeName)
Build a host dns endpoint based on host/node name.
|
HostRole |
getHostRole(java.sql.Connection conn)
Evaluates the host role of the given connection - either a writer or a reader.
|
RdsUrlType |
getRdsUrlType() |
@Nullable java.util.List<HostSpec> |
getStoredTopology()
Get cached topology.
|
protected RdsHostListProvider.ClusterSuggestedResult |
getSuggestedClusterId(java.lang.String url) |
protected RdsHostListProvider.FetchTopologyResult |
getTopology(java.sql.Connection conn,
boolean forceUpdate)
Get cluster topology.
|
HostSpec |
identifyConnection(java.sql.Connection connection) |
protected void |
init() |
protected java.util.List<HostSpec> |
queryForTopology(java.sql.Connection conn)
Obtain a cluster topology from database.
|
java.util.List<HostSpec> |
refresh() |
java.util.List<HostSpec> |
refresh(java.sql.Connection connection) |
protected void |
suggestPrimaryCluster(@NonNull java.util.List<HostSpec> primaryClusterHosts) |
public static final AwsWrapperProperty CLUSTER_TOPOLOGY_REFRESH_RATE_MS
public static final AwsWrapperProperty CLUSTER_ID
public static final AwsWrapperProperty CLUSTER_INSTANCE_HOST_PATTERN
protected static final java.util.concurrent.Executor networkTimeoutExecutor
protected static final RdsUtils rdsHelper
protected static final ConnectionUrlParser connectionUrlParser
protected static final int defaultTopologyQueryTimeoutMs
protected static final long suggestedClusterIdRefreshRateNano
protected static final CacheMap<java.lang.String,java.lang.String> suggestedPrimaryClusterIdCache
protected static final CacheMap<java.lang.String,java.lang.Boolean> primaryClusterIdCache
protected final FullServicesContainer servicesContainer
protected final HostListProviderService hostListProviderService
protected final java.lang.String originalUrl
protected final java.lang.String topologyQuery
protected final java.lang.String nodeIdQuery
protected final java.lang.String isReaderQuery
protected RdsUrlType rdsUrlType
protected long refreshRateNano
protected java.util.List<HostSpec> hostList
protected java.util.List<HostSpec> initialHostList
protected HostSpec initialHostSpec
protected final java.util.concurrent.locks.ReentrantLock lock
protected java.lang.String clusterId
protected HostSpec clusterInstanceTemplate
protected boolean isPrimaryClusterId
protected volatile boolean isInitialized
protected java.util.Properties properties
public RdsHostListProvider(java.util.Properties properties,
java.lang.String originalUrl,
FullServicesContainer servicesContainer,
java.lang.String topologyQuery,
java.lang.String nodeIdQuery,
java.lang.String isReaderQuery)
protected void init()
throws java.sql.SQLException
java.sql.SQLExceptionprotected RdsHostListProvider.FetchTopologyResult getTopology(java.sql.Connection conn, boolean forceUpdate) throws java.sql.SQLException
refreshRateNano).conn - A connection to database to fetch the latest topology, if needed.forceUpdate - If true, it forces a service to ignore cached copy of topology and to fetch
a fresh one.java.sql.SQLException - if errors occurred while retrieving the topology.protected void clusterIdChanged(java.lang.String oldClusterId)
throws java.sql.SQLException
java.sql.SQLExceptionprotected RdsHostListProvider.ClusterSuggestedResult getSuggestedClusterId(java.lang.String url)
protected void suggestPrimaryCluster(@NonNull java.util.List<HostSpec> primaryClusterHosts)
protected java.util.List<HostSpec> queryForTopology(java.sql.Connection conn) throws java.sql.SQLException
conn - A connection to database to fetch the latest topology.HostSpec objects representing the topologyjava.sql.SQLException - if errors occurred while retrieving the topology.protected HostSpec createHost(java.sql.ResultSet resultSet) throws java.sql.SQLException
resultSet - the result set from querying the topologyHostSpec instance for a specific instance from the clusterjava.sql.SQLException - If unable to retrieve the hostName from the result setprotected HostSpec createHost(java.lang.String host, boolean isWriter, long weight, java.sql.Timestamp lastUpdateTime)
protected java.lang.String getHostEndpoint(java.lang.String nodeName)
nodeName - A host name.public @Nullable java.util.List<HostSpec> getStoredTopology()
public static void clearAll()
public void clear()
public java.util.List<HostSpec> refresh() throws java.sql.SQLException
refresh in interface HostListProviderjava.sql.SQLExceptionpublic java.util.List<HostSpec> refresh(java.sql.Connection connection) throws java.sql.SQLException
refresh in interface HostListProviderjava.sql.SQLExceptionpublic java.util.List<HostSpec> forceRefresh() throws java.sql.SQLException
forceRefresh in interface HostListProviderjava.sql.SQLExceptionpublic java.util.List<HostSpec> forceRefresh(java.sql.Connection connection) throws java.sql.SQLException
forceRefresh in interface HostListProviderjava.sql.SQLExceptionpublic RdsUrlType getRdsUrlType() throws java.sql.SQLException
java.sql.SQLExceptionpublic HostRole getHostRole(java.sql.Connection conn) throws java.sql.SQLException
HostListProvidergetHostRole in interface HostListProviderconn - a connection to the database instance whose role should be determinedjava.sql.SQLException - if there is a problem executing or processing the SQL query used to
determine the host rolepublic HostSpec identifyConnection(java.sql.Connection connection) throws java.sql.SQLException
identifyConnection in interface HostListProviderjava.sql.SQLExceptionpublic java.lang.String getClusterId()
throws java.lang.UnsupportedOperationException,
java.sql.SQLException
getClusterId in interface HostListProviderjava.lang.UnsupportedOperationExceptionjava.sql.SQLException