Search in sources :

Example 1 with EventBridge

use of org.apache.cayenne.event.EventBridge in project cayenne by apache.

the class ClientChannel method setupRemoteChannelListener.

/**
 * Starts up an EventBridge to listen for remote updates. Returns true if the listener
 * was setup, false if not. False can be returned if the underlying connection doesn't
 * support events of if there is no EventManager available.
 */
protected boolean setupRemoteChannelListener() throws CayenneRuntimeException {
    if (eventManager == null) {
        return false;
    }
    EventBridge bridge = connection.getServerEventBridge();
    if (bridge == null) {
        return false;
    }
    try {
        // make sure events are sent on behalf of this channel...and received from all
        bridge.startup(eventManager, EventBridge.RECEIVE_LOCAL_EXTERNAL, null, this);
    } catch (Exception e) {
        throw new CayenneRuntimeException("Error starting EventBridge " + bridge, e);
    }
    this.remoteChannelListener = bridge;
    return true;
}
Also used : CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) EventBridge(org.apache.cayenne.event.EventBridge) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException)

Example 2 with EventBridge

use of org.apache.cayenne.event.EventBridge in project cayenne by apache.

the class DefaultDataRowStoreFactory method setUpEventBridge.

private void setUpEventBridge(DataRowStore store) {
    try {
        EventBridge eventBridge = eventBridgeProvider.get();
        if (eventBridge instanceof NoopEventBridge) {
            return;
        }
        store.setEventBridge(eventBridge);
        store.startListeners();
    } catch (Exception ex) {
        throw new CayenneRuntimeException("Error initializing DataRowStore.", ex);
    }
}
Also used : NoopEventBridge(org.apache.cayenne.event.NoopEventBridge) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) NoopEventBridge(org.apache.cayenne.event.NoopEventBridge) EventBridge(org.apache.cayenne.event.EventBridge) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) DIRuntimeException(org.apache.cayenne.di.DIRuntimeException)

Example 3 with EventBridge

use of org.apache.cayenne.event.EventBridge in project cayenne by apache.

the class ClientChannelTest method testEventBridgeFailure.

@Test
public void testEventBridgeFailure() throws Exception {
    MockClientConnection connection = new MockClientConnection() {

        @Override
        public EventBridge getServerEventBridge() throws CayenneRuntimeException {
            return new EventBridge(Collections.emptyList(), "ext") {

                @Override
                protected void sendExternalEvent(CayenneEvent localEvent) throws Exception {
                }

                @Override
                protected void shutdownExternal() throws Exception {
                }

                @Override
                protected void startupExternal() throws Exception {
                    // intentionally throw an exception
                    throw new CayenneRuntimeException("Test failure");
                }
            };
        }
    };
    // default constructor must fail
    try {
        new ClientChannel(connection, false, new MockEventManager(), false);
        fail("Channel didn't throw on broken EventBridge");
    } catch (CayenneRuntimeException e) {
    // expected
    }
    try {
        DefaultEventManager manager = new DefaultEventManager(2);
        managers.add(manager);
        new ClientChannel(connection, false, manager, false);
        fail("Channel didn't throw on broken EventBridge");
    } catch (CayenneRuntimeException e) {
    // expected
    }
    try {
        DefaultEventManager manager = new DefaultEventManager(2);
        managers.add(manager);
        new ClientChannel(connection, false, manager, true);
    } catch (CayenneRuntimeException e) {
        fail("Channel threw on broken EventBridge");
    }
}
Also used : DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) CayenneEvent(org.apache.cayenne.event.CayenneEvent) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) EventBridge(org.apache.cayenne.event.EventBridge) MockEventManager(org.apache.cayenne.event.MockEventManager) Test(org.junit.Test)

Aggregations

CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)3 EventBridge (org.apache.cayenne.event.EventBridge)3 DIRuntimeException (org.apache.cayenne.di.DIRuntimeException)1 CayenneEvent (org.apache.cayenne.event.CayenneEvent)1 DefaultEventManager (org.apache.cayenne.event.DefaultEventManager)1 MockEventManager (org.apache.cayenne.event.MockEventManager)1 NoopEventBridge (org.apache.cayenne.event.NoopEventBridge)1 Test (org.junit.Test)1