public class PluginServiceImpl extends java.lang.Object implements PluginService, CanReleaseResources, HostListProviderService, PluginManagerService
| Modifier and Type | Field and Description |
|---|---|
protected java.sql.Connection |
currentConnection |
protected HostSpec |
currentHostSpec |
protected static long |
DEFAULT_HOST_AVAILABILITY_CACHE_EXPIRE_NANO |
protected Dialect |
dialect |
protected DialectProvider |
dialectProvider |
protected static CacheMap<java.lang.String,HostAvailability> |
hostAvailabilityExpiringCache |
protected HostListProvider |
hostListProvider |
protected java.util.List<HostSpec> |
hosts |
protected HostSpec |
initialConnectionHostSpec |
protected ConnectionPluginManager |
pluginManager |
| Constructor and Description |
|---|
PluginServiceImpl(@NonNull ConnectionPluginManager pluginManager,
@NonNull ExceptionManager exceptionManager,
@NonNull java.util.Properties props,
@NonNull java.lang.String originalUrl,
java.lang.String targetDriverProtocol,
@Nullable DialectProvider dialectProvider) |
PluginServiceImpl(@NonNull ConnectionPluginManager pluginManager,
@NonNull java.util.Properties props,
@NonNull java.lang.String originalUrl,
java.lang.String targetDriverProtocol) |
| 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). |
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.
|
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.
|
void |
forceRefreshHostList() |
void |
forceRefreshHostList(java.sql.Connection connection) |
ConnectionProvider |
getConnectionProvider() |
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() |
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 |
getInitialConnectionHostSpec() |
HostSpec |
identifyConnection(java.sql.Connection connection) |
boolean |
isExplicitReadOnly() |
boolean |
isInTransaction() |
boolean |
isLoginException(java.lang.String sqlState) |
boolean |
isLoginException(java.lang.Throwable throwable) |
boolean |
isNetworkException(java.lang.String sqlState) |
boolean |
isNetworkException(java.lang.Throwable throwable) |
boolean |
isReadOnly() |
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 |
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) |
void |
setHostListProvider(HostListProvider hostListProvider) |
void |
setInitialConnectionHostSpec(@NonNull HostSpec initialConnectionHostSpec) |
void |
setInTransaction(boolean inTransaction) |
void |
setReadOnly(boolean readOnly) |
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 ConnectionPluginManager pluginManager
protected volatile HostListProvider hostListProvider
protected java.util.List<HostSpec> hosts
protected java.sql.Connection currentConnection
protected HostSpec currentHostSpec
protected HostSpec initialConnectionHostSpec
protected final DialectProvider dialectProvider
protected Dialect dialect
public PluginServiceImpl(@NonNull ConnectionPluginManager pluginManager, @NonNull java.util.Properties props, @NonNull java.lang.String originalUrl, java.lang.String targetDriverProtocol) throws java.sql.SQLException
java.sql.SQLExceptionpublic PluginServiceImpl(@NonNull ConnectionPluginManager pluginManager, @NonNull ExceptionManager exceptionManager, @NonNull java.util.Properties props, @NonNull java.lang.String originalUrl, java.lang.String targetDriverProtocol, @Nullable DialectProvider dialectProvider) 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 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.SQLExceptionpublic 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 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 getConnectionProvider()
getConnectionProvider 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
setCurrentConnection in interface PluginServicejava.sql.SQLExceptionprotected 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> getHosts()
getHosts in interface PluginServicepublic void setAvailability(@NonNull java.util.Set<java.lang.String> hostAliases,
@NonNull HostAvailability availability)
setAvailability in interface PluginServicepublic boolean isExplicitReadOnly()
isExplicitReadOnly in interface PluginServicepublic boolean isReadOnly()
isReadOnly in interface PluginServicepublic boolean isInTransaction()
isInTransaction in interface PluginServicepublic void setReadOnly(boolean readOnly)
setReadOnly in interface PluginManagerServicepublic 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 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
ConnectionProviderManager.setConnectionProvider(software.amazon.jdbc.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 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
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.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 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)
isNetworkException in interface ExceptionHandlerpublic boolean isNetworkException(java.lang.String sqlState)
isNetworkException in interface ExceptionHandlerpublic boolean isLoginException(java.lang.Throwable throwable)
isLoginException in interface ExceptionHandlerpublic boolean isLoginException(java.lang.String sqlState)
isLoginException in interface ExceptionHandlerpublic Dialect getDialect()
getDialect in interface HostListProviderServicegetDialect 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 PluginService