Search in sources :

Example 6 with ConnectionEvent

use of javax.resource.spi.ConnectionEvent in project geode by apache.

the class JCAManagedConnection method onClose.

public void onClose(GFConnectionImpl connection) {
    connection.invalidate();
    this.connections.remove(connection);
    synchronized (this.listeners) {
        Iterator<ConnectionEventListener> iterator = this.listeners.iterator();
        ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED);
        event.setConnectionHandle(connection);
        while (iterator.hasNext()) {
            iterator.next().connectionClosed(event);
        }
    }
    if (this.connections.isEmpty()) {
        // safe to dissociate this managed connection so that it can go to pool
        if (this.initialized && !this.cache.isClosed()) {
            this.localTransaction = new JCALocalTransaction(this.cache, this.transactionManager);
        } else {
            this.localTransaction = new JCALocalTransaction();
        }
    }
}
Also used : ConnectionEvent(javax.resource.spi.ConnectionEvent) ConnectionEventListener(javax.resource.spi.ConnectionEventListener)

Example 7 with ConnectionEvent

use of javax.resource.spi.ConnectionEvent in project geode by apache.

the class JCAManagedConnection method onError.

private void onError(Exception e) {
    // TODO: currently unused
    this.localTransaction = null;
    synchronized (this.connections) {
        Iterator<GFConnectionImpl> iterator = this.connections.iterator();
        while (iterator.hasNext()) {
            GFConnectionImpl connection = iterator.next();
            connection.invalidate();
            synchronized (this.listeners) {
                ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_ERROR_OCCURRED, e);
                event.setConnectionHandle(connection);
                for (ConnectionEventListener listener : this.listeners) {
                    listener.connectionErrorOccurred(event);
                }
            }
            iterator.remove();
        }
    }
}
Also used : GFConnectionImpl(org.apache.geode.internal.ra.GFConnectionImpl) ConnectionEvent(javax.resource.spi.ConnectionEvent) ConnectionEventListener(javax.resource.spi.ConnectionEventListener)

Example 8 with ConnectionEvent

use of javax.resource.spi.ConnectionEvent in project cxf by apache.

the class AbstractManagedConnectionImpl method error.

public void error(Exception ex) {
    LOG.warning(ex.toString());
    sendEvent(new ConnectionEvent(this, ConnectionEvent.CONNECTION_ERROR_OCCURRED, ex));
}
Also used : ConnectionEvent(javax.resource.spi.ConnectionEvent)

Example 9 with ConnectionEvent

use of javax.resource.spi.ConnectionEvent in project cxf by apache.

the class ManagedConnectionImplTest method testRemoveConnectionEventListener.

@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);
}
Also used : ConnectionEvent(javax.resource.spi.ConnectionEvent) ConnectionEventListener(javax.resource.spi.ConnectionEventListener) Test(org.junit.Test)

Example 10 with ConnectionEvent

use of javax.resource.spi.ConnectionEvent in project cxf by apache.

the class ManagedConnectionImplTest method testSendEventTxStarted.

@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);
}
Also used : ConnectionEvent(javax.resource.spi.ConnectionEvent) ConnectionEventListener(javax.resource.spi.ConnectionEventListener) Test(org.junit.Test)

Aggregations

ConnectionEvent (javax.resource.spi.ConnectionEvent)24 ConnectionEventListener (javax.resource.spi.ConnectionEventListener)21 Test (org.junit.Test)5 BadConnectionEventListener (com.sun.appserv.connectors.internal.spi.BadConnectionEventListener)1 GFConnectionImpl (org.apache.geode.internal.ra.GFConnectionImpl)1