public class PluginServiceImpl extends java.lang.Object implements PluginService, CanReleaseResources, HostListProviderService, PluginManagerService
| Constructor and Description |
|---|
PluginServiceImpl(@NonNull FullServicesContainer servicesContainer,
@NonNull ExceptionManager exceptionManager,
@NonNull java.util.Properties props,
@NonNull java.lang.String originalUrl,
@NonNull java.lang.String targetDriverProtocol,
@Nullable DialectProvider dialectProvider,
@NonNull TargetDriverDialect targetDriverDialect,
@Nullable ConfigurationProfile configurationProfile,
@Nullable SessionStateService sessionStateService) |
PluginServiceImpl(@NonNull FullServicesContainer servicesContainer,
@NonNull java.util.Properties props,
@NonNull java.lang.String originalUrl,
@NonNull java.lang.String targetDriverProtocol,
@NonNull TargetDriverDialect targetDriverDialect) |
PluginServiceImpl(@NonNull FullServicesContainer servicesContainer,
@NonNull java.util.Properties props,
@NonNull java.lang.String originalUrl,
@NonNull java.lang.String targetDriverProtocol,
@NonNull TargetDriverDialect targetDriverDialect,
@Nullable ConfigurationProfile configurationProfile) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
acceptsStrategy(HostRole role,
java.lang.String strategy)
Returns a boolean indicating if the available
ConnectionProvider or
ConnectionPlugin instances support the selection of a host with the requested role and
strategy via PluginService.getHostSpecByStrategy(software.amazon.jdbc.HostRole, java.lang.String). |
static void |
clearCache() |
protected java.util.EnumSet<NodeChangeOptions> |
compare(@NonNull java.sql.Connection connA,
@NonNull HostSpec hostSpecA,
@NonNull java.sql.Connection connB,
@NonNull HostSpec hostSpecB) |
protected java.util.EnumSet<NodeChangeOptions> |
compare(@NonNull HostSpec hostSpecA,
@NonNull HostSpec hostSpecB) |
java.sql.Connection |
connect(HostSpec hostSpec,
java.util.Properties props)
Establishes a connection to the given host using the given properties.
|
java.sql.Connection |
connect(HostSpec hostSpec,
java.util.Properties props,
@Nullable ConnectionPlugin pluginToSkip) |
void |
fillAliases(java.sql.Connection connection,
HostSpec hostSpec) |
java.sql.Connection |
forceConnect(HostSpec hostSpec,
java.util.Properties props)
Establishes a connection to the given host using the given properties.
|
java.sql.Connection |
forceConnect(HostSpec hostSpec,
java.util.Properties props,
@Nullable ConnectionPlugin pluginToSkip) |
void |
forceRefreshHostList() |
boolean |
forceRefreshHostList(boolean shouldVerifyWriter,
long timeoutMs)
Initiates a topology update.
|
void |
forceRefreshHostList(java.sql.Connection connection) |
java.util.List<HostSpec> |
getAllHosts()
Get host information for all hosts in the cluster.
|
ConnectionProvider |
getConnectionProvider()
Deprecated.
|
java.sql.Connection |
getCurrentConnection() |
HostSpec |
getCurrentHostSpec() |
Dialect |
getDialect() |
java.lang.String |
getDriverProtocol() |
HostListProvider |
getHostListProvider() |
HostRole |
getHostRole(java.sql.Connection conn)
Evaluates the host role of the given connection - either a writer or a reader.
|
java.util.List<HostSpec> |
getHosts()
Get host information for allowed hosts in the cluster.
|
HostSpecBuilder |
getHostSpecBuilder() |
HostSpec |
getHostSpecByStrategy(HostRole role,
java.lang.String strategy)
Selects a
HostSpec with the requested role from available hosts using the requested
strategy. |
HostSpec |
getHostSpecByStrategy(java.util.List<HostSpec> hosts,
HostRole role,
java.lang.String strategy)
Selects a
HostSpec with the requested role from available hosts using the requested
strategy. |
HostSpec |
getInitialConnectionHostSpec() |
java.lang.String |
getOriginalUrl() |
<T> T |
getPlugin(java.lang.Class<T> pluginClazz) |
java.util.Properties |
getProperties() |
@NonNull SessionStateService |
getSessionStateService() |
<T> T |
getStatus(@NonNull java.lang.Class<T> clazz,
boolean clusterBound)
Deprecated.
|
<T> T |
getStatus(@NonNull java.lang.Class<T> clazz,
java.lang.String key)
Deprecated.
|
protected <T> java.lang.String |
getStatusCacheKey(java.lang.Class<T> clazz,
java.lang.String key) |
TargetDriverDialect |
getTargetDriverDialect() |
java.lang.String |
getTargetName() |
TelemetryFactory |
getTelemetryFactory() |
HostSpec |
identifyConnection(java.sql.Connection connection) |
boolean |
isInTransaction() |
boolean |
isLoginException(java.lang.String sqlState) |
boolean |
isLoginException(java.lang.Throwable throwable)
Deprecated.
|
boolean |
isLoginException(java.lang.Throwable throwable,
@Nullable TargetDriverDialect targetDriverDialect) |
boolean |
isNetworkException(java.lang.String sqlState) |
boolean |
isNetworkException(java.lang.Throwable throwable)
Deprecated.
|
boolean |
isNetworkException(java.lang.Throwable throwable,
@Nullable TargetDriverDialect targetDriverDialect) |
boolean |
isPluginInUse(java.lang.Class<? extends ConnectionPlugin> pluginClazz) |
boolean |
isPooledConnectionProvider(HostSpec host,
java.util.Properties props) |
boolean |
isStaticHostListProvider() |
void |
refreshHostList() |
void |
refreshHostList(java.sql.Connection connection) |
void |
releaseResources()
An object that implements this interface should release all acquired resources assuming it may
be disposed at any time.
|
void |
setAllowedAndBlockedHosts(AllowedAndBlockedHosts allowedAndBlockedHosts)
Deprecated.
|
void |
setAvailability(@NonNull java.util.Set<java.lang.String> hostAliases,
@NonNull HostAvailability availability) |
void |
setCurrentConnection(@NonNull java.sql.Connection connection,
@NonNull HostSpec hostSpec) |
java.util.EnumSet<NodeChangeOptions> |
setCurrentConnection(@NonNull java.sql.Connection connection,
@NonNull HostSpec hostSpec,
@Nullable ConnectionPlugin skipNotificationForThisPlugin)
Set a new internal connection.
|
void |
setHostListProvider(HostListProvider hostListProvider) |
void |
setInitialConnectionHostSpec(@NonNull HostSpec initialConnectionHostSpec) |
void |
setInTransaction(boolean inTransaction) |
<T> void |
setStatus(java.lang.Class<T> clazz,
T status,
boolean clusterBound)
Deprecated.
|
<T> void |
setStatus(java.lang.Class<T> clazz,
T status,
java.lang.String key)
Deprecated.
|
void |
updateDialect(@NonNull java.sql.Connection connection) |
protected static final long DEFAULT_HOST_AVAILABILITY_CACHE_EXPIRE_NANO
protected static final CacheMap<java.lang.String,HostAvailability> hostAvailabilityExpiringCache
protected final FullServicesContainer servicesContainer
protected static final CacheMap<java.lang.String,java.lang.Object> statusesExpiringCache
protected static final long DEFAULT_STATUS_CACHE_EXPIRE_NANO
protected final ConnectionPluginManager pluginManager
protected volatile HostListProvider hostListProvider
protected java.util.List<HostSpec> allHosts
protected java.sql.Connection currentConnection
protected HostSpec currentHostSpec
protected HostSpec initialConnectionHostSpec
protected final @Nullable ExceptionHandler exceptionHandler
protected final DialectProvider dialectProvider
protected Dialect dialect
protected TargetDriverDialect targetDriverDialect
protected final @Nullable ConfigurationProfile configurationProfile
protected final ConnectionProviderManager connectionProviderManager
protected final SessionStateService sessionStateService
protected final java.util.concurrent.locks.ReentrantLock connectionSwitchLock
public PluginServiceImpl(@NonNull FullServicesContainer servicesContainer, @NonNull java.util.Properties props, @NonNull java.lang.String originalUrl, @NonNull java.lang.String targetDriverProtocol, @NonNull TargetDriverDialect targetDriverDialect) throws java.sql.SQLException
java.sql.SQLExceptionpublic PluginServiceImpl(@NonNull FullServicesContainer servicesContainer, @NonNull java.util.Properties props, @NonNull java.lang.String originalUrl, @NonNull java.lang.String targetDriverProtocol, @NonNull TargetDriverDialect targetDriverDialect, @Nullable ConfigurationProfile configurationProfile) throws java.sql.SQLException
java.sql.SQLExceptionpublic PluginServiceImpl(@NonNull FullServicesContainer servicesContainer, @NonNull ExceptionManager exceptionManager, @NonNull java.util.Properties props, @NonNull java.lang.String originalUrl, @NonNull java.lang.String targetDriverProtocol, @Nullable DialectProvider dialectProvider, @NonNull TargetDriverDialect targetDriverDialect, @Nullable ConfigurationProfile configurationProfile, @Nullable SessionStateService sessionStateService) throws java.sql.SQLException
java.sql.SQLExceptionpublic java.sql.Connection getCurrentConnection()
getCurrentConnection in interface HostListProviderServicegetCurrentConnection in interface PluginServicepublic HostSpec getCurrentHostSpec()
getCurrentHostSpec in interface HostListProviderServicegetCurrentHostSpec in interface PluginServicepublic void setInitialConnectionHostSpec(@NonNull HostSpec initialConnectionHostSpec)
setInitialConnectionHostSpec in interface HostListProviderServicepublic HostSpec getInitialConnectionHostSpec()
getInitialConnectionHostSpec in interface HostListProviderServicegetInitialConnectionHostSpec in interface PluginServicepublic java.lang.String getOriginalUrl()
getOriginalUrl in interface PluginService@Deprecated public void setAllowedAndBlockedHosts(AllowedAndBlockedHosts allowedAndBlockedHosts)
PluginServicesetAllowedAndBlockedHosts in interface PluginServiceallowedAndBlockedHosts - An object defining the allowed and blocked sets of hosts.public boolean acceptsStrategy(HostRole role, java.lang.String strategy) throws java.sql.SQLException
PluginServiceConnectionProvider or
ConnectionPlugin instances support the selection of a host with the requested role and
strategy via PluginService.getHostSpecByStrategy(software.amazon.jdbc.HostRole, java.lang.String).acceptsStrategy in interface PluginServicerole - the desired host rolestrategy - the strategy that should be used to pick a host (eg "random")ConnectionProvider or ConnectionPlugin instances
support the selection of a host with the requested role and strategy via
PluginService.getHostSpecByStrategy(software.amazon.jdbc.HostRole, java.lang.String). Otherwise, return false.java.sql.SQLException - if there's an error processing this method.public HostSpec getHostSpecByStrategy(HostRole role, java.lang.String strategy) throws java.sql.SQLException
PluginServiceHostSpec with the requested role from available hosts using the requested
strategy. PluginService.acceptsStrategy(software.amazon.jdbc.HostRole, java.lang.String) should be called first to evaluate if the available
ConnectionProvider or ConnectionPlugin instances support the selection of a
host with the requested role and strategy.getHostSpecByStrategy in interface PluginServicerole - the desired role of the host - either a writer or a readerstrategy - the strategy that should be used to select a HostSpec from the
available hosts (eg "random")HostSpec with the requested rolejava.sql.SQLException - if the available ConnectionProvider or
ConnectionPlugin instances do not cannot find a
host matching the requested role or an error occurs while
selecting a hostpublic HostSpec getHostSpecByStrategy(java.util.List<HostSpec> hosts, HostRole role, java.lang.String strategy) throws java.sql.SQLException
PluginServiceHostSpec with the requested role from available hosts using the requested
strategy. PluginService.acceptsStrategy(software.amazon.jdbc.HostRole, java.lang.String) should be called first to evaluate if the available
ConnectionProvider or ConnectionPlugin instances support the selection of a
host with the requested role and strategy.getHostSpecByStrategy in interface PluginServicehosts - the list of HostSpec from which a HostSpec will be selected fromrole - the desired role of the host - either a writer or a readerstrategy - the strategy that should be used to select a HostSpec from the
available hosts (eg "random")HostSpec with the requested rolejava.sql.SQLException - if the available ConnectionProvider or
ConnectionPlugin instances do not cannot find a
host matching the requested role or an error occurs while
selecting a hostpublic HostRole getHostRole(java.sql.Connection conn) throws java.sql.SQLException
PluginServicegetHostRole in interface PluginServiceconn - 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 role@Deprecated public ConnectionProvider getConnectionProvider()
getConnectionProvider in interface PluginServicepublic boolean isPooledConnectionProvider(HostSpec host, java.util.Properties props)
isPooledConnectionProvider in interface PluginServicepublic java.lang.String getDriverProtocol()
getDriverProtocol in interface PluginServicepublic void setCurrentConnection(@NonNull java.sql.Connection connection,
@NonNull HostSpec hostSpec)
throws java.sql.SQLException
setCurrentConnection in interface PluginServicejava.sql.SQLExceptionpublic java.util.EnumSet<NodeChangeOptions> setCurrentConnection(@NonNull java.sql.Connection connection, @NonNull HostSpec hostSpec, @Nullable ConnectionPlugin skipNotificationForThisPlugin) throws java.sql.SQLException
PluginServiceConnectionPlugin.notifyConnectionChanged(EnumSet) for more details. A plugin mentioned
in parameter skipNotificationForThisPlugin won't be receiving such notification.setCurrentConnection in interface PluginServiceconnection - the new internal connection.hostSpec - the host details for a new internal connection.skipNotificationForThisPlugin - A reference to a plugin that doesn't need to receive notification
about connection change. Usually, a plugin that initiates connection change
doesn't need to receive such notification and uses a pointer to
itself as a call parameter.java.sql.SQLException - if there's an error setting a current connection.protected java.util.EnumSet<NodeChangeOptions> compare(@NonNull java.sql.Connection connA, @NonNull HostSpec hostSpecA, @NonNull java.sql.Connection connB, @NonNull HostSpec hostSpecB)
protected java.util.EnumSet<NodeChangeOptions> compare(@NonNull HostSpec hostSpecA, @NonNull HostSpec hostSpecB)
public java.util.List<HostSpec> getAllHosts()
PluginServicegetAllHosts in interface PluginServicepublic java.util.List<HostSpec> getHosts()
PluginServicegetHosts in interface PluginServicepublic void setAvailability(@NonNull java.util.Set<java.lang.String> hostAliases,
@NonNull HostAvailability availability)
setAvailability in interface PluginServicepublic boolean isInTransaction()
isInTransaction in interface PluginServicepublic void setInTransaction(boolean inTransaction)
setInTransaction in interface PluginManagerServicepublic HostListProvider getHostListProvider()
getHostListProvider in interface HostListProviderServicegetHostListProvider in interface PluginServicepublic void refreshHostList()
throws java.sql.SQLException
refreshHostList in interface PluginServicejava.sql.SQLExceptionpublic void refreshHostList(java.sql.Connection connection)
throws java.sql.SQLException
refreshHostList in interface PluginServicejava.sql.SQLExceptionpublic void forceRefreshHostList()
throws java.sql.SQLException
forceRefreshHostList in interface PluginServicejava.sql.SQLExceptionpublic void forceRefreshHostList(java.sql.Connection connection)
throws java.sql.SQLException
forceRefreshHostList in interface PluginServicejava.sql.SQLExceptionpublic boolean forceRefreshHostList(boolean shouldVerifyWriter,
long timeoutMs)
throws java.sql.SQLException
PluginServiceforceRefreshHostList in interface PluginServiceshouldVerifyWriter - true, if a caller expects to get topology with the latest confirmed writertimeoutMs - timeout in msec to wait until topology gets refreshed and a new (or existing) writer is
confirmed (if shouldVerifyWriter has a value of true).java.sql.SQLException - if there was an error establishing a connection or fetching a topologypublic boolean isStaticHostListProvider()
isStaticHostListProvider in interface HostListProviderServicepublic void setHostListProvider(HostListProvider hostListProvider)
setHostListProvider in interface HostListProviderServicepublic java.sql.Connection connect(HostSpec hostSpec, java.util.Properties props) throws java.sql.SQLException
PluginServiceConnectionProvider has been set with
Driver.setCustomConnectionProvider(ConnectionProvider) and
ConnectionProvider.acceptsUrl(String, HostSpec, Properties) returns true for the
desired protocol, host, and properties, the connection will be created by the non-default
ConnectionProvider. Otherwise, the connection will be created by the default
ConnectionProvider. The default ConnectionProvider will be DriverConnectionProvider for
connections requested via the DriverManager and
DataSourceConnectionProvider for connections requested via an
AwsWrapperDataSource.connect in interface PluginServicehostSpec - the host details for the desired connectionprops - the connection propertiesConnection to the requested hostjava.sql.SQLException - if there was an error establishing a Connection to the requested
hostpublic java.sql.Connection connect(HostSpec hostSpec, java.util.Properties props, @Nullable ConnectionPlugin pluginToSkip) throws java.sql.SQLException
connect in interface PluginServicejava.sql.SQLExceptionpublic java.sql.Connection forceConnect(HostSpec hostSpec, java.util.Properties props) throws java.sql.SQLException
PluginServiceConnectionPlugin.connect(java.lang.String, software.amazon.jdbc.HostSpec, java.util.Properties, boolean, software.amazon.jdbc.JdbcCallable<java.sql.Connection, java.sql.SQLException>) in that the default ConnectionProvider will be used to
establish the connection even if a non-default ConnectionProvider has been set via
Driver.setCustomConnectionProvider(ConnectionProvider). The default ConnectionProvider will be
DriverConnectionProvider for connections requested via the
DriverManager and DataSourceConnectionProvider for connections
requested via an AwsWrapperDataSource.forceConnect in interface PluginServicehostSpec - the host details for the desired connectionprops - the connection propertiesConnection to the requested hostjava.sql.SQLException - if there was an error establishing a Connection to the requested
hostpublic java.sql.Connection forceConnect(HostSpec hostSpec, java.util.Properties props, @Nullable ConnectionPlugin pluginToSkip) throws java.sql.SQLException
forceConnect in interface PluginServicejava.sql.SQLExceptionpublic void releaseResources()
CanReleaseResourcesCalling this method does NOT mean that an object is disposing and there won't be any further calls. An object should keep its functional state after calling this method.
releaseResources in interface CanReleaseResources@Deprecated public boolean isNetworkException(java.lang.Throwable throwable)
ExceptionHandlerisNetworkException in interface ExceptionHandlerthrowable - A throwable object to check.public boolean isNetworkException(java.lang.Throwable throwable,
@Nullable TargetDriverDialect targetDriverDialect)
isNetworkException in interface ExceptionHandlerpublic boolean isNetworkException(java.lang.String sqlState)
isNetworkException in interface ExceptionHandler@Deprecated public boolean isLoginException(java.lang.Throwable throwable)
ExceptionHandlerisLoginException in interface ExceptionHandlerthrowable - A throwable object to check.public boolean isLoginException(java.lang.Throwable throwable,
@Nullable TargetDriverDialect targetDriverDialect)
isLoginException in interface ExceptionHandlerpublic boolean isLoginException(java.lang.String sqlState)
isLoginException in interface ExceptionHandlerpublic Dialect getDialect()
getDialect in interface HostListProviderServicegetDialect in interface PluginServicepublic TargetDriverDialect getTargetDriverDialect()
getTargetDriverDialect in interface PluginServicepublic void updateDialect(@NonNull java.sql.Connection connection)
throws java.sql.SQLException
updateDialect in interface PluginServicejava.sql.SQLExceptionpublic HostSpec identifyConnection(java.sql.Connection connection) throws java.sql.SQLException
identifyConnection in interface PluginServicejava.sql.SQLExceptionpublic void fillAliases(java.sql.Connection connection,
HostSpec hostSpec)
throws java.sql.SQLException
fillAliases in interface PluginServicejava.sql.SQLExceptionpublic HostSpecBuilder getHostSpecBuilder()
getHostSpecBuilder in interface HostListProviderServicegetHostSpecBuilder in interface PluginServicepublic java.util.Properties getProperties()
getProperties in interface PluginServicepublic TelemetryFactory getTelemetryFactory()
getTelemetryFactory in interface PluginServicepublic java.lang.String getTargetName()
getTargetName in interface PluginServicepublic @NonNull SessionStateService getSessionStateService()
getSessionStateService in interface PluginServicepublic <T> T getPlugin(java.lang.Class<T> pluginClazz)
getPlugin in interface PluginServicepublic static void clearCache()
@Deprecated
public <T> void setStatus(java.lang.Class<T> clazz,
T status,
boolean clusterBound)
setStatus in interface PluginService@Deprecated
public <T> void setStatus(java.lang.Class<T> clazz,
T status,
java.lang.String key)
setStatus in interface PluginService@Deprecated
public <T> T getStatus(@NonNull java.lang.Class<T> clazz,
boolean clusterBound)
getStatus in interface PluginService@Deprecated
public <T> T getStatus(@NonNull java.lang.Class<T> clazz,
java.lang.String key)
getStatus in interface PluginServiceprotected <T> java.lang.String getStatusCacheKey(java.lang.Class<T> clazz,
java.lang.String key)
public boolean isPluginInUse(java.lang.Class<? extends ConnectionPlugin> pluginClazz)
isPluginInUse in interface PluginService