| Method from org.jboss.resource.connectionmanager.CachedConnectionManager Detail: |
public int getInUseConnections() {
synchronized (connectionStackTraces)
{
return connectionStackTraces.size();
}
}
|
public CachedConnectionManager getInstance() {
return this;
}
|
public TransactionManager getTransactionManager() {
return tm;
}
|
public boolean isDebug() {
return debug;
}
|
public boolean isError() {
return error;
}
|
public boolean isSpecCompliant() {
return specCompliant;
}
|
public Map listInUseConnections() {
synchronized (connectionStackTraces)
{
HashMap result = new HashMap();
for (Iterator i = connectionStackTraces.entrySet().iterator(); i.hasNext();)
{
Map.Entry entry = (Map.Entry) i.next();
Throwable stackTrace = (Throwable) entry.getValue();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
stackTrace.printStackTrace(ps);
result.put(entry.getKey().toString(), baos.toString());
}
return result;
}
}
|
KeyConnectionAssociation peekMetaAwareObject() {
LinkedList stack = (LinkedList) currentObjects.get();
if (stack == null)
return null;
if (!stack.isEmpty())
return (KeyConnectionAssociation) stack.getLast();
else
return null;
}
|
public void popMetaAwareObject(Set unsharableResources) throws ResourceException {
LinkedList stack = (LinkedList) currentObjects.get();
KeyConnectionAssociation oldKey = (KeyConnectionAssociation) stack.removeLast();
if (trace)
log.trace("popped object: " + Strings.defaultToString(oldKey));
if (specCompliant)
{
if (!stack.contains(oldKey))
{
disconnect(oldKey, unsharableResources);
} // end of if ()
}
else if (debug)
{
if (closeAll(oldKey.getCMToConnectionsMap()) && error)
throw new ResourceException("Some connections were not closed, see the log for the allocation stacktraces");
}
//At one time I attempted to recycle connections held over method calls.
//This caused problems if the other method call started a new transaction.
//To assure optimal use of connections, close them before calling out.
}
Describe popMetaAwareObject method here. |
public void pushMetaAwareObject(Object rawKey,
Set unsharableResources) throws ResourceException {
LinkedList stack = (LinkedList) currentObjects.get();
if (stack == null)
{
if (trace)
log.trace("new stack for key: " + Strings.defaultToString(rawKey));
stack = new LinkedList();
currentObjects.set(stack);
} // end of if ()
else
{
if (trace)
log.trace("old stack for key: " + Strings.defaultToString(rawKey));
//At one time I attempted to recycle connections held over method calls.
//This caused problems if the other method call started a new transaction.
//To assure optimal use of connections, close them before calling out.
} // end of else
//check for reentrancy, reconnect if not reentrant.
//wrap key to be based on == rather than equals
KeyConnectionAssociation key = new KeyConnectionAssociation(rawKey);
if (specCompliant && !stack.contains(key))
{
reconnect(key, unsharableResources);
}
stack.addLast(key);
}
Describe pushMetaAwareObject method here. |
void registerConnection(ConnectionCacheListener cm,
ConnectionListener cl,
Object connection,
ConnectionRequestInfo cri) {
if (debug)
{
synchronized (connectionStackTraces)
{
connectionStackTraces.put(connection, new Throwable("STACKTRACE"));
}
}
KeyConnectionAssociation key = peekMetaAwareObject();
if (trace)
log.trace("registering connection from " + cm + ", connection : " + connection + ", key: " + key);
if (key == null)
return; //not participating properly in this management scheme.
ConnectionRecord cr = new ConnectionRecord(cl, connection, cri);
Map cmToConnectionsMap = key.getCMToConnectionsMap();
Collection conns = (Collection) cmToConnectionsMap.get(cm);
if (conns == null)
{
conns = new ArrayList();
cmToConnectionsMap.put(cm, conns);
}
conns.add(cr);
}
|
public void setDebug(boolean value) {
this.debug = value;
}
|
public void setError(boolean value) {
this.error = value;
}
|
public void setSpecCompliant(boolean specCompliant) {
if (specCompliant)
log.warn("THE SpecCompliant ATTRIBUTE IS MISNAMED SEE http://jira.jboss.com/jira/browse/JBAS-1662");
this.specCompliant = specCompliant;
}
|
public void setTransactionManager(TransactionManager tm) {
this.tm = tm;
// FIXME we should be injecting onto the synchronizer directly
if (tm != null)
TransactionSynchronizer.setTransactionManager(tm);
}
|
void unregisterConnection(ConnectionCacheListener cm,
Object c) {
if (debug)
{
CloseConnectionSynchronization cas = getCloseConnectionSynchronization(false);
if (cas != null)
cas.remove(c);
synchronized (connectionStackTraces)
{
connectionStackTraces.remove(c);
}
}
KeyConnectionAssociation key = peekMetaAwareObject();
if (trace)
log.trace("unregistering connection from " + cm + ", object: " + c + ", key: " + key);
if (key == null)
return; //not participating properly in this management scheme.
Map cmToConnectionsMap = key.getCMToConnectionsMap();
Collection conns = (Collection) cmToConnectionsMap.get(cm);
if (conns == null)
return; // Can happen if connections are "passed" between contexts
for (Iterator i = conns.iterator(); i.hasNext();)
{
if (((ConnectionRecord) i.next()).connection == c)
{
i.remove();
return;
}
}
throw new IllegalStateException("Trying to return an unknown connection2! " + c);
}
|
void unregisterConnectionCacheListener(ConnectionCacheListener cm) {
if (trace)
log.trace("unregisterConnectionCacheListener: " + cm);
synchronized (objectToConnectionManagerMap)
{
for (Iterator i = objectToConnectionManagerMap.values().iterator(); i.hasNext();)
{
Map cmToConnectionsMap = (Map) i.next();
if (cmToConnectionsMap != null)
cmToConnectionsMap.remove(cm);
}
}
}
Describe unregisterConnectionCacheListener method here.
This is a shutdown method called by a connection manager. It will remove all reference
to that connection manager from the cache, so cached connections from that manager
will never be recoverable.
Possibly this method should not exist. |
public void userTransactionStarted() throws SystemException {
KeyConnectionAssociation key = peekMetaAwareObject();
if (trace)
log.trace("user tx started, key: " + key);
if (key == null)
return; //not participating properly in this management scheme.
Map cmToConnectionsMap = key.getCMToConnectionsMap();
Iterator cmToConnectionsMapIterator = cmToConnectionsMap.entrySet().iterator();
while (cmToConnectionsMapIterator.hasNext())
{
Map.Entry cmToConnectionsMapEntry = (Map.Entry)cmToConnectionsMapIterator.next();
ConnectionCacheListener cm = (ConnectionCacheListener) cmToConnectionsMapEntry.getKey();
Collection conns = (Collection) cmToConnectionsMapEntry.getValue();
cm.transactionStarted(conns);
}
}
|