javax.resource.spi.ConnectionEvent Java Examples

The following examples show how to use javax.resource.spi.ConnectionEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JCAManagedConnection.java    From gemfirexd-oss with Apache License 2.0 7 votes vote down vote up
public void onClose(GFConnectionImpl conn) throws ResourceException
{
  conn.invalidate();
  this.connections.remove(conn);
  synchronized (this.listeners) {
    Iterator<ConnectionEventListener> itr = this.listeners.iterator();
    ConnectionEvent ce = new ConnectionEvent(this,
        ConnectionEvent.CONNECTION_CLOSED);
    ce.setConnectionHandle(conn);
    while (itr.hasNext()) {
      itr.next().connectionClosed(ce);
    }
  }
  if (this.connections.isEmpty()) {
    // safe to dissociate this managedconnection so that it can go to pool
    if (this.initDone && !this.cache.isClosed()) {
      this.localTran = new JCALocalTransaction(this.cache, this.gfTxMgr);
    }
    else {
      this.localTran = new JCALocalTransaction();
    }
  }

}
 
Example #2
Source File: AbstractManagedConnectionImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void sendEventToListener(ConnectionEvent coEvent, ConnectionEventListener listener) {
    if (coEvent.getId() == ConnectionEvent.CONNECTION_CLOSED) {
        listener.connectionClosed(coEvent);
        LOG.log(Level.FINE, "CONNECTION_CLOSED_EVENT_FIRED", new Object[] {listener});
    }

    if (coEvent.getId() == ConnectionEvent.LOCAL_TRANSACTION_COMMITTED) {
        listener.localTransactionCommitted(coEvent);
        LOG.log(Level.FINE, "LOCAL_TX_COMMITTED_EVENT_FIRED", new Object[] {listener});
    }

    if (coEvent.getId() == ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK) {
        listener.localTransactionRolledback(coEvent);
        LOG.log(Level.FINE, "LOCAL_TX_ROLLEDBACK_EVENT_FIRED", new Object[] {listener});
    }

    if (coEvent.getId() == ConnectionEvent.LOCAL_TRANSACTION_STARTED) {
        listener.localTransactionStarted(coEvent);
        LOG.log(Level.FINE, "LOCAL_TX_STARTED_EVENT_FIRED", new Object[] {listener});
    }

    if (coEvent.getId() == ConnectionEvent.CONNECTION_ERROR_OCCURRED) {
        listener.connectionErrorOccurred(coEvent);
        LOG.log(Level.FINE, "CTX_ERROR_OCURRED_EVENT_FIRED", new Object[] {listener});
    }
}
 
Example #3
Source File: PerfManagedConnection.java    From ironjacamar with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void rollback() throws ResourceException
{
   if (txCommitDuration > 0)
   {
      try
      {
         Thread.sleep(txCommitDuration);
      }
      catch (Exception e)
      {
         // Ignore
      }
   }

   ConnectionEvent ce = new ConnectionEvent(this, ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK);
   
   for (ConnectionEventListener cel : listeners)
   {
      cel.localTransactionRolledback(ce);
   }
}
 
Example #4
Source File: NoTxConnectionListener.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void connectionClosed(ConnectionEvent ce)
{
   if (getCachedConnectionManager() != null)
   {
      try
      {
         getCachedConnectionManager().unregisterConnection(getConnectionManager(), this, ce.getConnectionHandle());
      }
      catch (Throwable t)
      {
         log.debug("Throwable from unregisterConnection", t);
      }
   }

   getConnectionManager().unregisterAssociation(this, ce.getConnectionHandle());
   
   if (isManagedConnectionFree())
   {
      getConnectionManager().returnManagedConnection(this, false);
   }
}
 
Example #5
Source File: PerfManagedConnection.java    From ironjacamar with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void commit() throws ResourceException
{
   if (txCommitDuration > 0)
   {
      try
      {
         Thread.sleep(txCommitDuration);
      }
      catch (Exception e)
      {
         // Ignore
      }
   }

   ConnectionEvent ce = new ConnectionEvent(this, ConnectionEvent.LOCAL_TRANSACTION_COMMITTED);
   
   for (ConnectionEventListener cel : listeners)
   {
      cel.localTransactionCommitted(ce);
   }
}
 
Example #6
Source File: FacetsJCAConnectionManagerImpl.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Callback for Connection Closed.
 * 
 * @param event ConnectionEvent Object.
 */
public void connectionClosed(ConnectionEvent event) {
  if (isActive) {
    ManagedConnection conn = (ManagedConnection) event.getSource();
    TransactionManagerImpl transManager = TransactionManagerImpl
        .getTransactionManager();
    try {
      Transaction txn = transManager.getTransaction();
      if (txn == null) {
        mannPoolCache.returnPooledConnectionToPool(conn);
      }
    }
    catch (Exception se) {
      String exception = "FacetsJCAConnectionManagerImpl::connectionClosed: Exception occured due to "
          + se;
      LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
      if (writer.fineEnabled()) writer.fine(exception, se);
    }
  }
}
 
Example #7
Source File: PerfManagedConnection.java    From ironjacamar with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void begin() throws ResourceException
{
   if (txBeginDuration > 0)
   {
      try
      {
         Thread.sleep(txBeginDuration);
      }
      catch (Exception e)
      {
         // Ignore
      }
   }

   ConnectionEvent ce = new ConnectionEvent(this, ConnectionEvent.LOCAL_TRANSACTION_STARTED);
   
   for (ConnectionEventListener cel : listeners)
   {
      cel.localTransactionStarted(ce);
   }
}
 
Example #8
Source File: JCAManagedConnection.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private void onError(Exception e)
{

  this.localTran = null;

  synchronized (this.connections) {
    Iterator<GFConnectionImpl> connsItr = this.connections.iterator();
    while (connsItr.hasNext()) {
      GFConnectionImpl conn = connsItr.next();
      conn.invalidate();
      synchronized (this.listeners) {
        Iterator<ConnectionEventListener> itr = this.listeners.iterator();
        ConnectionEvent ce = new ConnectionEvent(this,
            ConnectionEvent.CONNECTION_ERROR_OCCURRED, e);
        ce.setConnectionHandle(conn);
        while (itr.hasNext()) {
          itr.next().connectionErrorOccurred(ce);
        }
      }
      connsItr.remove();
    }
  }

}
 
Example #9
Source File: FacetsJCAConnectionManagerImpl.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Callback for Connection Closed.
 * 
 * @param event ConnectionEvent Object.
 */
public void connectionClosed(ConnectionEvent event) {
  if (isActive) {
    ManagedConnection conn = (ManagedConnection) event.getSource();
    TransactionManagerImpl transManager = TransactionManagerImpl
        .getTransactionManager();
    try {
      Transaction txn = transManager.getTransaction();
      if (txn == null) {
        mannPoolCache.returnPooledConnectionToPool(conn);
      }
    }
    catch (Exception se) {
      String exception = "FacetsJCAConnectionManagerImpl::connectionClosed: Exception occured due to "
          + se;
      LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
      if (writer.fineEnabled()) writer.fine(exception, se);
    }
  }
}
 
Example #10
Source File: JCAManagedConnection.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
private void onError(Exception e)
{

  this.localTran = null;

  synchronized (this.connections) {
    Iterator<GFConnectionImpl> connsItr = this.connections.iterator();
    while (connsItr.hasNext()) {
      GFConnectionImpl conn = connsItr.next();
      conn.invalidate();
      synchronized (this.listeners) {
        Iterator<ConnectionEventListener> itr = this.listeners.iterator();
        ConnectionEvent ce = new ConnectionEvent(this,
            ConnectionEvent.CONNECTION_ERROR_OCCURRED, e);
        ce.setConnectionHandle(conn);
        while (itr.hasNext()) {
          itr.next().connectionErrorOccurred(ce);
        }
      }
      connsItr.remove();
    }
  }

}
 
Example #11
Source File: JCAManagedConnection.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void onClose(GFConnectionImpl conn) throws ResourceException
{
  conn.invalidate();
  this.connections.remove(conn);
  synchronized (this.listeners) {
    Iterator<ConnectionEventListener> itr = this.listeners.iterator();
    ConnectionEvent ce = new ConnectionEvent(this,
        ConnectionEvent.CONNECTION_CLOSED);
    ce.setConnectionHandle(conn);
    while (itr.hasNext()) {
      itr.next().connectionClosed(ce);
    }
  }
  if (this.connections.isEmpty()) {
    // safe to dissociate this managedconnection so that it can go to pool
    if (this.initDone && !this.cache.isClosed()) {
      this.localTran = new JCALocalTransaction(this.cache, this.gfTxMgr);
    }
    else {
      this.localTran = new JCALocalTransaction();
    }
  }

}
 
Example #12
Source File: ManagedConnectionImplTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveConnectionEventListener() throws Exception {
    ConnectionEvent event = new ConnectionEvent(mc, ConnectionEvent.CONNECTION_ERROR_OCCURRED);

    ConnectionEventListener listener = EasyMock.createMock(ConnectionEventListener.class);
    mc.addConnectionEventListener(listener);
    listener.connectionErrorOccurred(EasyMock.isA(ConnectionEvent.class));
    EasyMock.expectLastCall();
    EasyMock.replay(listener);
    mc.sendEvent(event);
    EasyMock.verify(listener);

    mc.removeConnectionEventListener(listener);
    mc.sendEvent(event);

}
 
Example #13
Source File: ManagedConnectionImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void sendEventToListener(ConnectionEventListener listener,
        ConnectionEvent coEvent) {
    if (coEvent.getId() == ConnectionEvent.CONNECTION_CLOSED) {
        listener.connectionClosed(coEvent);
    }

    if (coEvent.getId() == ConnectionEvent.LOCAL_TRANSACTION_COMMITTED) {
        listener.localTransactionCommitted(coEvent);
    }

    if (coEvent.getId() == ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK) {
        listener.localTransactionRolledback(coEvent);
    }

    if (coEvent.getId() == ConnectionEvent.LOCAL_TRANSACTION_STARTED) {
        listener.localTransactionStarted(coEvent);
    }

    if (coEvent.getId() == ConnectionEvent.CONNECTION_ERROR_OCCURRED) {
        listener.connectionErrorOccurred(coEvent);
    }

}
 
Example #14
Source File: PerfManagedConnection.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Error handle
 */
void errorHandle()
{
   ConnectionEvent errorEvent = new ConnectionEvent(this, ConnectionEvent.CONNECTION_ERROR_OCCURRED,
                                                    new Exception());
   errorEvent.setConnectionHandle(connection);

   List<ConnectionEventListener> copy = new ArrayList<ConnectionEventListener>(listeners);
   for (ConnectionEventListener cel : copy)
   {
      cel.connectionErrorOccurred(errorEvent);
   }
}
 
Example #15
Source File: PerfManagedConnection.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Close handle
 */
void closeHandle()
{
   ConnectionEvent closeEvent = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED);
   closeEvent.setConnectionHandle(connection);

   List<ConnectionEventListener> copy = new ArrayList<ConnectionEventListener>(listeners);
   for (ConnectionEventListener cel : copy)
   {
      cel.connectionClosed(closeEvent);
   }
}
 
Example #16
Source File: TxLogManagedConnection.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void begin() throws ResourceException
{
   log.trace("begin()");

   addTxState(TX_LOCAL_BEGIN);

   ConnectionEvent ce = new ConnectionEvent(this, ConnectionEvent.LOCAL_TRANSACTION_STARTED);
   
   for (ConnectionEventListener cel : listeners)
   {
      cel.localTransactionStarted(ce);
   }
}
 
Example #17
Source File: TxLogManagedConnection.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void commit() throws ResourceException
{
   log.trace("commit()");

   addTxState(TX_LOCAL_COMMIT);

   ConnectionEvent ce = new ConnectionEvent(this, ConnectionEvent.LOCAL_TRANSACTION_COMMITTED);
   
   for (ConnectionEventListener cel : listeners)
   {
      cel.localTransactionCommitted(ce);
   }
}
 
Example #18
Source File: ManagedConnectionImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendEventTxCommitted() throws Exception {
    ConnectionEvent event = new ConnectionEvent(mc, ConnectionEvent.LOCAL_TRANSACTION_COMMITTED);
    ConnectionEventListener listener = EasyMock.createMock(ConnectionEventListener.class);
    mc.addConnectionEventListener(listener);
    listener.localTransactionCommitted(EasyMock.isA(ConnectionEvent.class));
    EasyMock.expectLastCall();
    EasyMock.replay(listener);
    mc.sendEvent(event);
    EasyMock.verify(listener);
}
 
Example #19
Source File: ManagedConnectionImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendEventTxStarted() throws Exception {
    ConnectionEvent event = new ConnectionEvent(mc, ConnectionEvent.LOCAL_TRANSACTION_STARTED);
    ConnectionEventListener listener = EasyMock.createMock(ConnectionEventListener.class);
    mc.addConnectionEventListener(listener);
    listener.localTransactionStarted(EasyMock.isA(ConnectionEvent.class));
    EasyMock.expectLastCall();
    EasyMock.replay(listener);
    mc.sendEvent(event);
    EasyMock.verify(listener);
}
 
Example #20
Source File: ManagedConnectionImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendEventError() throws Exception {
    ConnectionEvent event = new ConnectionEvent(mc, ConnectionEvent.CONNECTION_ERROR_OCCURRED);
    ConnectionEventListener listener = EasyMock.createMock(ConnectionEventListener.class);
    mc.addConnectionEventListener(listener);
    listener.connectionErrorOccurred(EasyMock.isA(ConnectionEvent.class));
    EasyMock.expectLastCall();
    EasyMock.replay(listener);
    mc.sendEvent(event);
    EasyMock.verify(listener);
}
 
Example #21
Source File: AbstractConnectionListener.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void connectionClosed(ConnectionEvent event)
{
   Object connection = event.getConnectionHandle();

   removeConnection(connection);

   if (cm.getCachedConnectionManager() != null)
   {
      cm.getCachedConnectionManager().unregisterConnection(cm, this, connection);
   }

   if (connectionHandles.isEmpty() && !isEnlisted())
      cm.returnConnectionListener(this, false);
}
 
Example #22
Source File: HelloWorldManagedConnection.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Close handle
 * @param handle The handle
 */
void closeHandle(HelloWorldConnection handle)
{
   connections.remove((HelloWorldConnectionImpl)handle);

   ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED);
   event.setConnectionHandle(handle);

   for (ConnectionEventListener cel : listeners)
   {
      cel.connectionClosed(event);
   }
}
 
Example #23
Source File: ManagedConnectionImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testError() throws Exception {
    ConnectionEventListener listener = EasyMock.createMock(ConnectionEventListener.class);
    mc.addConnectionEventListener(listener);
    listener.connectionErrorOccurred(EasyMock.isA(ConnectionEvent.class));
    EasyMock.expectLastCall();
    EasyMock.replay(listener);
    mc.setLogWriter(null);
    mc.error(new Exception());
    EasyMock.verify(listener);
}
 
Example #24
Source File: SampleManagedConnection.java    From tomee with Apache License 2.0 5 votes vote down vote up
void closeHandle(SampleConnection handle) {
    ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED);
    event.setConnectionHandle(handle);
    for (ConnectionEventListener cel : listeners) {
        cel.connectionClosed(event);
    }
}
 
Example #25
Source File: HelloWorldManagedConnection.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Close handle
 * @param handle The handle
 */
void closeHandle(HelloWorldConnection handle)
{
   connections.remove((HelloWorldConnectionImpl)handle);

   ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED);
   event.setConnectionHandle(handle);

   for (ConnectionEventListener cel : listeners)
   {
      cel.connectionClosed(event);
   }
}
 
Example #26
Source File: ManagedConnectionImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testCloseConnection() throws Exception {
    Connection conn = (Connection)mci.getConnection(subj, cri);
    EasyMock.reset(mockListener);
    mockListener.connectionClosed(EasyMock.isA(ConnectionEvent.class));
    EasyMock.expectLastCall();
    EasyMock.replay(mockListener);
    conn.close();
}
 
Example #27
Source File: HelloWorldManagedConnection.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Close handle
 * @param handle The handle
 */
void closeHandle(HelloWorldConnection handle)
{
   connections.remove((HelloWorldConnectionImpl)handle);

   ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED);
   event.setConnectionHandle(handle);

   for (ConnectionEventListener cel : listeners)
   {
      cel.connectionClosed(event);
   }
}
 
Example #28
Source File: SampleManagedConnection.java    From tomee with Apache License 2.0 5 votes vote down vote up
void closeHandle(SampleConnection handle) {
    ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED);
    event.setConnectionHandle(handle);
    for (ConnectionEventListener cel : listeners) {
        cel.connectionClosed(event);
    }
}
 
Example #29
Source File: AbstractManagedConnectionImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void close(Object closingHandle) throws ResourceException {
    LOG.fine("Closing handle: " + closingHandle);

    ConnectionEvent coEvent = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED);
    coEvent.setConnectionHandle(closingHandle);
    sendEvent(coEvent);
}
 
Example #30
Source File: TestManagedConnection.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Close handle
 *
 * @param handle The handle
 */
void closeHandle(TestConnection handle)
{
   connections.remove((TestConnectionImpl)handle);
   ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED);
   event.setConnectionHandle(handle);
   for (ConnectionEventListener cel : listeners)
   {
      cel.connectionClosed(event);
   }
}