public class DefaultConnectionManager extends Thread implements ConnectionManager
Although this manager implements a strict 1:1 mapping between dbs and connections
it can be easily extended to implememt a M:N mapping, see the MpxConnectionManager.
Thread.State, Thread.UncaughtExceptionHandler| Modifier and Type | Field and Description |
|---|---|
protected ManagedConnection[] |
conList
managed connections.
|
protected int |
dbSize
current allocation size for
Dbs logged in. |
protected int |
freeConCount
number of entries in freeConList.
|
protected int[] |
freeConList
free list for conList (unused entries in conList).
|
protected int |
freeDbCount
number of entries in freeDbList.
|
protected int[] |
freeDbList
free list for dbList (unused entries in dbList).
|
protected int |
idOffset
offset for connection IDs.
|
protected int |
iniSize
initial size.
|
protected int |
maxConSize
maximum number of connections, 0 = unlimited.
|
protected int |
maxDbSize
maximum number of
Dbs, 0 = unlimited. |
protected String |
name
name of the connection manager.
|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY| Constructor and Description |
|---|
DefaultConnectionManager()
Creates a connection manager.
|
DefaultConnectionManager(String name,
int iniSize,
int maxSize,
int idOffset)
Creates a new connection manager.
|
| Modifier and Type | Method and Description |
|---|---|
protected int |
addConnection(ManagedConnection con)
Adds a connection to the list.
|
protected int |
addDb(Db db)
Adds a Db to the list.
|
protected void |
assertSessionBelongsToMe(Session session)
Asserts that the session belongs to this manager.
|
void |
attach(Session session)
Attaches a
Db to a connection.A Db must be attached before it can use any statements. |
protected int |
convertConnectionIdToIndex(int id)
Converts the connection id to the internal Db-array index.
|
void |
detach(Session session)
Detaches a connection from a
Db.A Db must be detached to release the connection for use of other Db instances. |
void |
forceDetach(Session session)
Detaches but also scans for pending statements to cleanup.
|
long |
getAttachTimeout()
Gets the attach timeout.
|
int |
getConnectionCount()
Gets the number of established connections
|
Collection<ManagedConnection> |
getConnections()
Gets the connections.
|
int |
getMaxConnections()
Gets the maximum number of connections.
|
int |
getMaxCountForClearWarnings()
Gets the current setting for clearWarnings() trigger
|
int |
getMaxSessions() |
int |
getNumConnections()
Gets the number of open connections.
|
int |
getNumSessions() |
int |
login(Session session) |
void |
logout(Session session) |
protected ManagedConnection |
removeConnection(int index)
Removes a connection from the list.
|
protected void |
removeDb(int index)
Removes a Db from the list.
|
void |
run() |
void |
setAttachTimeout(long attachTimeout)
Sets the attach timeout.
|
void |
setMaxCountForClearWarnings(int maxCountForClearWarnings)
Sets the countForClearWarnings trigger, 0 = app must eat the warnings!
|
void |
shutdown() |
String |
toString()
Gets the name of the manager.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, yieldequals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetNameprotected final String name
protected final int iniSize
protected final int idOffset
protected int dbSize
Dbs logged in.protected int maxDbSize
Dbs, 0 = unlimited.protected int[] freeDbList
protected int freeDbCount
protected ManagedConnection[] conList
protected final int maxConSize
protected int[] freeConList
protected int freeConCount
public DefaultConnectionManager(String name, int iniSize, int maxSize, int idOffset)
name - the name of the connection manageriniSize - the initial iniSize of the db tablemaxSize - the maximum number of connections, 0 = unlimited (dangerous!)idOffset - the offset for connection ids (> 0)public DefaultConnectionManager()
With an initial size of 2, a maximum of 8 concurrent connections and an id offset of 1. This is the default connection manager for 2-tier client applications. The max connections will prevent ill behaving applications from tearing down the dbserver by opening connections excessively. The usual application holds 2 connections and temporarily 1 or 2 more. If you need more, change the connection manager in Db.
public void setMaxCountForClearWarnings(int maxCountForClearWarnings)
maxCountForClearWarnings - the maxcountpublic int getMaxCountForClearWarnings()
public long getAttachTimeout()
public void setAttachTimeout(long attachTimeout)
attachTimeout - the max. attach time, 0 if check is disabled (default)protected int addDb(Db db)
db - the db to addprotected void removeDb(int index)
index - the index of db in the dblistprotected int addConnection(ManagedConnection con)
con - the connection to addprotected ManagedConnection removeConnection(int index)
index - the index of connection in the conlistpublic int getConnectionCount()
public int getMaxSessions()
getMaxSessions in interface SessionManagerpublic int getNumSessions()
getNumSessions in interface SessionManagerpublic int getMaxConnections()
ConnectionManagergetMaxConnections in interface ConnectionManagerpublic int getNumConnections()
ConnectionManagergetNumConnections in interface ConnectionManagerpublic Collection<ManagedConnection> getConnections()
ConnectionManagergetConnections in interface ConnectionManagerpublic int login(Session session)
login in interface SessionManagerpublic void logout(Session session)
logout in interface SessionManagerpublic void attach(Session session)
ConnectionManagerDb to a connection.Upon return the the session will reference the connection.
attach in interface ConnectionManagersession - the sessionpublic void detach(Session session)
ConnectionManagerDb.detach in interface ConnectionManagersession - the sessionpublic void forceDetach(Session session)
ConnectionManagerThis will detach at any nesting level!
forceDetach in interface ConnectionManagersession - the sessionpublic void shutdown()
shutdown in interface SessionManagerprotected int convertConnectionIdToIndex(int id)
id - the connection id (> 0)protected void assertSessionBelongsToMe(Session session)
session - the sessionCopyright © 2016 Krake Softwaretechnik. All rights reserved.