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 = (GraphDiff) 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);
}
Object postedBy = (originatingContext != null)
? originatingContext
: this;
GraphEvent e = new GraphEvent(this, postedBy, notification);
eventManager.postEvent(e, subject);
}
}
}
callbackAction.applyPostCommit();
return replyDiff;
}