Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarrez committed Nov 1, 2016
1 parent 6096768 commit efd2568
Show file tree
Hide file tree
Showing 8 changed files with 310 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
target/
36 changes: 36 additions & 0 deletions pom.xml
@@ -0,0 +1,36 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.flowable</groupId>
<artifactId>flowable-cockroachdb-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-engine</artifactId>
<version>6.0.0.RC1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1211.jre7</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.6</version>
</dependency>
</dependencies>

</project>
63 changes: 63 additions & 0 deletions src/main/java/org/flowable/Demo.java
@@ -0,0 +1,63 @@
package org.flowable;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Random;

import org.activiti.engine.HistoryService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;

/**
* @author Joram Barrez
*/
public class Demo {

public static void main(String[] args) {

ProcessEngine processEngine = ProcessEngineConfiguration
.createProcessEngineConfigurationFromResource("flowable.cfg.xml").buildProcessEngine();

RepositoryService repositoryService = processEngine.getRepositoryService();
RuntimeService runtimeService = processEngine.getRuntimeService();
TaskService taskService = processEngine.getTaskService();
HistoryService historyService = processEngine.getHistoryService();

repositoryService.createDeployment().addClasspathResource("demo-process.bpmn").deploy();
System.out.println("Process definitions deployed = " + repositoryService.createProcessDefinitionQuery().count());

Random random = new Random();
for (int i=0; i<100; i++) {
Map<String, Object> vars = new HashMap<>();
vars.put("var", random.nextInt(100));
runtimeService.startProcessInstanceByKey("myProcess", vars);
}

System.out.println("Process instances running = " + runtimeService.createProcessInstanceQuery().count());
LinkedList<Task> tasks = new LinkedList<>(taskService.createTaskQuery().list());
int taskCounter = 0;
while (!tasks.isEmpty()) {
Task task = taskService.createTaskQuery().taskId(tasks.pop().getId()).singleResult();
if (task != null) {
taskService.complete(task.getId());

taskCounter++;
if (taskCounter % 10 == 0) {
System.out.println("Completed " + taskCounter + " tasks");
}
}
tasks.addAll(taskService.createTaskQuery().list());
}

System.out.println("Finished all tasks. Finished process instances = "
+ historyService.createHistoricProcessInstanceQuery().finished().count());

processEngine.close();
}

}
14 changes: 14 additions & 0 deletions src/main/java/org/flowable/delegate/MyJavaDelegate.java
@@ -0,0 +1,14 @@
package org.flowable.delegate;

import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;

public class MyJavaDelegate implements JavaDelegate {

@Override
public void execute(DelegateExecution execution) {
Integer var = (Integer) execution.getVariable("var");
execution.setVariable("var", var * 10);
}

}
25 changes: 25 additions & 0 deletions src/main/resources/README.txt
@@ -0,0 +1,25 @@
* Download latest CockroachDB tarball
* Untar and run: ./cockroachdb start
* ./cockroach start --store=node2 --port=26258 --http-port=8081 --join=localhost:26257
*
* Admin UI is running on http://localhost:8080/
* Create a database and a user: ./cockroachdb sql
* Execute following statements:
* CREATE DATABASE flowable;
* GRANT ALL ON DATABASE flowable TO maxroach;
* CockroachDB hasn't implemented the 'jdbc metadata' yet, which means the Flowable auto-schema creation won't work.
* Manually create the schema (simplified engine sql script, without foreign keys):

sql=$(wget https://raw.githubusercontent.com/jbarrez/flowable-cockroachdb-demo/master/engine-schema.sql -q -O -)
./cockroach sql --database=flowable --user=maxroach -e "$sql"


---------------------------------------------------------------------------------------------------------
Tested on CockroachDB with following version (./cockroachdb version):

Build Tag: beta-20161027
Build Time: 2016/10/27 13:34:56
Platform: linux amd64
Go Version: go1.7.3
C Compiler: gcc 4.9.2

141 changes: 141 additions & 0 deletions src/main/resources/demo-process.bpmn
@@ -0,0 +1,141 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="myProcess" name="My process" isExecutable="true">
<startEvent id="startevent2" name="Start"></startEvent>
<subProcess id="subprocess1" name="Sub Process">
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="exclusivegateway1"></sequenceFlow>
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask2" name="Task two"></userTask>
<userTask id="usertask1" name="Task one"></userTask>
<exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway>
<sequenceFlow id="flow2" sourceRef="exclusivegateway1" targetRef="usertask1"></sequenceFlow>
<sequenceFlow id="flow3" sourceRef="exclusivegateway1" targetRef="usertask2"></sequenceFlow>
<sequenceFlow id="flow4" sourceRef="exclusivegateway1" targetRef="usertask3"></sequenceFlow>
<userTask id="usertask3" name="Task three"></userTask>
</subProcess>
<sequenceFlow id="flow7" sourceRef="startevent2" targetRef="parallelgateway1"></sequenceFlow>
<parallelGateway id="parallelgateway1" name="Exclusive Gateway"></parallelGateway>
<sequenceFlow id="flow8" sourceRef="parallelgateway1" targetRef="subprocess1"></sequenceFlow>
<sequenceFlow id="flow9" sourceRef="parallelgateway1" targetRef="servicetask1"></sequenceFlow>
<serviceTask id="servicetask1" name="Calculate values" activiti:class="org.flowable.delegate.MyJavaDelegate"></serviceTask>
<userTask id="usertask4" name="Task four"></userTask>
<sequenceFlow id="flow10" sourceRef="servicetask1" targetRef="usertask4"></sequenceFlow>
<sequenceFlow id="flow11" sourceRef="usertask4" targetRef="parallelgateway2"></sequenceFlow>
<parallelGateway id="parallelgateway2" name="Exclusive Gateway"></parallelGateway>
<sequenceFlow id="flow12" sourceRef="subprocess1" targetRef="parallelgateway2"></sequenceFlow>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow13" sourceRef="parallelgateway2" targetRef="endevent1"></sequenceFlow>
<boundaryEvent id="boundarytimer1" name="Timer" attachedToRef="subprocess1" cancelActivity="true">
<timerEventDefinition>
<timeDuration>PT5H</timeDuration>
</timerEventDefinition>
</boundaryEvent>
<userTask id="usertask5" name="Task escalation"></userTask>
<sequenceFlow id="flow14" sourceRef="boundarytimer1" targetRef="usertask5"></sequenceFlow>
<sequenceFlow id="flow15" sourceRef="usertask5" targetRef="parallelgateway2"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_myProcess">
<bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess">
<bpmndi:BPMNShape bpmnElement="startevent2" id="BPMNShape_startevent2">
<omgdc:Bounds height="35.0" width="35.0" x="60.0" y="305.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="subprocess1" id="BPMNShape_subprocess1">
<omgdc:Bounds height="322.0" width="541.0" x="240.0" y="110.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="345.0" y="250.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
<omgdc:Bounds height="55.0" width="105.0" x="510.0" y="241.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1">
<omgdc:Bounds height="40.0" width="40.0" x="425.0" y="248.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3">
<omgdc:Bounds height="55.0" width="105.0" x="510.0" y="340.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="510.0" y="140.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="boundarytimer1" id="BPMNShape_boundarytimer1">
<omgdc:Bounds height="30.0" width="30.0" x="680.0" y="91.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="parallelgateway1" id="BPMNShape_parallelgateway1">
<omgdc:Bounds height="40.0" width="40.0" x="140.0" y="303.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="servicetask1" id="BPMNShape_servicetask1">
<omgdc:Bounds height="55.0" width="105.0" x="240.0" y="481.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask4" id="BPMNShape_usertask4">
<omgdc:Bounds height="55.0" width="105.0" x="390.0" y="481.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="parallelgateway2" id="BPMNShape_parallelgateway2">
<omgdc:Bounds height="40.0" width="40.0" x="910.0" y="495.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="995.0" y="498.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask5" id="BPMNShape_usertask5">
<omgdc:Bounds height="55.0" width="105.0" x="642.0" y="1.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="380.0" y="267.0"></omgdi:waypoint>
<omgdi:waypoint x="425.0" y="268.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="445.0" y="248.0"></omgdi:waypoint>
<omgdi:waypoint x="444.0" y="167.0"></omgdi:waypoint>
<omgdi:waypoint x="510.0" y="167.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="465.0" y="268.0"></omgdi:waypoint>
<omgdi:waypoint x="510.0" y="268.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
<omgdi:waypoint x="445.0" y="288.0"></omgdi:waypoint>
<omgdi:waypoint x="445.0" y="367.0"></omgdi:waypoint>
<omgdi:waypoint x="510.0" y="367.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
<omgdi:waypoint x="95.0" y="322.0"></omgdi:waypoint>
<omgdi:waypoint x="140.0" y="323.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow8" id="BPMNEdge_flow8">
<omgdi:waypoint x="160.0" y="303.0"></omgdi:waypoint>
<omgdi:waypoint x="160.0" y="271.0"></omgdi:waypoint>
<omgdi:waypoint x="240.0" y="271.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow9" id="BPMNEdge_flow9">
<omgdi:waypoint x="160.0" y="343.0"></omgdi:waypoint>
<omgdi:waypoint x="159.0" y="508.0"></omgdi:waypoint>
<omgdi:waypoint x="240.0" y="508.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow10" id="BPMNEdge_flow10">
<omgdi:waypoint x="345.0" y="508.0"></omgdi:waypoint>
<omgdi:waypoint x="390.0" y="508.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow11" id="BPMNEdge_flow11">
<omgdi:waypoint x="495.0" y="508.0"></omgdi:waypoint>
<omgdi:waypoint x="910.0" y="515.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow12" id="BPMNEdge_flow12">
<omgdi:waypoint x="781.0" y="271.0"></omgdi:waypoint>
<omgdi:waypoint x="930.0" y="271.0"></omgdi:waypoint>
<omgdi:waypoint x="930.0" y="495.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow13" id="BPMNEdge_flow13">
<omgdi:waypoint x="950.0" y="515.0"></omgdi:waypoint>
<omgdi:waypoint x="995.0" y="515.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow14" id="BPMNEdge_flow14">
<omgdi:waypoint x="695.0" y="91.0"></omgdi:waypoint>
<omgdi:waypoint x="694.0" y="56.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow15" id="BPMNEdge_flow15">
<omgdi:waypoint x="747.0" y="28.0"></omgdi:waypoint>
<omgdi:waypoint x="930.0" y="28.0"></omgdi:waypoint>
<omgdi:waypoint x="930.0" y="495.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
19 changes: 19 additions & 0 deletions src/main/resources/flowable.cfg.xml
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<property name="jdbcUrl" value="jdbc:postgresql://127.0.0.1:26257/flowable?sslmode=disable" />
<property name="jdbcDriver" value="org.postgresql.Driver" />
<property name="jdbcUsername" value="maxroach" />
<property name="jdbcPassword" value="" />

<property name="databaseSchemaUpdate" value="cockroachDb" />

<!-- Disabling identity management. Don't need it here -->
<property name="disableIdmEngine" value="true" />
</bean>

</beans>
11 changes: 11 additions & 0 deletions src/main/resources/log4j.properties
@@ -0,0 +1,11 @@
log4j.rootLogger=INFO, CA

# ConsoleAppender
log4j.appender.CA=org.apache.log4j.ConsoleAppender
log4j.appender.CA.layout=org.apache.log4j.PatternLayout
log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - %m%n


log4j.logger.org.apache.ibatis.level=INFO
log4j.logger.javax.activation.level=INFO
log4j.logger.org.activiti.engine.impl.agenda=INFO

0 comments on commit efd2568

Please sign in to comment.