use of javax.resource.spi.ManagedConnection in project geode by apache.
the class FacetsJCAConnectionManagerImpl method afterCompletion.
/*
* (non-Javadoc)
*
* @see javax.transaction.Synchronization#afterCompletion(int)
*/
public void afterCompletion(int arg0) {
// DELIST THE XARESOURCE FROM THE LIST. RETURN ALL THE CONNECTIONS TO THE
// POOL.
java.util.List lsConn = (ArrayList) xalistThreadLocal.get();
Iterator itr = lsConn.iterator();
while (itr.hasNext()) {
ManagedConnection conn = (ManagedConnection) itr.next();
mannPoolCache.returnPooledConnectionToPool(conn);
}
lsConn.clear();
// return all the connections to pool.
}
use of javax.resource.spi.ManagedConnection in project geode by apache.
the class FacetsJCAConnectionManagerImpl method connectionErrorOccurred.
/**
* CallBack for Connection Error.
*
* @param event ConnectionEvent
*/
public void connectionErrorOccurred(ConnectionEvent event) {
if (isActive) {
// If its an XAConnection
ManagedConnection conn = (ManagedConnection) event.getSource();
// XAResource xar = (XAResource) xaResourcesMap.get(conn);
((List) xalistThreadLocal.get()).remove(conn);
TransactionManagerImpl transManager = TransactionManagerImpl.getTransactionManager();
try {
Transaction txn = transManager.getTransaction();
if (txn == null) {
mannPoolCache.returnPooledConnectionToPool(conn);
} else {
// do nothing.
}
} catch (Exception se) {
se.printStackTrace();
}
try {
mannPoolCache.expirePooledConnection(conn);
// mannPoolCache.destroyPooledConnection(conn);
} catch (Exception ex) {
String exception = "FacetsJCAConnectionManagerImpl::connectionErrorOccurred: Exception occurred due to " + ex.getMessage();
if (logger.isDebugEnabled()) {
logger.debug(exception, ex);
}
}
}
}
use of javax.resource.spi.ManagedConnection in project geode by apache.
the class JCAConnectionManagerImpl method allocateConnection.
/*
* allocates a ManagedConnection from the ConnectionPool or creates a new
* ManagedConnection. @param javax.resource.spi.ManagedConnectionFactory
*
* @param javax.resource.spi.ConnectionRequestInfo
*
* @throws ResourceException
*/
public Object allocateConnection(ManagedConnectionFactory mcf, ConnectionRequestInfo reqInfo) throws ResourceException {
if (!isActive) {
throw new ResourceException(LocalizedStrings.JCAConnectionManagerImpl_JCACONNECTIONMANAGERIMPLALLOCATECONNECTIONNO_VALID_CONNECTION_AVAILABLE.toLocalizedString());
}
ManagedConnection conn = null;
try {
conn = (ManagedConnection) mannPoolCache.getPooledConnectionFromPool();
} catch (PoolException ex) {
// ex.printStackTrace();
throw new ResourceException(LocalizedStrings.JCAConnectionManagerImpl_JCACONNECTIONMANAGERIMPL_ALLOCATECONNECTION_IN_GETTING_CONNECTION_FROM_POOL_DUE_TO_0.toLocalizedString(ex.getMessage()), ex);
}
// Transaction Manager.
try {
synchronized (this) {
if (transManager == null) {
transManager = JNDIInvoker.getTransactionManager();
}
}
Transaction txn = transManager.getTransaction();
if (txn != null) {
// Check if Data Source provides XATransaction
// if(configs.getTransactionType = "XATransaction")
XAResource xar = conn.getXAResource();
txn.enlistResource(xar);
// Asif :Add in the Map after successful registration of XAResource
xaResourcesMap.put(conn, xar);
// else throw a resource exception
}
} catch (RollbackException ex) {
throw new ResourceException(LocalizedStrings.JCAConnectionManagerImpl_JCACONNECTIONMANAGERIMPL_ALLOCATECONNECTION_IN_TRANSACTION_DUE_TO_0.toLocalizedString(ex.getMessage()), ex);
} catch (SystemException ex) {
throw new ResourceException(LocalizedStrings.JCAConnectionManagerImpl_JCACONNECTIONMANAGERIMPL_ALLOCATECONNECTION_SYSTEM_EXCEPTION_DUE_TO_0.toLocalizedString(ex.getMessage()), ex);
}
return conn.getConnection(subject, reqInfo);
}
use of javax.resource.spi.ManagedConnection in project geode by apache.
the class ManagedPoolCacheImpl method getNewPoolConnection.
/**
* Creates a new connection for the managed connection pool.
*
* @return the managed connection from the EIS as ManagedConnection object.
* @throws PoolException
*/
@Override
public Object getNewPoolConnection() throws PoolException {
ManagedConnection manConn = null;
try {
manConn = connFactory.createManagedConnection(sub, connReqInfo);
} catch (ResourceException rex) {
rex.printStackTrace();
throw new PoolException(LocalizedStrings.ManagedPoolCacheImpl_MANAGEDPOOLCACHEIMPLGETNEWCONNECTION_EXCEPTION_IN_CREATING_NEW_MANAGED_POOLEDCONNECTION.toLocalizedString(), rex);
}
manConn.addConnectionEventListener((javax.resource.spi.ConnectionEventListener) connEventListner);
return manConn;
}
use of javax.resource.spi.ManagedConnection in project tomee by apache.
the class SampleManagedConnectionFactory method matchManagedConnections.
public ManagedConnection matchManagedConnections(Set connectionSet, Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException {
log.finest("matchManagedConnections()");
ManagedConnection result = null;
Iterator it = connectionSet.iterator();
while (result == null && it.hasNext()) {
ManagedConnection mc = (ManagedConnection) it.next();
if (mc instanceof SampleManagedConnection) {
result = mc;
}
}
return result;
}
Aggregations