public class ProxoolFacade extends Object
This provides some nice-to-have features that can't be provided by the
Driver implementation of java.sql.Driver. Like starting up
a pool before you need a connection. And getting statistical information.
You need to use this class wisely. It is obviously specfic to proxool so it will stop you switching to another driver. Consider isolating the code that calls this class so that you can easily remove it if you have to.
| 构造器和说明 |
|---|
ProxoolFacade() |
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
addConfigurationListener(String alias,
ConfigurationListenerIF configurationListener)
Adds a listener that gets called everytime the configuration changes.
|
static void |
addConnectionListener(String alias,
ConnectionListenerIF connectionListener)
Add a listener that monitors each time a connection is made or destroyed.
|
static void |
addProxoolListener(ProxoolListenerIF proxoolListener)
Add a listener that gets called everytime a global Proxool event ocours.
|
static void |
addStateListener(String alias,
StateListenerIF stateListener)
Add a listener that monitors the change of state of the pool (quiet, busy, overloaded, or down)
|
static void |
addStatisticsListener(String alias,
StatisticsListenerIF statisticsListener)
Add a listener that receives statistics as they are produced
|
protected static void |
definitionUpdated(String alias,
ConnectionPoolDefinitionIF connectionPoolDefinition,
Properties completeInfo,
Properties changedInfo)
Broadcast a configuration change
|
static void |
disableShutdownHook()
If you call this then you'll have to call shutdown explicitly
|
static void |
enableShutdownHook()
Call this if you change your mind about
disabling it. |
protected void |
finalize() |
static String |
getAlias(Connection connection)
Get the alias for the connection pool that served a connection
|
protected static String |
getAlias(String url)
Extracts the pool alias from the url:
proxool.alias:driver:url -> alias
proxool.alias -> alias
|
static String[] |
getAliases()
Get a list of all the registered pools
|
static Collection |
getConnectionInfos(String alias)
已过时。
use
snapshot instead. |
static ConnectionPoolDefinitionIF |
getConnectionPoolDefinition(String alias)
Get the definition of a pool.
|
static ConnectionPoolStatisticsIF |
getConnectionPoolStatistics(String alias)
|
static String |
getConnectionPoolStatisticsDump(String alias)
|
static Connection |
getDelegateConnection(Connection connection)
已过时。
Just cast the connection that you are given into the driver specific one.
|
static Statement |
getDelegateStatement(Statement statement)
已过时。
Just cast the statement that you are given into the driver specific one.
|
static long |
getId(Connection connection)
Get the connection ID for a connection
|
static SnapshotIF |
getSnapshot(String alias)
Calls
getSnapshot
using false for the detail parameter. |
static SnapshotIF |
getSnapshot(String alias,
boolean detail)
Gives a snapshot of what the pool is doing
|
static StatisticsIF[] |
getStatistics(String alias)
Get all the lastest performance statistics for this pool
|
static StatisticsIF |
getStatistics(String alias,
String token)
Get a particular set of performance statistics for this pool
|
static boolean |
isShutdownHookEnabled()
Whether the
ShutdownHook should do anything. |
static void |
killAllConnections(String alias)
已过时。
use
alternative
to provide better auditing in log |
static void |
killAllConnections(String alias,
boolean merciful)
已过时。
use
alternative
to provide better auditing in log |
static void |
killAllConnections(String alias,
String reason)
Like
killAllConnections(java.lang.String, boolean) but defaults to merciful. |
static void |
killAllConnections(String alias,
String reason,
boolean merciful)
Kill all connections in a pool.
|
static boolean |
killConnecton(Connection connection,
boolean merciful)
Kill a single connection
|
static boolean |
killConnecton(String alias,
long id,
boolean merciful)
Kill a single connection
|
static void |
redefineConnectionPool(String url,
Properties info)
Redefine the behaviour of the pool.
|
protected static void |
registerConnectionPool(org.logicalcobwebs.proxool.ConnectionPoolDefinition connectionPoolDefinition) |
static void |
registerConnectionPool(String url)
With no configurator or properties (using default values)
|
static String |
registerConnectionPool(String url,
Properties info)
Build a ConnectionPool based on this definition and then start it.
|
protected static String |
registerConnectionPool(String url,
Properties info,
boolean explicitRegister)
Build a ConnectionPool based on this definition and then start it.
|
static void |
removeAllConnectionPools(int delay)
已过时。
use the better named
shutdown() instead. |
static boolean |
removeConfigurationListener(String alias,
ConfigurationListenerIF configurationListener)
Remove a listener that gets called everytime the configuration changes.
|
static boolean |
removeConnectionListener(String alias,
ConnectionListenerIF connectionListener)
Remove a listener that monitors each time a connection is made or destroyed.
|
static void |
removeConnectionPool(String alias)
Like
removeConnectionPool(java.lang.String, int) but uses no delay. |
static void |
removeConnectionPool(String alias,
int delay)
Remove a connection pool.
|
static boolean |
removeProxoolListener(ProxoolListenerIF proxoolListener)
Remove a registered
ProxoolListenerIF. |
static boolean |
removeStateListener(String alias,
StateListenerIF stateListener)
Remove a listener that monitors the change of state of the pool (quiet, busy, overloaded, or down)
|
static void |
setConfigurationListener(String alias,
ConfigurationListenerIF configurationListener)
已过时。
|
static void |
setConnectionListener(String alias,
ConnectionListenerIF connectionListener)
已过时。
use
addConnectionListener(String, ConnectionListenerIF) instead. |
protected static void |
setShutdownHook(Thread t)
By remembering the most recent
ShutdownHook ProxoolFacade
will know to disable it when it is shutdown(). |
static void |
setStateListener(String alias,
StateListenerIF stateListener)
已过时。
use
addStateListener(String, StateListenerIF) instead. |
static void |
shutdown()
Removes all connection pools.
|
static void |
shutdown(int delay)
Removes all connection pools.
|
protected static void |
shutdown(String finalizer,
int delay)
Removes all connection pools.
|
static void |
updateConnectionPool(String url,
Properties info)
Update the behaviour of the pool.
|
public static String registerConnectionPool(String url, Properties info) throws ProxoolException
url - defines the delegate driver and delegate url.info - the properties used to configure Proxool (and any for the delegate driver too) - optionalProxoolException - if anything goes wrongprotected static String registerConnectionPool(String url, Properties info, boolean explicitRegister) throws ProxoolException
url - defines the delegate driver and delegate url.info - the properties used to configure Proxool (and any for the delegate driver too) - optionalexplicitRegister - set to true if we are registering a new pool explicitly, or false
if it's just because we are serving a url that we haven't come across beforeProxoolException - if anything goes wrongprotected static void registerConnectionPool(org.logicalcobwebs.proxool.ConnectionPoolDefinition connectionPoolDefinition)
throws ProxoolException
ProxoolExceptionpublic static void registerConnectionPool(String url) throws ProxoolException
protected static String getAlias(String url) throws ProxoolException
ProxoolException - if we couldn't find the aliaspublic static void removeConnectionPool(String alias, int delay) throws ProxoolException
alias - the pool to removedelay - the time to wait for connections to become inactive before killing it (milliseconds)ProxoolException - if we couldn't find the poolpublic static void removeAllConnectionPools(int delay)
shutdown() instead.delay - the time to wait for connections to become inactive before killing it (milliseconds)public static void shutdown()
shutdown(java.lang.String, int) but passes the current thread name
and a delay of zero.public static void shutdown(int delay)
shutdown(java.lang.String, int) but passes the current thread name.delay - the time to wait for connections to become inactive before killing it (milliseconds)protected static void shutdown(String finalizer, int delay)
finalizer - used to identify who is causing the pools to be removed (helps logging)delay - the time to wait for connections to become inactive before killing it (milliseconds)public static void disableShutdownHook()
shutdown(String, int)public static void enableShutdownHook()
disabling it.
The default behaviour is to have it enabled so unless you have disabled it then
there's nothing to do.public static boolean isShutdownHookEnabled()
ShutdownHook should do anything.disableShutdownHook(),
enableShutdownHook()public static void removeConnectionPool(String alias) throws ProxoolException
removeConnectionPool(java.lang.String, int) but uses no delay. (Kills
everything as quickly as possible).alias - to identify the poolProxoolException - if we couldn't find the poolpublic static ConnectionPoolStatisticsIF getConnectionPoolStatistics(String alias) throws ProxoolException
alias - to identify the poolProxoolException - if we couldn't find the poolpublic static String getConnectionPoolStatisticsDump(String alias) throws ProxoolException
alias - to identify the poolProxoolException - if we couldn't find the poolpublic static ConnectionPoolDefinitionIF getConnectionPoolDefinition(String alias) throws ProxoolException
alias - identifies the poolProxoolException - if we couldn't find the poolpublic static Collection getConnectionInfos(String alias) throws ProxoolException
snapshot instead.alias - identifies the poolConnectionInfoIFsProxoolException - if we couldn't find the poolpublic static void killAllConnections(String alias, boolean merciful) throws ProxoolException
alternative
to provide better auditing in logalias - the pool containing the connectionmerciful - if true will only kill connections that aren't activeProxoolException - if we couldn't find the poolpublic static void killAllConnections(String alias, String reason, boolean merciful) throws ProxoolException
alias - the pool containing the connectionreason - provides audit in log of why connections were killedmerciful - if true will only kill connections that aren't activeProxoolException - if we couldn't find the poolpublic static void killAllConnections(String alias) throws ProxoolException
alternative
to provide better auditing in logkillAllConnections(java.lang.String, boolean) but defaults to merciful.alias - to identify the poolProxoolException - if we couldn't find the poolpublic static void killAllConnections(String alias, String reason) throws ProxoolException
killAllConnections(java.lang.String, boolean) but defaults to merciful.alias - to identify the poolreason - provides audit in log of why connections were killedProxoolException - if we couldn't find the poolpublic static boolean killConnecton(String alias, long id, boolean merciful) throws ProxoolException
alias - the pool containing the connectionid - the id of the specific connectionmerciful - if true will only kill connections that aren't activeProxoolException - if we couldn't find the poolpublic static boolean killConnecton(Connection connection, boolean merciful) throws ProxoolException
connection - the connection to killmerciful - if true will only kill connections that aren't activeProxoolException - if we didn't recognise the connectionpublic static void addProxoolListener(ProxoolListenerIF proxoolListener)
proxoolListener - the listener to add.public static boolean removeProxoolListener(ProxoolListenerIF proxoolListener)
ProxoolListenerIF.proxoolListener - the listener to remove.public static void setStateListener(String alias, StateListenerIF stateListener) throws ProxoolException
addStateListener(String, StateListenerIF) instead.ProxoolExceptionpublic static void addStateListener(String alias, StateListenerIF stateListener) throws ProxoolException
alias - identifies the poolstateListener - the new listenerProxoolException - if we couldn't find the poolpublic static boolean removeStateListener(String alias, StateListenerIF stateListener) throws ProxoolException
alias - identifies the poolstateListener - the listener to be removed.ProxoolException - if we couldn't find the poolpublic static void setConnectionListener(String alias, ConnectionListenerIF connectionListener) throws ProxoolException
addConnectionListener(String, ConnectionListenerIF) instead.ProxoolExceptionpublic static void addConnectionListener(String alias, ConnectionListenerIF connectionListener) throws ProxoolException
alias - identifies the poolconnectionListener - the new listenerProxoolException - if we couldn't find the poolpublic static boolean removeConnectionListener(String alias, ConnectionListenerIF connectionListener) throws ProxoolException
alias - identifies the poolconnectionListener - the listener to be removedProxoolException - if we couldn't find the poolpublic static void setConfigurationListener(String alias, ConfigurationListenerIF configurationListener) throws ProxoolException
addConfigurationListener(String, ConfigurationListenerIF) instead.ProxoolExceptionpublic static void addConfigurationListener(String alias, ConfigurationListenerIF configurationListener) throws ProxoolException
alias - identifies the poolconfigurationListener - the new listenerProxoolException - if we couldn't find the poolprotected static void definitionUpdated(String alias, ConnectionPoolDefinitionIF connectionPoolDefinition, Properties completeInfo, Properties changedInfo)
alias - identifies the poolconnectionPoolDefinition - the definitioncompleteInfo - all propertieschangedInfo - only changed properties (since the last
time this method was called)public static boolean removeConfigurationListener(String alias, ConfigurationListenerIF configurationListener) throws ProxoolException
alias - identifies the pool.configurationListener - the listener to be removed.ProxoolException - if we couldn't find the poolpublic static void redefineConnectionPool(String url, Properties info) throws ProxoolException
url - the url that defines the pool (or the abbreviated ""proxool.alias")info - the new propertiesProxoolExceptionupdateConnectionPool(java.lang.String, java.util.Properties)public static void updateConnectionPool(String url, Properties info) throws ProxoolException
url - the url that defines the pool (or the abbreviated ""proxool.alias")info - the new propertiesProxoolExceptionredefineConnectionPool(java.lang.String, java.util.Properties)public static Statement getDelegateStatement(Statement statement) throws ProxoolException
ProxoolExceptionpublic static Connection getDelegateConnection(Connection connection) throws ProxoolException
ProxoolExceptionpublic static long getId(Connection connection) throws ProxoolException
connection - the connection that was servedProxoolException - if the connection wasn't recognised.public static String getAlias(Connection connection) throws ProxoolException
connection - the connection that was servedProxoolException - if the connection wasn't recognised.public static String[] getAliases()
public static StatisticsIF getStatistics(String alias, String token) throws ProxoolException
alias - identifies the pooltoken - identifies which set, as defined in the configuration (see definition)ProxoolException - if we couldn't find the poolpublic static StatisticsIF[] getStatistics(String alias) throws ProxoolException
alias - identifies the poolProxoolException - if we couldn't find the poolpublic static void addStatisticsListener(String alias, StatisticsListenerIF statisticsListener) throws ProxoolException
statisticsListener - the new listenerProxoolException - if the pool couldn't be foundpublic static SnapshotIF getSnapshot(String alias, boolean detail) throws ProxoolException
alias - identifies the pooldetail - if true then include detail of each connection. Note it you ask for
detail then the pool must necessarily be locked for the duration it takes to gather
the information (which isn't very long). You probably shouldn't do it that often (like
not every second or something). Being locked means that connections cannot be
served or returned (it doesn't mean that they can't be active).ProxoolException - if we couldn't find the poolpublic static SnapshotIF getSnapshot(String alias) throws ProxoolException
getSnapshot
using false for the detail parameter.protected static void setShutdownHook(Thread t)
ShutdownHook ProxoolFacade
will know to disable it when it is shutdown(). It will gracefully
cope with the fact that it may be shutting down by the request of the
sutdownHook. If you don't do this and do several "hot deploys" then you
end up with a series of shutdown hooks. We only every want one.t - the thread that will be run as a shutdown hookShutdownHookCopyright © 2024. All rights reserved.