Search in sources :

Example 1 with SnapshotEvent

use of org.apache.cayenne.access.event.SnapshotEvent in project cayenne by apache.

the class DataRowStore method sendUpdateNotification.

private void sendUpdateNotification(Object postedBy, Map<ObjectId, DataRow> diffs, Collection<ObjectId> deletedSnapshotIDs, Collection<ObjectId> invalidatedSnapshotIDs, Collection<ObjectId> indirectlyModifiedIds) {
    // do not send bogus events... e.g. inserted objects are not counted
    if ((diffs != null && !diffs.isEmpty()) || (deletedSnapshotIDs != null && !deletedSnapshotIDs.isEmpty()) || (invalidatedSnapshotIDs != null && !invalidatedSnapshotIDs.isEmpty()) || (indirectlyModifiedIds != null && !indirectlyModifiedIds.isEmpty())) {
        SnapshotEvent event = new SnapshotEvent(this, postedBy, diffs, deletedSnapshotIDs, invalidatedSnapshotIDs, indirectlyModifiedIds);
        if (logger.isDebugEnabled()) {
            logger.debug("postSnapshotsChangeEvent: " + event);
        }
        // synchronously notify listeners; leaving it up to the listeners to
        // register as "non-blocking" if needed.
        eventManager.postEvent(event, getSnapshotEventSubject());
    }
}
Also used : SnapshotEvent(org.apache.cayenne.access.event.SnapshotEvent)

Example 2 with SnapshotEvent

use of org.apache.cayenne.access.event.SnapshotEvent in project cayenne by apache.

the class EventBridgeTest method testSendExternalEvent.

@Test
public void testSendExternalEvent() throws Exception {
    final EventSubject local = EventSubject.getSubject(EventBridgeTest.class, "testInstall");
    String external = "externalSubject";
    final TestBridge bridge = new TestBridge(local, external);
    DefaultEventManager manager = new DefaultEventManager(2);
    managersToClean.add(manager);
    bridge.startup(manager, EventBridge.RECEIVE_LOCAL_EXTERNAL);
    final SnapshotEvent eventWithNoSubject = new SnapshotEvent(this, this, null, null, null, null);
    manager.postEvent(eventWithNoSubject, local);
    // check that event was received and that subject was injected...
    // since bridge is notified asynchronously by default,
    // we must wait till notification is received
    ParallelTestContainer helper = new ParallelTestContainer() {

        @Override
        protected void assertResult() throws Exception {
            assertTrue(bridge.lastLocalEvent instanceof SnapshotEvent);
            assertEquals(local, bridge.lastLocalEvent.getSubject());
        }
    };
    helper.runTest(5000);
    final SnapshotEvent eventWithSubject = new SnapshotEvent(this, this, null, null, null, null);
    eventWithSubject.setSubject(local);
    manager.postEvent(eventWithNoSubject, local);
    // check that event was received and that subject was injected...
    // since bridge is notified asynchronously by default,
    // we must wait till notification is received
    ParallelTestContainer helper1 = new ParallelTestContainer() {

        @Override
        protected void assertResult() throws Exception {
            assertTrue(bridge.lastLocalEvent instanceof SnapshotEvent);
            assertEquals(local, bridge.lastLocalEvent.getSubject());
        }
    };
    helper1.runTest(5000);
}
Also used : SnapshotEvent(org.apache.cayenne.access.event.SnapshotEvent) ParallelTestContainer(org.apache.cayenne.test.parallel.ParallelTestContainer) Test(org.junit.Test)

Example 3 with SnapshotEvent

use of org.apache.cayenne.access.event.SnapshotEvent in project cayenne by apache.

the class DataContextMergeHandler method graphChanged.

// *** GraphEventListener methods
public void graphChanged(GraphEvent event) {
    // parent received external change
    if (shouldProcessEvent(event)) {
        // temp kludge - see TODO in ObjectStore.snapshotsChanged(..)
        GraphDiff diff = event.getDiff();
        if (diff instanceof SnapshotEventDecorator) {
            SnapshotEvent decoratedEvent = ((SnapshotEventDecorator) diff).getEvent();
            context.getObjectStore().processSnapshotEvent(decoratedEvent);
        } else {
            synchronized (context.getObjectStore()) {
                diff.apply(this);
            }
        }
        // repost channel change event for our own children
        context.fireDataChannelChanged(event.getPostedBy(), event.getDiff());
    }
}
Also used : GraphDiff(org.apache.cayenne.graph.GraphDiff) SnapshotEventDecorator(org.apache.cayenne.access.ObjectStore.SnapshotEventDecorator) SnapshotEvent(org.apache.cayenne.access.event.SnapshotEvent)

Aggregations

SnapshotEvent (org.apache.cayenne.access.event.SnapshotEvent)3 SnapshotEventDecorator (org.apache.cayenne.access.ObjectStore.SnapshotEventDecorator)1 GraphDiff (org.apache.cayenne.graph.GraphDiff)1 ParallelTestContainer (org.apache.cayenne.test.parallel.ParallelTestContainer)1 Test (org.junit.Test)1