Search in sources :

Example 6 with ConnectionEventListener

use of javax.resource.spi.ConnectionEventListener 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 ConnectionEventListener

use of javax.resource.spi.ConnectionEventListener 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 ConnectionEventListener

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

the class ManagedConnectionImplTest method testError.

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

Example 9 with ConnectionEventListener

use of javax.resource.spi.ConnectionEventListener 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 ConnectionEventListener

use of javax.resource.spi.ConnectionEventListener 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)22 ConnectionEventListener (javax.resource.spi.ConnectionEventListener)22 Test (org.junit.Test)7 BadConnectionEventListener (com.sun.appserv.connectors.internal.spi.BadConnectionEventListener)1 NotSupportedException (javax.resource.NotSupportedException)1 GFConnectionImpl (org.apache.geode.internal.ra.GFConnectionImpl)1