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 | Field and Description |
|---|---|
protected static java.lang.String |
ALL_METHODS |
protected static java.lang.String |
CONNECT_METHOD |
protected ConnectionWrapper |
connectionWrapper |
protected @NonNull ConnectionProvider |
defaultConnProvider |
protected @Nullable ConnectionProvider |
effectiveConnProvider |
protected static java.lang.String |
GET_HOST_SPEC_BY_STRATEGY_METHOD |
protected java.util.Map<java.lang.String,software.amazon.jdbc.ConnectionPluginManager.PluginChainJdbcCallable> |
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 TelemetryFactory |
telemetryFactory |
| Constructor and Description |
|---|
ConnectionPluginManager(@NonNull ConnectionProvider defaultConnProvider,
@Nullable ConnectionProvider effectiveConnProvider,
@NonNull 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)
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,
java.lang.String methodName,
JdbcCallable<T,E> jdbcMethodFunc,
java.lang.Object[] jdbcMethodArgs) |
protected <T,E extends java.lang.Exception> |
executeWithSubscribedPlugins(java.lang.String methodName,
software.amazon.jdbc.ConnectionPluginManager.PluginPipeline<T,E> pluginPipeline,
JdbcCallable<T,E> jdbcMethodFunc) |
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)
Establishes a connection to the given host using the given driver protocol and properties.
|
ConnectionWrapper |
getConnectionWrapper() |
ConnectionProvider |
getDefaultConnProvider() |
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(PluginService pluginService,
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 |
isHeldByCurrentThread() |
boolean |
isWrapperFor(java.lang.Class<?> iface) |
void |
lock() |
protected <T,E extends java.lang.Exception> |
makePluginChainFunc(@NonNull java.lang.String methodName) |
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,
software.amazon.jdbc.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 static final java.lang.String ALL_METHODS
protected static final java.lang.String CONNECT_METHOD
protected static final java.lang.String GET_HOST_SPEC_BY_STRATEGY_METHOD
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 PluginService pluginService
protected TelemetryFactory telemetryFactory
protected final java.util.Map<java.lang.String,software.amazon.jdbc.ConnectionPluginManager.PluginChainJdbcCallable> pluginChainFuncMap
public ConnectionPluginManager(@NonNull ConnectionProvider defaultConnProvider, @Nullable ConnectionProvider effectiveConnProvider, @NonNull ConnectionWrapper connectionWrapper, @NonNull TelemetryFactory telemetryFactory)
public void lock()
public void unlock()
public boolean isHeldByCurrentThread()
public void init(PluginService pluginService, 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.
pluginService - a reference to a plugin service that plugin can useprops - 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(java.lang.String methodName,
software.amazon.jdbc.ConnectionPluginManager.PluginPipeline<T,E> pluginPipeline,
JdbcCallable<T,E> jdbcMethodFunc)
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 software.amazon.jdbc.ConnectionPluginManager.PluginChainJdbcCallable<T,E> makePluginChainFunc(@NonNull java.lang.String methodName)
protected <E extends java.lang.Exception> void notifySubscribedPlugins(java.lang.String methodName,
software.amazon.jdbc.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 <T,E extends java.lang.Exception> T execute(java.lang.Class<T> resultType,
java.lang.Class<E> exceptionClass,
java.lang.Object methodInvokeOn,
java.lang.String methodName,
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)
throws java.sql.SQLException
ConnectionProvider has been set with
ConnectionProviderManager.setConnectionProvider(software.amazon.jdbc.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 pastConnection 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)
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 ConnectionProviderManager.setConnectionProvider(software.amazon.jdbc.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 pastConnection 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.SQLExceptionpublic 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 ConnectionProvider getDefaultConnProvider()
public ConnectionProvider getEffectiveConnProvider()