Java Code Examples for javax.resource.spi.ConnectionEvent#CONNECTION_ERROR_OCCURRED

The following examples show how to use javax.resource.spi.ConnectionEvent#CONNECTION_ERROR_OCCURRED . 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 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 2
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 3
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 4
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 5
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 6
Source File: ActiveMQRAManagedConnection.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Notifies user of a JMS exception.
 *
 * @param exception The JMS exception
 */
@Override
public void onException(final JMSException exception) {
   if (ActiveMQConnection.EXCEPTION_FAILOVER.equals(exception.getErrorCode())) {
      return;
   }
   if (logger.isTraceEnabled()) {
      ActiveMQRALogger.LOGGER.trace("onException(" + exception + ")");
   }

   if (isDestroyed.get()) {
      if (logger.isTraceEnabled()) {
         ActiveMQRALogger.LOGGER.trace("Ignoring error on already destroyed connection " + this, exception);
      }
      return;
   }

   ActiveMQRALogger.LOGGER.handlingJMSFailure(exception);

   try {
      connection.setExceptionListener(null);
   } catch (JMSException e) {
      logger.debug("Unable to unset exception listener", e);
   }

   ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_ERROR_OCCURRED, exception);
   sendEvent(event);
}
 
Example 7
Source File: ActiveMQRAManagedConnection.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Send an event.
 *
 * @param event The event to send.
 */
protected void sendEvent(final ConnectionEvent event) {
   if (logger.isTraceEnabled()) {
      ActiveMQRALogger.LOGGER.trace("sendEvent(" + event + ")");
   }

   int type = event.getId();

   // convert to an array to avoid concurrent modification exceptions
   ConnectionEventListener[] list = eventListeners.toArray(new ConnectionEventListener[eventListeners.size()]);

   for (ConnectionEventListener l : list) {
      switch (type) {
         case ConnectionEvent.CONNECTION_CLOSED:
            l.connectionClosed(event);
            break;

         case ConnectionEvent.LOCAL_TRANSACTION_STARTED:
            l.localTransactionStarted(event);
            break;

         case ConnectionEvent.LOCAL_TRANSACTION_COMMITTED:
            l.localTransactionCommitted(event);
            break;

         case ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK:
            l.localTransactionRolledback(event);
            break;

         case ConnectionEvent.CONNECTION_ERROR_OCCURRED:
            l.connectionErrorOccurred(event);
            break;

         default:
            throw new IllegalArgumentException("Illegal eventType: " + type);
      }
   }
}
 
Example 8
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 9
Source File: UnifiedSecurityManagedConnection.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Error handle
 *
 * @param handle The handle
 * @param exception The exception
 */
void errorHandle(UnifiedSecurityConnection handle, Exception exception)
{
   connectionSet.remove(handle);

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

   List<ConnectionEventListener> copy = new ArrayList<ConnectionEventListener>(listeners);
   for (ConnectionEventListener cel : copy)
   {
      cel.connectionErrorOccurred(event);
   }
}
 
Example 10
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 11
Source File: TxLogManagedConnection.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Error handle
 *
 * @param handle The handle
 * @param exception The exception
 */
void errorHandle(TxLogConnection handle, Exception exception)
{
   connections.remove((TxLogConnectionImpl)handle);

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

   List<ConnectionEventListener> copy = new ArrayList<ConnectionEventListener>(listeners);
   for (ConnectionEventListener cel : copy)
   {
      cel.connectionErrorOccurred(event);
   }
}