Skip to content

Commit

Permalink
JBPM-8210: Avoid reflection in NodeInstances (#1)
Browse files Browse the repository at this point in the history
* avoid reflection in node, context factories; disable ScriptManager in SVM

* remove ScriptFactory for SVM compat

* test: should not check node factory for Class type

* @ignore tests using DataTransformers
  • Loading branch information
evacchi authored and tarilabs committed Apr 7, 2019
1 parent 13725b7 commit a7a8bb7
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ public void testServiceTask() throws Exception {
assertEquals("Hello john!", processInstance.getVariable("s"));
}

@Test
@Test @Ignore("Transfomer has been disabled")
public void testServiceTaskWithTransformation() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-ServiceProcessWithTransformation.bpmn2");
ksession = createKnowledgeSession(kbase);
Expand Down Expand Up @@ -1380,7 +1380,7 @@ public void testServiceTaskInterface() throws Exception {
}

@SuppressWarnings("unchecked")
@Test
@Test @Ignore("Transfomer has been disabled")
public void testBusinessRuleTaskWithTransformation() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-RuleTaskWithTransformation.bpmn2",
"BPMN2-RuleTaskWithTransformation.drl");
Expand All @@ -1406,7 +1406,7 @@ public void testBusinessRuleTaskWithTransformation() throws Exception {

}

@Test
@Test @Ignore("Transfomer has been disabled")
public void testCallActivityWithTransformation() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-CallActivityWithTransformation.bpmn2", "BPMN2-CallActivitySubProcess.bpmn2");
ksession = createKnowledgeSession(kbase);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.jbpm.process.instance.timer.TimerManager;
import org.jbpm.test.util.NodeLeftCountDownProcessEventListener;
import org.junit.After;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
Expand Down Expand Up @@ -1815,7 +1816,7 @@ public void testIntermediateCatchEventSignalAndBoundarySignalEvent() throws Exce
assertProcessInstanceFinished(processInstance, ksession);
}

@Test
@Test @Ignore("Transfomer has been disabled")
public void testSignalIntermediateThrowEventWithTransformation() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper(
"BPMN2-BoundarySignalEventOnTaskbpmn2.bpmn",
Expand All @@ -1838,7 +1839,7 @@ public void testSignalIntermediateThrowEventWithTransformation() throws Exceptio
assertThat(var).isEqualTo("JOHN");
}

@Test
@Test @Ignore("Transfomer has been disabled")
public void testSignalBoundaryEventWithTransformation() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper(
"BPMN2-BoundarySignalEventOnTaskWithTransformation.bpmn",
Expand All @@ -1861,7 +1862,7 @@ public void testSignalBoundaryEventWithTransformation() throws Exception {
assertThat(var).isEqualTo("JOHN");
}

@Test
@Test @Ignore("Transfomer has been disabled")
public void testMessageIntermediateThrowWithTransformation() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2");
ksession = createKnowledgeSession(kbase);
Expand All @@ -1887,7 +1888,7 @@ public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {

}

@Test
@Test @Ignore("Transfomer has been disabled")
public void testIntermediateCatchEventSignalWithTransformation() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-IntermediateCatchEventSignalWithTransformation.bpmn2");
ksession = createKnowledgeSession(kbase);
Expand All @@ -1905,7 +1906,7 @@ public void testIntermediateCatchEventSignalWithTransformation() throws Exceptio
assertThat(var).isEqualTo("SOMEVALUE");
}

@Test
@Test @Ignore("Transfomer has been disabled")
public void testIntermediateCatchEventMessageWithTransformation() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-IntermediateCatchEventMessageWithTransformation.bpmn2");
ksession = createKnowledgeSession(kbase);
Expand All @@ -1922,7 +1923,7 @@ public void testIntermediateCatchEventMessageWithTransformation() throws Excepti
assertThat(var).isEqualTo("SOMEVALUE");
}

@Test
@Test @Ignore("Transfomer has been disabled")
public void testEventSubprocessSignalWithTransformation() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-EventSubprocessSignalWithTransformation.bpmn2");
ksession = createKnowledgeSession(kbase);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.jbpm.bpmn2.objects.TestWorkItemHandler;
import org.jbpm.test.util.NodeLeftCountDownProcessEventListener;
import org.junit.After;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
Expand Down Expand Up @@ -525,7 +526,7 @@ public void testTimerCycle() throws Exception {
assertThat(listener.getCount("start.cycle")).isEqualTo(5);
}

@Test(timeout=10000)
@Test(timeout=10000) @Ignore("Transfomer has been disabled")
public void testSignalStartWithTransformation() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartProcess", 1);
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-SignalStartWithTransformation.bpmn2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.jbpm.process.core.impl;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -70,18 +71,17 @@
public class DataTransformerRegistry {

private static final Logger logger = LoggerFactory.getLogger(DataTransformerRegistry.class);
private static final DataTransformerRegistry INSTANCE = new DataTransformerRegistry();
private static final DataTransformerRegistry INSTANCE =
// do not create ScriptEngineManager on SVM for now
new DataTransformerRegistry(Collections.emptyList());

private Map<String, DataTransformer> registry;

protected DataTransformerRegistry() {
protected DataTransformerRegistry(List<ScriptEngineFactory> factories) {
this.registry = new ConcurrentHashMap<String, DataTransformer>();
this.registry.put("http://www.mvel.org/2.0", new MVELDataTransformer());
ScriptEngineManager manager = new ScriptEngineManager();
List<ScriptEngineFactory> factories = manager.getEngineFactories();
for (ScriptEngineFactory factory : factories) {
DataTransformer transformer = new JavaScriptingDataTransformer(factory);

for (String name : factory.getNames()) {
String key = "http://www.java.com/"+name;
registry.put(key, transformer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@

import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;

import org.jbpm.process.core.Context;
import org.jbpm.process.core.context.exception.CompensationScope;
import org.jbpm.process.core.context.exception.ExceptionScope;
import org.jbpm.process.core.context.swimlane.SwimlaneContext;
import org.jbpm.process.core.context.variable.VariableScope;
import org.jbpm.process.instance.ContextInstance;
import org.jbpm.process.instance.ContextInstanceContainer;
import org.jbpm.process.instance.ProcessInstance;
import org.jbpm.process.instance.context.AbstractContextInstance;
import org.jbpm.process.instance.context.exception.CompensationScopeInstance;
import org.jbpm.process.instance.context.exception.DefaultExceptionScopeInstance;
import org.jbpm.process.instance.context.swimlane.SwimlaneContextInstance;
Expand All @@ -39,16 +44,6 @@ public class ContextInstanceFactoryRegistry {

public ContextInstanceFactoryRegistry() {
this.registry = new HashMap<Class<? extends Context>, ContextInstanceFactory>();

// hard wired contexts:
register(VariableScope.class, new ReuseContextInstanceFactory(
VariableScopeInstance.class));
register(ExceptionScope.class, new ReuseContextInstanceFactory(
DefaultExceptionScopeInstance.class));
register(CompensationScope.class, new ReuseContextInstanceFactory(
CompensationScopeInstance.class));
register(SwimlaneContext.class, new ReuseContextInstanceFactory(
SwimlaneContextInstance.class));
}

public void register(Class<? extends Context> cls,
Expand All @@ -57,6 +52,39 @@ public void register(Class<? extends Context> cls,
}

public ContextInstanceFactory getContextInstanceFactory(Context context) {
return this.registry.get(context.getClass());
Class<? extends Context> cls = context.getClass();
// hard wired contexts:
if (cls == VariableScope.class) return factoryOf(VariableScopeInstance::new);
if (cls == ExceptionScope.class) return factoryOf(DefaultExceptionScopeInstance::new);
if (cls == CompensationScope.class) return factoryOf(CompensationScopeInstance::new);
if (cls == SwimlaneContext.class) return factoryOf(SwimlaneContextInstance::new);

return this.registry.get(cls);
}

private static ContextInstanceFactory factoryOf(Supplier<? extends ContextInstance> supplier) {
return (context, contextInstanceContainer, processInstance) ->
getContextInstance(supplier,
context,
contextInstanceContainer,
processInstance);
}

private static ContextInstance getContextInstance(
Supplier<? extends ContextInstance> supplier,
Context context,
ContextInstanceContainer contextInstanceContainer,
ProcessInstance processInstance) {
ContextInstance result = contextInstanceContainer.getContextInstance( context.getType(), context.getId() );
if (result != null) {
return result;
}
AbstractContextInstance contextInstance = (AbstractContextInstance) supplier.get();
contextInstance.setProcessInstance(processInstance);
contextInstance.setContextId(context.getId());
contextInstance.setContextInstanceContainer(contextInstanceContainer);
contextInstanceContainer.addContextInstance(context.getType(), contextInstance);
return contextInstance;
}

}
Loading

0 comments on commit a7a8bb7

Please sign in to comment.