Sync Macro

Last modified by Thomas Mortagne on 2024/12/02 14:55

cogA macro which content is executed by only one thread at a time
TypeJAR
CategoryMacro
Developed by

Thomas Mortagne

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Installable with the Extension Manager

Description

A macro which content is executed by only one thread at a time.

A target use case for this macro is when an application which can be called by several persons at the same time to update some common document (for example, a button to let users register themself to some event where registering a user means adding that user reference to a field of the event page). Without a way to synchronize these document updates, users will keep overwriting the modifications made a few milliseconds before by other users.

Note that the macro won't help if the two requests are executed on two different instances of the same cluster. It currently only lock threads executed on the same instance.

Usage

{{sync}}
some content which much not be executed by several threads at the same time
{{/sync}}
{{sync id="somecustomid"}}
some content which much not be executed by several threads at the same time
{{/sync}}

Parameters definition

NameOptionalAllowed valuesDefault valueDescription
idnoanyEmptyThe identifier associated to the content to execute. Any sync macro with the same identifier, wherever it is located in the XWiki instance, will wait when a content associated with the same identifier is being executed but another thread. By default, the identifier is a combination of the identifier of the source containing the macro call and its index in that source (so each sync macro all in the same page have their own identifier).

Prerequisites & Installation Instructions

We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager).

You can also use the manual method which involves dropping the JAR file and all its dependencies into the WEB-INF/lib folder and restarting XWiki.

Dependencies

Dependencies for this extension (org.xwiki.contrib.concurrent:concurrent-macro-sync 1.0.0):

Get Connected