public class PartialPluginService extends java.lang.Object implements PluginService, CanReleaseResources, HostListProviderService, PluginManagerService
PluginService containing some methods that are not intended to be called. This class is intended to be used
by monitors, which require a PluginService, but are not expected to need or use some of the methods defined
by the PluginService interface. The methods that are not expected to be called will log a warning or throw an
UnsupportedOperationException when called.| Modifier and Type | Field and Description |
|---|---|
protected java.util.List<HostSpec> |
allHosts |
protected @Nullable ConfigurationProfile |
configurationProfile |
protected ConnectionProviderManager |
connectionProviderManager |
protected HostSpec |
currentHostSpec |
protected Dialect |
dbDialect |
protected static long |
DEFAULT_HOST_AVAILABILITY_CACHE_EXPIRE_NANO |
protected static int |
DEFAULT_TOPOLOGY_QUERY_TIMEOUT_MS |
protected java.lang.String |
driverProtocol |
protected @Nullable ExceptionHandler |
exceptionHandler |
protected ExceptionManager |
exceptionManager |
protected static CacheMap<java.lang.String,HostAvailability> |
hostAvailabilityExpiringCache |
protected HostListProvider |
hostListProvider |
protected HostSpec |
initialConnectionHostSpec |
protected boolean |
isInTransaction |
protected java.lang.String |
originalUrl |
protected ConnectionPluginManager |
pluginManager |
protected java.util.Properties |
props |
protected FullServicesContainer |
servicesContainer |
protected TargetDriverDialect |
targetDriverDialect |
| Constructor and Description |
|---|
PartialPluginService(@NonNull FullServicesContainer servicesContainer,
@NonNull ExceptionManager exceptionManager,
@NonNull java.util.Properties props,
@NonNull java.lang.String originalUrl,
@NonNull java.lang.String targetDriverProtocol,
@NonNull TargetDriverDialect targetDriverDialect,
@NonNull Dialect dbDialect,
@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 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() |
@Nullable 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) |
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 pooledConnection) |
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 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 final java.util.Properties props
protected volatile HostListProvider hostListProvider
protected java.util.List<HostSpec> allHosts
protected HostSpec currentHostSpec
protected HostSpec initialConnectionHostSpec
protected boolean isInTransaction
protected final ExceptionManager exceptionManager
protected final @Nullable ExceptionHandler exceptionHandler
protected final java.lang.String originalUrl
protected final java.lang.String driverProtocol
protected TargetDriverDialect targetDriverDialect
protected Dialect dbDialect
protected final @Nullable ConfigurationProfile configurationProfile
protected final ConnectionProviderManager connectionProviderManager
public PartialPluginService(@NonNull FullServicesContainer servicesContainer, @NonNull ExceptionManager exceptionManager, @NonNull java.util.Properties props, @NonNull java.lang.String originalUrl, @NonNull java.lang.String targetDriverProtocol, @NonNull TargetDriverDialect targetDriverDialect, @NonNull Dialect dbDialect, @Nullable ConfigurationProfile configurationProfile) 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 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 boolean isDialectConfirmed()
isDialectConfirmed 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 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)
updateDialect in interface PluginServicepublic @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 <T> T getPlugin(java.lang.Class<T> pluginClazz)
getPlugin in interface PluginServicepublic boolean isPluginInUse(java.lang.Class<? extends ConnectionPlugin> pluginClazz)
isPluginInUse in interface PluginServicepublic 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 pooledConnection)
setIsPooledConnection in interface PluginManagerServicepublic PluginCallContext getCallContext()
PluginServicegetCallContext in interface PluginServicePluginCallContext.public 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 static void clearCache()
public @Nullable java.util.List<Pair<java.lang.String,java.lang.Object>> getSnapshotState()
getSnapshotState in interface StateSnapshotProvider