use of org.apache.cayenne.graph.GraphEvent in project cayenne by apache.
the class ClientChannel method onSync.
public GraphDiff onSync(ObjectContext originatingContext, GraphDiff changes, int syncType) {
DataChannelSyncCallbackAction callbackAction = DataChannelSyncCallbackAction.getCallbackAction(getEntityResolver().getCallbackRegistry(), originatingContext.getGraphManager(), changes, syncType);
callbackAction.applyPreCommit();
changes = diffCompressor.compress(changes);
GraphDiff replyDiff = send(new SyncMessage(originatingContext, syncType, changes), GraphDiff.class);
if (channelEventsEnabled) {
EventSubject subject;
switch(syncType) {
case DataChannel.ROLLBACK_CASCADE_SYNC:
subject = DataChannel.GRAPH_ROLLEDBACK_SUBJECT;
break;
case DataChannel.FLUSH_NOCASCADE_SYNC:
subject = DataChannel.GRAPH_CHANGED_SUBJECT;
break;
case DataChannel.FLUSH_CASCADE_SYNC:
subject = DataChannel.GRAPH_FLUSHED_SUBJECT;
break;
default:
subject = null;
}
if (subject != null) {
// combine message sender changes and message receiver changes into a
// single event
boolean sentNoop = changes == null || changes.isNoop();
boolean receivedNoop = replyDiff == null || replyDiff.isNoop();
if (!sentNoop || !receivedNoop) {
CompoundDiff notification = new CompoundDiff();
if (!sentNoop) {
notification.add(changes);
}
if (!receivedNoop) {
notification.add(replyDiff);
}
GraphEvent e = new GraphEvent(this, originatingContext, notification);
eventManager.postEvent(e, subject);
}
}
}
callbackAction.applyPostCommit();
return replyDiff;
}
use of org.apache.cayenne.graph.GraphEvent in project cayenne by apache.
the class CayenneContextMergeHandlerIT method testShouldProcessEvent.
@Test
public void testShouldProcessEvent() {
CayenneContextMergeHandler handler = new CayenneContextMergeHandler(context);
// 1. Our context initiated the sync:
// src == channel && postedBy == context
GraphEvent e1 = new GraphEvent(context.getChannel(), context, null);
assertFalse(handler.shouldProcessEvent(e1));
// 2. Another context initiated the sync:
// postedBy != context && source == channel
GraphEvent e2 = new GraphEvent(context.getChannel(), mock(ObjectContext.class), null);
assertTrue(handler.shouldProcessEvent(e2));
// 2.1 Another object initiated the sync:
// postedBy != context && source == channel
GraphEvent e21 = new GraphEvent(context.getChannel(), new Object(), null);
assertTrue(handler.shouldProcessEvent(e21));
// 3. Another channel initiated the sync:
// postedBy == ? && source != channel
GraphEvent e3 = new GraphEvent(new MockDataChannel(), new Object(), null);
assertFalse(handler.shouldProcessEvent(e3));
// 4. inactive
GraphEvent e4 = new GraphEvent(context.getChannel(), mock(ObjectContext.class), null);
handler.active = false;
assertFalse(handler.shouldProcessEvent(e4));
}
use of org.apache.cayenne.graph.GraphEvent in project cayenne by apache.
the class CayenneContextGraphManager method send.
/**
* Wraps GraphDiff in a GraphEvent and sends it via EventManager with specified
* subject.
*/
void send(GraphDiff diff, EventSubject subject, Object eventSource) {
EventManager manager = (context.getChannel() != null) ? context.getChannel().getEventManager() : null;
if (manager != null) {
GraphEvent e = new GraphEvent(context, eventSource, diff);
manager.postEvent(e, subject);
}
}
use of org.apache.cayenne.graph.GraphEvent in project cayenne by apache.
the class BaseContext method fireDataChannelRolledback.
/**
* @since 1.2
*/
protected void fireDataChannelRolledback(Object postedBy, GraphDiff changes) {
EventManager manager = getEventManager();
if (manager != null) {
GraphEvent e = new GraphEvent(this, postedBy, changes);
manager.postEvent(e, DataChannel.GRAPH_ROLLEDBACK_SUBJECT);
}
}
use of org.apache.cayenne.graph.GraphEvent in project cayenne by apache.
the class BaseContext method fireDataChannelCommitted.
/**
* @since 1.2
*/
protected void fireDataChannelCommitted(Object postedBy, GraphDiff changes) {
EventManager manager = getEventManager();
if (manager != null) {
GraphEvent e = new GraphEvent(this, postedBy, changes);
manager.postEvent(e, DataChannel.GRAPH_FLUSHED_SUBJECT);
}
}
Aggregations