use of org.xwiki.observation.remote.LocalEventData in project xwiki-platform by xwiki.
the class LocalEventListener method onEvent.
@Override
public void onEvent(Event event, Object source, Object data) {
if (this.remoteObservationManager == null) {
try {
// Make sure to not receive events until RemoteObservationManager is ready
ObservationManager om = this.componentManager.getInstance(ObservationManager.class);
om.removeListener(getName());
this.remoteObservationManager = this.componentManager.getInstance(RemoteObservationManager.class);
om.addListener(this);
this.remoteObservationManager.notify(new LocalEventData(event, source, data));
} catch (ComponentLookupException e) {
this.logger.error("Failed to initialize the Remote Observation Manager", e);
}
} else {
this.remoteObservationManager.notify(new LocalEventData(event, source, data));
}
}
use of org.xwiki.observation.remote.LocalEventData in project xwiki-platform by xwiki.
the class DefaultRemoteObservationManager method notify.
@Override
public void notify(RemoteEventData remoteEvent) {
// Make sure the Execution context is properly initialized
initializeContext();
LocalEventData localEvent = this.eventConverterManager.createLocalEventData(remoteEvent);
// send event
if (localEvent != null) {
// Indicate all the following events are remote events
this.remoteEventManagerContext.pushRemoteState();
try {
this.observationManager.notify(localEvent.getEvent(), localEvent.getSource(), localEvent.getData());
} finally {
// Indicate all the following events are local events
this.remoteEventManagerContext.popRemoteState();
}
}
}
use of org.xwiki.observation.remote.LocalEventData in project xwiki-platform by xwiki.
the class DocumentEventConverterTest method testConvertWithOriginalDocNull.
@Test
public void testConvertWithOriginalDocNull() throws Exception {
EventConverterManager eventConverterManager = getComponentManager().getInstance(EventConverterManager.class);
// local -> remote
LocalEventData localEvent = new LocalEventData();
localEvent.setEvent(new DocumentUpdatedEvent(new DocumentReference("wiki", "space", "page")));
localEvent.setSource(new XWikiDocument(new DocumentReference("wiki", "space", "page")));
localEvent.setData(getContext());
RemoteEventData remoteEvent = eventConverterManager.createRemoteEventData(localEvent);
Assert.assertFalse(remoteEvent.getSource() instanceof XWikiDocument);
Assert.assertFalse(remoteEvent.getData() instanceof XWikiContext);
// serialize/unserialize
ByteArrayOutputStream sos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(sos);
oos.writeObject(remoteEvent);
ByteArrayInputStream sis = new ByteArrayInputStream(sos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(sis);
remoteEvent = (RemoteEventData) ois.readObject();
// remote -> local
LocalEventData localEvent2 = eventConverterManager.createLocalEventData(remoteEvent);
Assert.assertTrue(localEvent2.getSource() instanceof XWikiDocument);
Assert.assertTrue(localEvent2.getData() instanceof XWikiContext);
Assert.assertEquals("wiki", ((XWikiDocument) localEvent2.getSource()).getWikiName());
Assert.assertEquals("space", ((XWikiDocument) localEvent2.getSource()).getSpaceName());
Assert.assertEquals("page", ((XWikiDocument) localEvent2.getSource()).getPageName());
Assert.assertTrue(((XWikiDocument) localEvent2.getSource()).getOriginalDocument().isNew());
}
Aggregations