public abstract class AbstractReadWriteSplittingPlugin extends AbstractConnectionPlugin implements CanReleaseResources
| Modifier and Type | Field and Description |
|---|---|
static AwsWrapperProperty |
CACHED_READER_KEEP_ALIVE_TIMEOUT |
protected HostListProviderService |
hostListProviderService |
protected boolean |
inReadWriteSplit |
protected boolean |
isReaderConnFromInternalPool |
protected boolean |
isWriterConnFromInternalPool |
protected PluginService |
pluginService |
protected java.util.Properties |
properties |
protected CacheItem<java.sql.Connection> |
readerCacheItem |
protected HostSpec |
readerHostSpec |
protected java.sql.Connection |
writerConnection |
protected HostSpec |
writerHostSpec |
| Constructor and Description |
|---|
AbstractReadWriteSplittingPlugin(PluginService pluginService,
java.util.Properties properties) |
| Modifier and Type | Method and Description |
|---|---|
void |
closeReaderConnectionIfIdle() |
protected abstract void |
closeReaderIfNecessary() |
void |
closeWriterConnectionIfIdle() |
<T,E extends java.lang.Exception> |
execute(java.lang.Class<T> resultClass,
java.lang.Class<E> exceptionClass,
java.lang.Object methodInvokeOn,
java.lang.String methodName,
JdbcCallable<T,E> jdbcMethodFunc,
java.lang.Object[] args) |
protected long |
getKeepAliveTimeout(boolean isPooledConnection) |
java.sql.Connection |
getReaderConnection() |
HostSpec |
getReaderHostSpec() |
java.util.Set<java.lang.String> |
getSubscribedMethods() |
java.sql.Connection |
getWriterConnection()
Methods for testing purposes only.
|
HostSpec |
getWriterHostSpec() |
void |
initHostProvider(java.lang.String driverProtocol,
java.lang.String initialUrl,
java.util.Properties props,
HostListProviderService hostListProviderService,
JdbcCallable<java.lang.Void,java.sql.SQLException> initHostProviderFunc) |
protected abstract void |
initializeReaderConnection() |
protected abstract void |
initializeWriterConnection() |
protected boolean |
isConnectionUsable(java.sql.Connection connection) |
protected abstract boolean |
isReader(HostSpec currentHost) |
protected abstract boolean |
isWriter(HostSpec currentHost) |
protected void |
logAndThrowException(java.lang.String logMessage) |
protected void |
logAndThrowException(java.lang.String logMessage,
SqlState sqlState) |
OldConnectionSuggestedAction |
notifyConnectionChanged(java.util.EnumSet<NodeChangeOptions> changes) |
protected abstract void |
refreshAndStoreTopology(java.sql.Connection currentConnection) |
void |
releaseResources()
An object that implements this interface should release all acquired resources assuming it may
be disposed at any time.
|
protected void |
setReaderConnection(java.sql.Connection conn,
HostSpec host) |
protected void |
setWriterConnection(java.sql.Connection conn,
HostSpec host) |
protected abstract boolean |
shouldUpdateReaderConnection(java.sql.Connection currentConnection,
HostSpec currentHost) |
protected abstract boolean |
shouldUpdateWriterConnection(java.sql.Connection currentConnection,
HostSpec currentHost) |
void |
switchConnectionIfRequired(boolean readOnly) |
protected void |
switchCurrentConnectionTo(java.sql.Connection newConnection,
HostSpec newConnectionHost) |
acceptsStrategy, connect, forceConnect, getHostSpecByStrategy, getHostSpecByStrategy, getSnapshotState, notifyNodeListChangedprotected final PluginService pluginService
protected final java.util.Properties properties
protected volatile boolean inReadWriteSplit
protected HostListProviderService hostListProviderService
protected java.sql.Connection writerConnection
protected CacheItem<java.sql.Connection> readerCacheItem
protected HostSpec writerHostSpec
protected HostSpec readerHostSpec
protected boolean isReaderConnFromInternalPool
protected boolean isWriterConnFromInternalPool
public static final AwsWrapperProperty CACHED_READER_KEEP_ALIVE_TIMEOUT
public AbstractReadWriteSplittingPlugin(PluginService pluginService, java.util.Properties properties)
public java.util.Set<java.lang.String> getSubscribedMethods()
getSubscribedMethods in interface ConnectionPlugingetSubscribedMethods in class AbstractConnectionPluginpublic void initHostProvider(java.lang.String driverProtocol,
java.lang.String initialUrl,
java.util.Properties props,
HostListProviderService hostListProviderService,
JdbcCallable<java.lang.Void,java.sql.SQLException> initHostProviderFunc)
throws java.sql.SQLException
initHostProvider in interface ConnectionPlugininitHostProvider in class AbstractConnectionPluginjava.sql.SQLExceptionpublic OldConnectionSuggestedAction notifyConnectionChanged(java.util.EnumSet<NodeChangeOptions> changes)
notifyConnectionChanged in interface ConnectionPluginnotifyConnectionChanged in class AbstractConnectionPluginpublic <T,E extends java.lang.Exception> T execute(java.lang.Class<T> resultClass,
java.lang.Class<E> exceptionClass,
java.lang.Object methodInvokeOn,
java.lang.String methodName,
JdbcCallable<T,E> jdbcMethodFunc,
java.lang.Object[] args)
throws E extends java.lang.Exception
execute in interface ConnectionPluginexecute in class AbstractConnectionPluginE extends java.lang.Exceptionprotected void setWriterConnection(java.sql.Connection conn,
HostSpec host)
throws java.sql.SQLException
java.sql.SQLExceptionprotected void setReaderConnection(java.sql.Connection conn,
HostSpec host)
public void switchConnectionIfRequired(boolean readOnly)
throws java.sql.SQLException
java.sql.SQLExceptionprotected void logAndThrowException(java.lang.String logMessage)
throws java.sql.SQLException
java.sql.SQLExceptionprotected void logAndThrowException(java.lang.String logMessage,
SqlState sqlState)
throws java.sql.SQLException
java.sql.SQLExceptionprotected void switchCurrentConnectionTo(java.sql.Connection newConnection,
HostSpec newConnectionHost)
throws java.sql.SQLException
java.sql.SQLExceptionprotected boolean isConnectionUsable(java.sql.Connection connection)
throws java.sql.SQLException
java.sql.SQLExceptionprotected long getKeepAliveTimeout(boolean isPooledConnection)
public 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 void closeReaderConnectionIfIdle()
public void closeWriterConnectionIfIdle()
protected abstract boolean shouldUpdateReaderConnection(java.sql.Connection currentConnection,
HostSpec currentHost)
throws java.sql.SQLException
java.sql.SQLExceptionprotected abstract boolean shouldUpdateWriterConnection(java.sql.Connection currentConnection,
HostSpec currentHost)
throws java.sql.SQLException
java.sql.SQLExceptionprotected abstract boolean isWriter(HostSpec currentHost)
protected abstract boolean isReader(HostSpec currentHost)
protected abstract void refreshAndStoreTopology(java.sql.Connection currentConnection)
throws java.sql.SQLException
java.sql.SQLExceptionprotected abstract void initializeWriterConnection()
throws java.sql.SQLException
java.sql.SQLExceptionprotected abstract void initializeReaderConnection()
throws java.sql.SQLException
java.sql.SQLExceptionprotected abstract void closeReaderIfNecessary()
public java.sql.Connection getWriterConnection()
public java.sql.Connection getReaderConnection()
public HostSpec getReaderHostSpec()
public HostSpec getWriterHostSpec()