Search in sources :

Example 1 with LocalEventData

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));
    }
}
Also used : LocalEventData(org.xwiki.observation.remote.LocalEventData) ObservationManager(org.xwiki.observation.ObservationManager) RemoteObservationManager(org.xwiki.observation.remote.RemoteObservationManager) RemoteObservationManager(org.xwiki.observation.remote.RemoteObservationManager) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 2 with LocalEventData

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();
        }
    }
}
Also used : LocalEventData(org.xwiki.observation.remote.LocalEventData)

Example 3 with LocalEventData

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());
}
Also used : LocalEventData(org.xwiki.observation.remote.LocalEventData) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) RemoteEventData(org.xwiki.observation.remote.RemoteEventData) ByteArrayInputStream(java.io.ByteArrayInputStream) EventConverterManager(org.xwiki.observation.remote.converter.EventConverterManager) XWikiContext(com.xpn.xwiki.XWikiContext) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) DocumentReference(org.xwiki.model.reference.DocumentReference) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Aggregations

LocalEventData (org.xwiki.observation.remote.LocalEventData)3 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 Test (org.junit.Test)1 DocumentUpdatedEvent (org.xwiki.bridge.event.DocumentUpdatedEvent)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 ObservationManager (org.xwiki.observation.ObservationManager)1 RemoteEventData (org.xwiki.observation.remote.RemoteEventData)1 RemoteObservationManager (org.xwiki.observation.remote.RemoteObservationManager)1 EventConverterManager (org.xwiki.observation.remote.converter.EventConverterManager)1