Multiple Delete events when renaming a page/document

Hi,

I’m using XWiki 13.10.5 and I have written an extension that listens for page/document deletions and renames. In the case of a rename my code appears to be getting a delete event which is part of the rename job (I.e. context.isIn(new DocumentRenamingEvent()); returns true) but separately a second DocumentDeletedEvent which isn’t part of the rename job (context.isIn(new DocumentRenamingEvent()); returns false) as well as a DocumentRenamedEvent.

As such, my code can’t reliably tell whether the document has been deleted or renamed.

Is there something I may be doing wrong or is there a way to determine whether a Delete event is an actual delete or part of a rename?

Thanks in advance,
Alex

Sounds very weird, could you get the stack trace of that one ?

Sorry for the delay. I’ve now realised what’s happening. I have an XWiki cluster and the extra Deleted Event is being seen on the other node. What I mean is…

  1. A Cluster with 2 instances of XWiki: A and B.
  2. Log in to XWiki, I end up on A.
  3. I rename a page.
  4. On A, I get:
    1. A DocumentDeletedEvent event which is in the context of a rename so, my code ignores it.
    2. A DocumentRenamedEvent which my code processes.
  5. On B, I get:
    1. A DocumentDeletedEvent event, which is not part of a context (the Event Deque the ObservationContext gets from the ExecutionContext is empty) so my code thinks it’s a page deletion and processes it as such.

Is there a way for my code to ignore remote events?

Cheers

My extension code basically follows the example provided here: Local Observation Module (XWiki.org) such that it was intended to listen for “local” events rather than remote one.

I think I’ve found a solution but I would like some confirmation that I’m doing something acceptable. My solution is to:

Inject the Remote Observation Manager Context:

@Inject
private RemoteObservationManagerContext remoteContext;

An then in onEvent, check remoteContext.isRemoteState(); and if that returns true ignore the event.

WDYT?

Cheers

Yes, that’s it.

But this reminds me that we need to add support for DocumentRenaming/edEvent events in the remote events distribution too since they are very important as your example shows. I created [XWIKI-19817] DocumentRenaming/edEvent events are not distributed to other cluster members - XWiki.org JIRA.

Ok, great. Thank you @tmortagne, very much appreciated.