GithubHelp home page GithubHelp logo

stephenott / camunda-concurrency-helpers-process-engine-plugin Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 2.0 17 KB

Camunda BPM Process Engine Plugin that provides "Concurrency Helpers" for common functions performed in Process executions

License: MIT License

Java 100.00%
camunda bpm concurrency bpmn process-engine-plugin camunda-plugin

camunda-concurrency-helpers-process-engine-plugin's Introduction

Camunda Concurrency Helpers Process Engine Plugin

A plugin providing helpers for in-flight processes to perform common concurrency actions.

Install the Plugin

As a dependency

Add JitPack as a repository source in your build file.

If you are using Maven, then add the following to your pom.xml

<project>
...
    <repositories>
        <repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
        </repository>
    </repositories>
...

This snippet will enable Maven dependency download directly from Github.com

Then add the following dependency:

...
 <dependency>
    <groupId>com.github.StephenOTT</groupId>
    <artifactId>camunda-concurrency-helpers-process-engine-plugin</artifactId>
    <version>v0.0.0</version>
 </dependency>
 ...

❗️ See the Releases for the latest version number ❗️

Setup the plugin

Plugin Configuration

<!-- engine plugins -->
<property name="processEnginePlugins">
    <list>
        ...
        <bean id="concurrencyHelpersProcessEnginePlugin" class="io.digitalstate.camunda.concurrency.ConcurrencyHelpersProcessEnginePlugin">
        </bean>
        ...
    </list>
</property>

Concurrency Data Aggregation (Concurrent HashMap)

This helper is a simple static ConcurrentHashMap that provides a in-memory storage space outside of the process execution.

The helper is found in io.digitalstate.camunda.concurrency.concurrencyhelpers.ParallelUpdateMap

example usage for Java Delegate

Adding data into the Map

package concurrency;

import io.digitalstate.camunda.concurrency.concurrencyhelpers.ParallelUpdateMap;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;

public class DataGenDelegate implements JavaDelegate {

    @Override
    public void execute(DelegateExecution execution) throws Exception {

        String superProcessInstanceId = execution.getSuperExecution().getProcessInstanceId();
        String processInstanceId = execution.getProcessInstanceId();
        // For a unique Key, the Super Process and sub-process IDs are used. But you can add your own modifier based on your needs
        // This is important for when you have multiple sets of data doing updates in the same sub-process
        String keyName = String.join("--",superProcessInstanceId, processInstanceId);

        // Uses putIfAbsent to ensure atomic update
        ParallelUpdateMap.concurrentMap.putIfAbsent(keyName, 100);
    }

}

Aggregating Data from the Map

package concurrency;

import io.digitalstate.camunda.concurrency.concurrencyhelpers.ParallelUpdateMap;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;

import java.util.List;

public class DataCombineDelegate implements JavaDelegate {

    @Override
    public void execute(DelegateExecution execution) throws Exception {
        String processInstanceId = execution.getProcessInstanceId();

        // Save the array of values as a string into Camunda DB Variables:
        // In practice you would perform whatever merging you like
        // (such as merging a JSON objects into a Array of Json Objects)
        List<Object> values = ParallelUpdateMap.getValues(processInstanceId);
        execution.setVariable("finalResult", values.toString());

        // Reduce a sum of all the values:
        int sum  = (int)values.stream().reduce(0,(x,y) -> (int)x +(int)y);
        execution.setVariable("sum", sum);

        // Clear out the map of the old values
        ParallelUpdateMap.concurrentMap.entrySet()
                .removeIf(e-> e.getKey().contains(processInstanceId));
    }

}

See the ConcurrencyMap1.java unit test for further details.

getValues() Method

The ParallelUpdateMap.getValues("someString") static method is provided which has a String input for providing a "key" value which will be used for a "Contains" search.

The function is as follows:

    public static synchronized List<Object> getValues(String keyContains){
        List<Object> result = concurrentMap.entrySet()
                .stream()
                .filter(e -> e.getKey().contains(keyContains))
                .map(Map.Entry::getValue)
                .collect(Collectors.toList());
        return result;
    }

The result is a List of objects based on the keyContains string value

camunda-concurrency-helpers-process-engine-plugin's People

Contributors

stephenott avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

aravindhrs avall

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.