/** * Releases any managed connections held by a garbage collected connection proxy. * @param connectionInfo the connection to be obtained * @param key the unique id of the connection manager */ public void setEnvironment(ConnectionInfo connectionInfo, String key) { ProxyPhantomReference reference = (ProxyPhantomReference) referenceQueue.poll(); while (reference != null) { reference.clear(); references.remove(reference.managedConnectionInfo); ConnectionInfo released = new ConnectionInfo(reference.managedConnectionInfo); reference.interceptor.returnConnection(released, ConnectionReturnAction.DESTROY); reference = (ProxyPhantomReference) referenceQueue.poll(); } }
private void associateConnections(ConnectorInstanceContext context) throws ResourceException { Map<ConnectionTrackingInterceptor, Set<ConnectionInfo>> connectionManagerToManagedConnectionInfoMap = context.getConnectionManagerMap(); for (Map.Entry<ConnectionTrackingInterceptor, Set<ConnectionInfo>> entry : connectionManagerToManagedConnectionInfoMap.entrySet()) { ConnectionTrackingInterceptor mcci = entry.getKey(); Set<ConnectionInfo> connections = entry.getValue(); mcci.enter(connections); } }
public synchronized Object getHandle() { if (connectionTrackingInterceptor == null) { // connection has been closed... send invocations directly to the handle // which will throw an exception or in some clases like JDBC connection.close() // ignore the invocation return handle; } if (released) { try { connectionTrackingInterceptor.reassociateConnection(connectionInfo); } catch (ResourceException e) { throw (IllegalStateException) new IllegalStateException("Could not obtain a physical connection").initCause(e); } released = false; } return handle; } }
public void exit(ConnectorInstanceContext oldContext) throws ResourceException { ConnectorInstanceContext currentContext = currentInstanceContexts.get(); try { // for each connection type opened in this componet Map<ConnectionTrackingInterceptor, Set<ConnectionInfo>> resources = currentContext.getConnectionManagerMap(); for (Iterator<Map.Entry<ConnectionTrackingInterceptor, Set<ConnectionInfo>>> iterator = resources.entrySet().iterator(); iterator.hasNext();) { Map.Entry<ConnectionTrackingInterceptor, Set<ConnectionInfo>> entry = iterator.next(); ConnectionTrackingInterceptor mcci = entry.getKey(); Set<ConnectionInfo> connections = entry.getValue(); // release proxy connections if (lazyConnect) { for (ConnectionInfo connectionInfo : connections) { releaseProxyConnection(connectionInfo); } } // use connection interceptor to dissociate connections that support disassociation mcci.exit(connections); // if no connection remain clear context... we could support automatic commit, rollback or exception here if (connections.isEmpty()) { iterator.remove(); } } } finally { // when lazy we do not need or want to track open connections... they will automatically reconnect if (lazyConnect) { currentContext.getConnectionManagerMap().clear(); } currentInstanceContexts.set(oldContext); } }
stack = new TCCLInterceptor(stack, classLoader); if (connectionTracker != null) { stack = new ConnectionTrackingInterceptor(stack, name, connectionTracker);
/** * Releases any managed connections held by a garbage collected connection proxy. * * @param connectionInfo the connection to be obtained * @param key the unique id of the connection manager */ public void setEnvironment(final ConnectionInfo connectionInfo, final String key) { ProxyPhantomReference reference = (ProxyPhantomReference) referenceQueue.poll(); while (reference != null) { reference.clear(); references.remove(reference.managedConnectionInfo); final ConnectionInfo released = new ConnectionInfo(reference.managedConnectionInfo); reference.interceptor.returnConnection(released, ConnectionReturnAction.DESTROY); reference = (ProxyPhantomReference) referenceQueue.poll(); } }
/** * Releases any managed connections held by a garbage collected connection proxy. * * @param connectionInfo the connection to be obtained * @param key the unique id of the connection manager */ public void setEnvironment(final ConnectionInfo connectionInfo, final String key) { ProxyPhantomReference reference = (ProxyPhantomReference) referenceQueue.poll(); while (reference != null) { reference.clear(); references.remove(reference.managedConnectionInfo); final ConnectionInfo released = new ConnectionInfo(reference.managedConnectionInfo); reference.interceptor.returnConnection(released, ConnectionReturnAction.DESTROY); reference = (ProxyPhantomReference) referenceQueue.poll(); } }
public void exit(Collection<ConnectionInfo> connectionInfos) throws ResourceException { for (Iterator<ConnectionInfo> iterator = connectionInfos.iterator(); iterator.hasNext();) { ConnectionInfo connectionInfo = iterator.next(); if (connectionInfo.isUnshareable()) { //if one is, they all are return; } ManagedConnectionInfo managedConnectionInfo = connectionInfo.getManagedConnectionInfo(); ManagedConnection managedConnection = managedConnectionInfo.getManagedConnection(); if (managedConnection instanceof DissociatableManagedConnection && managedConnectionInfo.isFirstConnectionInfo(connectionInfo)) { iterator.remove(); ((DissociatableManagedConnection) managedConnection).dissociateConnections(); managedConnectionInfo.clearConnectionHandles(); //todo this needs some kind of check so cx isn't returned more than once //in case dissociate calls connection closed event and returns cx to pool. returnConnection(connectionInfo, ConnectionReturnAction.RETURN_HANDLE); } } }