public class ConnectionPluginManager extends java.lang.Object implements CanReleaseResources, java.sql.Wrapper
ConnectionPlugin for each connection.
THIS CLASS IS NOT MULTI-THREADING SAFE IT'S EXPECTED TO HAVE ONE INSTANCE OF THIS MANAGER PER JDBC CONNECTION
| Modifier and Type | Class and Description |
|---|---|
protected static interface |
ConnectionPluginManager.PluginChainJdbcCallable<T,E extends java.lang.Exception> |
protected static class |
ConnectionPluginManager.PluginChainJdbcCallableInfo<T,E extends java.lang.Exception> |
protected static interface |
ConnectionPluginManager.PluginPipeline<T,E extends java.lang.Exception> |
| Modifier and Type | Field and Description |
|---|---|
protected ConnectionWrapper |
connectionWrapper |
protected @NonNull ConnectionProvider |
defaultConnProvider |
protected @Nullable ConnectionProvider |
effectiveConnProvider |
protected boolean |
isTelemetryInUse |
protected ConnectionPluginManager.PluginChainJdbcCallableInfo[] |
pluginChainFuncMap |
protected static java.util.Map<java.lang.Class<? extends ConnectionPlugin>,java.lang.String> |
pluginNameByClass |
protected java.util.List<ConnectionPlugin> |
plugins |
protected PluginService |
pluginService |
protected java.util.Properties |
props |
protected FullServicesContainer |
servicesContainer |
protected TelemetryFactory |
telemetryFactory |
| Constructor and Description |
|---|
ConnectionPluginManager(@NonNull ConnectionProvider defaultConnProvider,
@Nullable ConnectionProvider effectiveConnProvider,
@Nullable ConnectionWrapper connectionWrapper,
@NonNull TelemetryFactory telemetryFactory) |
| 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 implement the selection of a host with the requested role
and strategy via getHostSpecByStrategy(software.amazon.jdbc.HostRole, java.lang.String). |
java.sql.Connection |
connect(java.lang.String driverProtocol,
HostSpec hostSpec,
java.util.Properties props,
boolean isInitialConnection,
@Nullable ConnectionPlugin pluginToSkip)
Establishes a connection to the given host using the given driver protocol and properties.
|
<T,E extends java.lang.Exception> |
execute(java.lang.Class<T> resultType,
java.lang.Class<E> exceptionClass,
java.lang.Object methodInvokeOn,
JdbcMethod jdbcMethod,
JdbcCallable<T,E> jdbcMethodFunc,
java.lang.Object[] jdbcMethodArgs) |
protected <T,E extends java.lang.Exception> |
executeWithSubscribedPlugins(JdbcMethod jdbcMethod,
ConnectionPluginManager.PluginPipeline<T,E> pluginPipeline,
JdbcCallable<T,E> jdbcMethodFunc,
@Nullable ConnectionPlugin pluginToSkip) |
protected <T,E extends java.lang.Exception> |
executeWithTelemetry(@NonNull JdbcCallable<T,E> execution,
@NonNull java.lang.String pluginName) |
java.sql.Connection |
forceConnect(java.lang.String driverProtocol,
HostSpec hostSpec,
java.util.Properties props,
boolean isInitialConnection,
@Nullable ConnectionPlugin pluginToSkip)
Establishes a connection to the given host using the given driver protocol and properties.
|
ConnectionWrapper |
getConnectionWrapper() |
@NonNull ConnectionProvider |
getDefaultConnProvider() |
@Nullable ConnectionProvider |
getEffectiveConnProvider() |
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) |
TelemetryFactory |
getTelemetryFactory() |
void |
init(FullServicesContainer servicesContainer,
java.util.Properties props,
PluginManagerService pluginManagerService,
@Nullable ConfigurationProfile configurationProfile)
Initialize a chain of
ConnectionPlugin using their corresponding ConnectionPluginFactory. |
void |
initHostProvider(java.lang.String driverProtocol,
java.lang.String initialUrl,
java.util.Properties props,
HostListProviderService hostListProviderService) |
boolean |
isWrapperFor(java.lang.Class<?> iface) |
void |
lock() |
protected <T,E extends java.lang.Exception> |
makePluginChainFunc(@NonNull java.lang.String methodName) |
boolean |
mustUsePipeline(JdbcMethod jdbcMethod) |
java.util.EnumSet<OldConnectionSuggestedAction> |
notifyConnectionChanged(@NonNull java.util.EnumSet<NodeChangeOptions> changes,
@Nullable ConnectionPlugin skipNotificationForThisPlugin) |
void |
notifyNodeListChanged(@NonNull java.util.Map<java.lang.String,java.util.EnumSet<NodeChangeOptions>> changes) |
protected <E extends java.lang.Exception> |
notifySubscribedPlugins(java.lang.String methodName,
ConnectionPluginManager.PluginPipeline<java.lang.Void,E> pluginPipeline,
ConnectionPlugin skipNotificationForThisPlugin) |
void |
releaseResources()
Release all dangling resources held by the connection plugins associated with a single
connection.
|
void |
unlock() |
<T> T |
unwrap(java.lang.Class<T> iface) |
protected static final java.util.Map<java.lang.Class<? extends ConnectionPlugin>,java.lang.String> pluginNameByClass
protected java.util.Properties props
protected java.util.List<ConnectionPlugin> plugins
protected final @NonNull ConnectionProvider defaultConnProvider
protected final @Nullable ConnectionProvider effectiveConnProvider
protected final ConnectionWrapper connectionWrapper
protected FullServicesContainer servicesContainer
protected PluginService pluginService
protected TelemetryFactory telemetryFactory
protected boolean isTelemetryInUse
protected final ConnectionPluginManager.PluginChainJdbcCallableInfo[] pluginChainFuncMap
public ConnectionPluginManager(@NonNull ConnectionProvider defaultConnProvider, @Nullable ConnectionProvider effectiveConnProvider, @Nullable ConnectionWrapper connectionWrapper, @NonNull TelemetryFactory telemetryFactory)
public void lock()
public void unlock()
public void init(FullServicesContainer servicesContainer, java.util.Properties props, PluginManagerService pluginManagerService, @Nullable ConfigurationProfile configurationProfile) throws java.sql.SQLException
ConnectionPlugin using their corresponding ConnectionPluginFactory. If PropertyDefinition.PLUGINS is provided by the user,
initialize the chain with the given connection plugins in the order they are specified.
The DefaultConnectionPlugin will always be initialized and attached as the last
connection plugin in the chain.
servicesContainer - the service container for the services required by this class.props - the configuration of the connectionpluginManagerService - a reference to a plugin manager serviceconfigurationProfile - a profile configuration defined by the userjava.sql.SQLException - if errors occurred during the executionprotected <T,E extends java.lang.Exception> T executeWithSubscribedPlugins(JdbcMethod jdbcMethod, ConnectionPluginManager.PluginPipeline<T,E> pluginPipeline, JdbcCallable<T,E> jdbcMethodFunc, @Nullable ConnectionPlugin pluginToSkip) throws E extends java.lang.Exception
E extends java.lang.Exceptionprotected <T,E extends java.lang.Exception> T executeWithTelemetry(@NonNull JdbcCallable<T,E> execution, @NonNull java.lang.String pluginName) throws E extends java.lang.Exception
E extends java.lang.Exceptionprotected <T,E extends java.lang.Exception> @Nullable ConnectionPluginManager.PluginChainJdbcCallableInfo<T,E> makePluginChainFunc(@NonNull java.lang.String methodName)
protected <E extends java.lang.Exception> void notifySubscribedPlugins(java.lang.String methodName,
ConnectionPluginManager.PluginPipeline<java.lang.Void,E> pluginPipeline,
ConnectionPlugin skipNotificationForThisPlugin)
throws E extends java.lang.Exception
E extends java.lang.Exceptionpublic ConnectionWrapper getConnectionWrapper()
public TelemetryFactory getTelemetryFactory()
public boolean mustUsePipeline(JdbcMethod jdbcMethod)
public <T,E extends java.lang.Exception> T execute(java.lang.Class<T> resultType,
java.lang.Class<E> exceptionClass,
java.lang.Object methodInvokeOn,
JdbcMethod jdbcMethod,
JdbcCallable<T,E> jdbcMethodFunc,
java.lang.Object[] jdbcMethodArgs)
throws E extends java.lang.Exception
E extends java.lang.Exceptionpublic java.sql.Connection connect(java.lang.String driverProtocol,
HostSpec hostSpec,
java.util.Properties props,
boolean isInitialConnection,
@Nullable ConnectionPlugin pluginToSkip)
throws java.sql.SQLException
ConnectionProvider has been set with
Driver.setCustomConnectionProvider(ConnectionProvider) and
ConnectionProvider.acceptsUrl(String, HostSpec, Properties) returns true for the given
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.driverProtocol - the driver protocol that should be used to establish the connectionhostSpec - the host details for the desired connectionprops - the connection propertiesisInitialConnection - a boolean indicating whether the current Connection is
establishing an initial physical connection to the database or has
already established a physical connection in the pastpluginToSkip - the plugin that needs to be skipped while executing this pipelineConnection to the requested hostjava.sql.SQLException - if there was an error establishing a Connection to the requested
hostpublic java.sql.Connection forceConnect(java.lang.String driverProtocol,
HostSpec hostSpec,
java.util.Properties props,
boolean isInitialConnection,
@Nullable ConnectionPlugin pluginToSkip)
throws java.sql.SQLException
ConnectionPlugin.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.driverProtocol - the driver protocol that should be used to establish the connectionhostSpec - the host details for the desired connectionprops - the connection propertiesisInitialConnection - a boolean indicating whether the current Connection is
establishing an initial physical connection to the database or has
already established a physical connection in the pastpluginToSkip - the plugin that needs to be skipped while executing this pipelineConnection to the requested hostjava.sql.SQLException - if there was an error establishing a Connection to the requested
hostpublic boolean acceptsStrategy(HostRole role, java.lang.String strategy) throws java.sql.SQLException
ConnectionProvider or
ConnectionPlugin instances implement the selection of a host with the requested role
and strategy via getHostSpecByStrategy(software.amazon.jdbc.HostRole, java.lang.String).role - 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
getHostSpecByStrategy(software.amazon.jdbc.HostRole, java.lang.String). Otherwise, return false.java.sql.SQLException - if there's error processing this methodpublic HostSpec getHostSpecByStrategy(HostRole role, java.lang.String strategy) throws java.sql.SQLException, java.lang.UnsupportedOperationException
HostSpec with the requested role from available hosts using the requested
strategy. 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.role - 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 hosts do not contain any hosts matching
the requested role or an error occurs while selecting a
hostjava.lang.UnsupportedOperationException - if the available ConnectionProvider or
ConnectionPlugin instances do not support the
requested strategypublic HostSpec getHostSpecByStrategy(java.util.List<HostSpec> hosts, HostRole role, java.lang.String strategy) throws java.sql.SQLException, java.lang.UnsupportedOperationException
java.sql.SQLExceptionjava.lang.UnsupportedOperationExceptionpublic void initHostProvider(java.lang.String driverProtocol,
java.lang.String initialUrl,
java.util.Properties props,
HostListProviderService hostListProviderService)
throws java.sql.SQLException
java.sql.SQLExceptionpublic java.util.EnumSet<OldConnectionSuggestedAction> notifyConnectionChanged(@NonNull java.util.EnumSet<NodeChangeOptions> changes, @Nullable ConnectionPlugin skipNotificationForThisPlugin)
public void notifyNodeListChanged(@NonNull java.util.Map<java.lang.String,java.util.EnumSet<NodeChangeOptions>> changes)
public void releaseResources()
releaseResources in interface CanReleaseResourcespublic <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 @NonNull ConnectionProvider getDefaultConnProvider()
public @Nullable ConnectionProvider getEffectiveConnProvider()