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;
}
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);
}
}
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");
}
}
Aggregations