Skip to content
Snippets Groups Projects
Commit 9ef04085 authored by Lukas Raska's avatar Lukas Raska Committed by Thomas Mortagne
Browse files

XWIKI-12923: Specify if remote events should be processed by watchlist listener

parent 584a7324
No related branches found
No related tags found
No related merge requests found
......@@ -36,11 +36,13 @@
import org.xwiki.bridge.event.DocumentDeletedEvent;
import org.xwiki.bridge.event.DocumentUpdatedEvent;
import org.xwiki.component.annotation.Component;
import org.xwiki.component.phase.InitializationException;
import org.xwiki.configuration.ConfigurationSource;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.observation.AbstractEventListener;
import org.xwiki.observation.ObservationContext;
import org.xwiki.observation.event.Event;
import org.xwiki.observation.remote.RemoteObservationManagerContext;
import org.xwiki.watchlist.internal.api.WatchListEvent;
import org.xwiki.watchlist.internal.api.WatchListEventType;
import org.xwiki.watchlist.internal.api.WatchListNotifier;
......@@ -76,6 +78,11 @@ public class RealtimeNotificationGenerator extends AbstractEventListener
private static final List<Event> EVENTS = Arrays.<Event>asList(new DocumentCreatedEvent(),
new DocumentUpdatedEvent(), new DocumentDeletedEvent());
/**
* For parameters checking.
*/
private static final String TRUE = "true";
/**
* Used to detect if certain events are not independent, i.e. executed in the context of other events, case in which
* they should be skipped.
......@@ -83,6 +90,12 @@ public class RealtimeNotificationGenerator extends AbstractEventListener
@Inject
private ObservationContext observationContext;
/**
* Used to obtain observation event context, i.e. if the event is remote.
*/
@Inject
private RemoteObservationManagerContext remoteObservationManagerContext;
/**
* Used to access watchlist data.
*/
......@@ -114,18 +127,36 @@ public class RealtimeNotificationGenerator extends AbstractEventListener
@Named("xwikiproperties")
private ConfigurationSource xwikiProperties;
/**
* Allow processing of remote events.
*/
private boolean allowRemote;
/**
* Default constructor.
*/
public RealtimeNotificationGenerator()
{
super(LISTENER_NAME, EVENTS);
allowRemote = false;
}
/**
* Component manager initialize class. Called after all dependencies are injected.
*
* @throws InitializationException if component isn't properly initialized
*/
public void initialize() throws InitializationException
{
if (TRUE.equals(xwikiProperties.getProperty("watchlist.realtime.allow_remote"))) {
allowRemote = true;
}
}
@Override
public List<Event> getEvents()
{
if ("true".equals(xwikiProperties.getProperty("watchlist.realtime.enabled"))) {
if (TRUE.equals(xwikiProperties.getProperty("watchlist.realtime.enabled"))) {
// If the realtime notification feature is explicitly enabled (temporarily disabled by default), then enable
// this event listener.
return super.getEvents();
......@@ -138,6 +169,12 @@ public List<Event> getEvents()
@Override
public void onEvent(Event event, Object source, Object data)
{
// Early check if event should be processed.
if (this.remoteObservationManagerContext.isRemoteState() && !this.allowRemote) {
// Don't handle remote events to avoid duplicated processing.
return;
}
XWikiDocument currentDoc = (XWikiDocument) source;
XWikiContext context = (XWikiContext) data;
......
......@@ -719,6 +719,11 @@ extension.oldflavors=$oldFlavor.trim()
#-# Once the feature stabilizes, it will be enabled by default and the option to disabled it will be removed.
# watchlist.realtime.enabled = false
#-# [Since 7.1.5, 7.3.1, 7.4M3]
#-# Controls if realtime notifications are triggered by remote events. Default value is false.
#-# Enable if you don't have watchlist loaded on all instances in cluster.
# watchlist.realtime.allow_remote = false
#-------------------------------------------------------------------------------------
# Debug
#-------------------------------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment