public class PluginServiceImpl extends java.lang.Object implements PluginService, CanReleaseResources, HostListProviderService, PluginManagerService, java.sql.Wrapper
| 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) |
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 verifyTopology,
long timeoutMs)
Initiates a topology update.
|
java.util.List<HostSpec> |
getAllHosts()
Get host information for all hosts in the cluster.
|
PluginCallContext |
getCallContext()
Returns the per-call context that flows through the plugin pipeline for the current JDBC call.
|
java.sql.Connection |
getCurrentConnection() |
HostSpec |
getCurrentHostSpec() |
ConnectionProvider |
getDefaultConnectionProvider() |
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(@Nullable 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,
@Nullable 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() |
@Nullable HostSpec |
getRoutedHostSpec() |
@NonNull SessionStateService |
getSessionStateService() |
java.util.List<Pair<java.lang.String,java.lang.Object>> |
getSnapshotState() |
TargetDriverDialect |
getTargetDriverDialect() |
java.lang.String |
getTargetName() |
TelemetryFactory |
getTelemetryFactory() |
TrackedConnectionList.Node |
getTrackedConnectionNode()
Returns the tracked connection list node associated with the current connection.
|
@Nullable HostSpec |
identifyConnection(java.sql.Connection connection) |
@Nullable HostSpec |
identifyConnection(java.sql.Connection connection,
@NonNull HostSpec connectionHostSpec) |
boolean |
isDialectConfirmed() |
boolean |
isInTransaction() |
boolean |
isLoginException(@Nullable java.lang.String sqlState) |
boolean |
isLoginException(java.lang.Throwable throwable,
@Nullable TargetDriverDialect targetDriverDialect) |
boolean |
isNetworkException(@Nullable java.lang.String sqlState) |
boolean |
isNetworkException(java.lang.Throwable throwable,
@Nullable TargetDriverDialect targetDriverDialect) |
boolean |
isPluginInUse(java.lang.Class<? extends ConnectionPlugin> pluginClazz) |
@Nullable java.lang.Boolean |
isPooledConnection()
Retrieves details about the most recent
PluginService.connect(software.amazon.jdbc.HostSpec, java.util.Properties, software.amazon.jdbc.ConnectionPlugin) or
PluginService.forceConnect(software.amazon.jdbc.HostSpec, java.util.Properties) calls. |
boolean |
isPooledConnectionProvider(HostSpec host,
java.util.Properties props)
Deprecated.
|
boolean |
isReadOnlyConnectionException(@Nullable java.lang.String sqlState,
@Nullable java.lang.Integer errorCode) |
boolean |
isReadOnlyConnectionException(java.lang.Throwable throwable,
@Nullable TargetDriverDialect targetDriverDialect) |
boolean |
isStaticHostListProvider() |
boolean |
isWrapperFor(java.lang.Class<?> iface) |
void |
refreshHostList() |
void |
releaseResources()
An object that implements this interface should release all acquired resources assuming it may
be disposed at any time.
|
void |
resetCallContext() |
void |
setAvailability(@NonNull HostSpec hostSpec,
@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) |
void |
setIsPooledConnection(@Nullable java.lang.Boolean isPooledConnection) |
void |
setRoutedHostSpec(@Nullable HostSpec routedHostSpec) |
void |
setTrackedConnectionNode(TrackedConnectionList.Node node)
Sets the tracked connection list node for the current connection.
|
<T> T |
unwrap(java.lang.Class<T> iface) |
void |
updateDialect(@NonNull java.sql.Connection connection) |
protected void |
updateHostListProvider() |
protected static final long DEFAULT_HOST_AVAILABILITY_CACHE_EXPIRE_NANO
protected static final int DEFAULT_TOPOLOGY_QUERY_TIMEOUT_MS
protected static final CacheMap<java.lang.String,HostAvailability> hostAvailabilityExpiringCache
protected final FullServicesContainer servicesContainer
protected final ConnectionPluginManager pluginManager
protected volatile HostListProvider hostListProvider
protected java.util.List<HostSpec> allHosts
protected java.sql.Connection currentConnection
protected @Nullable HostSpec currentHostSpec
protected HostSpec initialConnectionHostSpec
protected @Nullable HostSpec routedHostSpec
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 ResourceLock connectionSwitchLock
protected TrackedConnectionList.Node trackedConnectionNode
protected @Nullable java.lang.Boolean pooledConnection
protected final PluginCallContext callContext
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 PluginServicepublic 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(@Nullable 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, @Nullable 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 rolepublic ConnectionProvider getDefaultConnectionProvider()
getDefaultConnectionProvider in interface PluginService@Deprecated public 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.public @Nullable HostSpec getRoutedHostSpec()
getRoutedHostSpec in interface PluginServicepublic void setRoutedHostSpec(@Nullable HostSpec routedHostSpec)
setRoutedHostSpec in interface PluginServiceprotected 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 HostSpec hostSpec, @NonNull HostAvailability availability)
setAvailability in interface PluginServicepublic boolean isInTransaction()
isInTransaction in interface PluginServicepublic void setInTransaction(boolean inTransaction)
setInTransaction in interface PluginManagerServicepublic boolean isDialectConfirmed()
isDialectConfirmed in interface PluginServicepublic HostListProvider getHostListProvider()
getHostListProvider in interface HostListProviderServicegetHostListProvider in interface PluginServicepublic void refreshHostList()
throws java.sql.SQLException
refreshHostList in interface PluginServicejava.sql.SQLExceptionpublic void forceRefreshHostList()
throws java.sql.SQLException
forceRefreshHostList in interface PluginServicejava.sql.SQLExceptionpublic boolean forceRefreshHostList(boolean verifyTopology,
long timeoutMs)
throws java.sql.SQLException
PluginServiceforceRefreshHostList in interface PluginServiceverifyTopology - defines whether extra measures should be taken to verify the topology. If false, the
method will return as soon as topology is successfully retrieved from any instance. If
true, extra steps are taken to verify the topology is accurate.timeoutMs - timeout in msec to wait until the topology gets refreshed (if verifyWriter has a value of
false) or verified (if verifyTopology 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 CanReleaseResourcespublic boolean isNetworkException(java.lang.Throwable throwable,
@Nullable TargetDriverDialect targetDriverDialect)
isNetworkException in interface ExceptionHandlerpublic boolean isNetworkException(@Nullable java.lang.String sqlState)
isNetworkException in interface ExceptionHandlerpublic boolean isLoginException(java.lang.Throwable throwable,
@Nullable TargetDriverDialect targetDriverDialect)
isLoginException in interface ExceptionHandlerpublic boolean isLoginException(@Nullable java.lang.String sqlState)
isLoginException in interface ExceptionHandlerpublic boolean isReadOnlyConnectionException(@Nullable java.lang.String sqlState,
@Nullable java.lang.Integer errorCode)
isReadOnlyConnectionException in interface ExceptionHandlerpublic boolean isReadOnlyConnectionException(java.lang.Throwable throwable,
@Nullable TargetDriverDialect targetDriverDialect)
isReadOnlyConnectionException 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.SQLExceptionprotected void updateHostListProvider()
throws java.sql.SQLException
java.sql.SQLExceptionpublic @Nullable HostSpec identifyConnection(java.sql.Connection connection, @NonNull HostSpec connectionHostSpec) throws java.sql.SQLException
identifyConnection in interface PluginServicejava.sql.SQLExceptionpublic @Nullable HostSpec identifyConnection(java.sql.Connection connection) throws java.sql.SQLException
identifyConnection 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 PluginCallContext getCallContext()
PluginServicegetCallContext in interface PluginServicePluginCallContext.public <T> T getPlugin(java.lang.Class<T> pluginClazz)
getPlugin in interface PluginServicepublic static void clearCache()
public boolean isPluginInUse(java.lang.Class<? extends ConnectionPlugin> pluginClazz)
isPluginInUse in interface PluginServicepublic @Nullable java.lang.Boolean isPooledConnection()
PluginServicePluginService.connect(software.amazon.jdbc.HostSpec, java.util.Properties, software.amazon.jdbc.ConnectionPlugin) or
PluginService.forceConnect(software.amazon.jdbc.HostSpec, java.util.Properties) calls. Specifically indicates whether the
returned connection was obtained from a connection pool or newly created.
Note: The ConnectionPlugin must process or store this information during
the current JDBC call, as these details will be reset before the next JDBC call
is processed, or another PluginService.connect(software.amazon.jdbc.HostSpec, java.util.Properties, software.amazon.jdbc.ConnectionPlugin) or PluginService.forceConnect(software.amazon.jdbc.HostSpec, java.util.Properties)
is made.
isPooledConnection in interface PluginServicepublic void setIsPooledConnection(@Nullable java.lang.Boolean isPooledConnection)
setIsPooledConnection in interface PluginManagerServicepublic TrackedConnectionList.Node getTrackedConnectionNode()
PluginServicegetTrackedConnectionNode in interface PluginServicepublic void setTrackedConnectionNode(TrackedConnectionList.Node node)
PluginServicesetTrackedConnectionNode in interface PluginServicenode - the node returned by
OpenedConnectionTracker.populateOpenedConnectionQueue(software.amazon.jdbc.HostSpec, java.sql.Connection)public void resetCallContext()
resetCallContext in interface PluginManagerServicepublic <T> T unwrap(java.lang.Class<T> iface)
throws java.sql.SQLException
unwrap in interface java.sql.Wrapperjava.sql.SQLExceptionpublic boolean isWrapperFor(java.lang.Class<?> iface)
throws java.sql.SQLException
isWrapperFor in interface java.sql.Wrapperjava.sql.SQLExceptionpublic java.util.List<Pair<java.lang.String,java.lang.Object>> getSnapshotState()
getSnapshotState in interface StateSnapshotProvider