Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Gerardo hat mal wieder ein bisschen refactored und Commentiert

  • Loading branch information...
commit f78964ea89d781aec97d75c821fd4c85d7f6a530 1 parent f9b390f
@gerardo-navarro gerardo-navarro authored
View
6 engine-core-api/src/main/java/org/jodaengine/node/activity/Activity.java
@@ -20,7 +20,7 @@
* Execute. Starts the execution of the Activity.
*
* @param token
- * the instance the activity operates on
+ * - the instance the activity operates on
*/
void execute(@Nonnull Token token);
@@ -28,7 +28,7 @@
* Do some cleanup, if necessary. Cancellation of the activity's execution is not handled here.
*
* @param executingToken
- * the token that currently executes the activity
+ * - the token that currently executes the activity
*/
void cancel(Token executingToken);
@@ -36,7 +36,7 @@
* This method is called when the execution of the activity is resumed.
*
* @param token
- * the token that resumes this activity
+ * - the token that resumes this activity
* @param resumeObject
* - an object that is passed from class that resumes the Token
*/
View
63 engine-core-impl/src/main/java/org/jodaengine/node/activity/AbstractActivity.java
@@ -2,62 +2,81 @@
import javax.annotation.Nonnull;
+import org.jodaengine.exception.JodaEngineRuntimeException;
import org.jodaengine.process.token.Token;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
/**
* The Class AbstractActivityImpl.
* An activity is the behaviour of a node. It does not perform any control flow routing operations.
*/
-public abstract class AbstractActivity
-implements Activity {
-
+public abstract class AbstractActivity implements Activity {
+
protected final Logger logger = LoggerFactory.getLogger(getClass());
-
+
/**
* Instantiates a new activity. State is set to INIT, but observers will not
* be notified (since no observer are registered so far).
*
*/
protected AbstractActivity() {
+
}
-
+
@Override
public void execute(@Nonnull Token token) {
+
executeIntern(token);
}
-
+
/**
* Method, which implements the concrete's activity's implementation.
*
- * @param token the instance this activity operates on
+ * @param token
+ * the instance this activity operates on
*/
protected abstract void executeIntern(@Nonnull Token token);
-
- @Override
- public String toString() {
- return getClass().getSimpleName();
- }
-
+
/**
- * Override this, if need to cleanup, if the activity is cancelled (e.g. event deregistration).
- *
- * @param executingToken the executing token
+ * Override this, if need to cleanup, if the activity is cancelled (e.g. event unsubscription).
+ *
+ * @param executingToken
+ * the executing token
*/
@Override
public void cancel(Token executingToken) {
-
+
}
-
+
/**
* Override this, if you need to do cleanup after the executing token has been resumed.
- *
- * @param token the token
+ *
+ * @param token
+ * - the token that resumes this activity
+ * @param resumeObject
+ * - an object that is passed from class that resumes the Token
*/
@Override
public void resume(Token token, Object resumeObject) {
-
+
+ }
+
+ @Override
+ public String toString() {
+
+ return getClass().getSimpleName();
+ }
+
+ /**
+ * It is a utility method that can be used to throw an exception which is also logged.
+ *
+ * @param errorMessage
+ * - that message that describes the exception
+ */
+ protected void logAndThrowError(String errorMessage) {
+
+ logger.error(errorMessage);
+ throw new JodaEngineRuntimeException(errorMessage);
}
}
View
9 engine-core-impl/src/main/java/org/jodaengine/node/activity/AbstractCancelableActivity.java
@@ -4,7 +4,8 @@
import org.jodaengine.process.token.Token;
/**
- * This class provides some helper methods for activities that has a more extended canceling mechanism like {@link BpmnHumanTaskActivity}, ... .
+ * This class provides some helper methods for activities that has a more extended canceling mechanism like
+ * {@link BpmnHumanTaskActivity}, ... .
*/
public abstract class AbstractCancelableActivity extends AbstractActivity {
@@ -12,8 +13,10 @@
* This method returns the identifier for an internalVariable. The identifier should be unique, as the token can
* only work on one activity at a time.
*
- * @param prefix - the prefix of the variable
- * @param token - the token where the variable belongs to
+ * @param prefix
+ * - the prefix of the variable
+ * @param token
+ * - the token where the variable belongs to
* @return a String representing the identifier
*/
protected static final String internalVariableId(String prefix, Token token) {
View
71 engine-core-impl/src/main/java/org/jodaengine/node/activity/bpmn/BpmnEventBasedXorGateway.java
@@ -8,13 +8,12 @@
import org.jodaengine.eventmanagement.subscription.ProcessEventGroup;
import org.jodaengine.eventmanagement.subscription.ProcessIntermediateEvent;
import org.jodaengine.node.activity.AbstractCancelableActivity;
-import org.jodaengine.node.activity.Activity;
import org.jodaengine.process.structure.Node;
import org.jodaengine.process.structure.Transition;
import org.jodaengine.process.token.Token;
/**
- * This {@link Activity} represents the event-based gateway used in the BPMN.
+ * This {@link BpmnEventBasedXorGateway Activity} represents the event-based gateway used in the BPMN.
*/
public class BpmnEventBasedXorGateway extends AbstractCancelableActivity {
@@ -32,11 +31,17 @@ protected void executeIntern(Token token) {
for (Transition transition : token.getCurrentNode().getOutgoingTransitions()) {
Node node = transition.getDestination();
+
+ // This node needs to trigger create processIntermediateEvents for the node that are attached to him
+ // That's why we need to check whether the activity of the next node allows the creation of
+ // processIntermediateEvents
if (node.getActivityBehaviour() instanceof BpmnEventBasedGatewayEvent) {
BpmnEventBasedGatewayEvent eventBasedGatewayEvent = (BpmnEventBasedGatewayEvent) node
.getActivityBehaviour();
- ProcessIntermediateEvent processEvent = eventBasedGatewayEvent.createProcessIntermediateEventInEventGroup(token, eventXorGroup);
+ // Creating a processIntermediateEvent
+ ProcessIntermediateEvent processEvent = eventBasedGatewayEvent
+ .createProcessIntermediateEventInEventGroup(token, eventXorGroup);
// Setting the node that has fired the event; the node is not that one the execution is currently
// pointing at but rather the node that contained the event
processEvent.setFireringNode(node);
@@ -46,14 +51,21 @@ protected void executeIntern(Token token) {
// Subscribing on the event
eventManager.registerIntermediateEvent(processEvent);
- // // Putting the intermediate Events in the queue for later reference
- // registeredIntermediateEvents.add(processEvent);
+ // Putting the intermediate Events in the queue for later reference
+ registeredIntermediateEvents.add(processEvent);
+ } else {
+
+ String errorMessage = "The node '" + node.toString() + "' with the activity '"
+ + node.getActivityBehaviour().toString()
+ + "' cannot create a ProcessIntermediateEvent. Needs to be of the type BpmnEventBasedGatewayEvent.";
+ logAndThrowError(errorMessage);
}
}
- // Storing the list of intermediateProcessEvents as internal varibale for later reference
- // token.setInternalVariable(internalVariableId(REGISTERED_PROCESS_EVENT_PREFIX, token),
- // registeredIntermediateEvents);
+ // Storing the list of registered intermediateProcessEvents as internal variable for later reference
+ // (see canceling)
+ token.setInternalVariable(internalVariableId(REGISTERED_PROCESS_EVENT_PREFIX, token),
+ registeredIntermediateEvents);
token.suspend();
}
@@ -65,46 +77,29 @@ public void resume(Token token, Object resumeObject) {
logger.debug("The resumeObject '{}' is not a ProcessIntermediateEvent.", resumeObject);
}
+ // Each processIntermediateEvent knows which node is waiting for the event to fire
ProcessIntermediateEvent intermediateProcessEvent = (ProcessIntermediateEvent) resumeObject;
-
- // Maybe checking if it is in the list of registered events
-
- // @SuppressWarnings("unchecked")
- // List<ProcessIntermediateEvent> registeredIntermediateEvents = (List<ProcessIntermediateEvent>) token
- // .getInternalVariable(internalVariableId(REGISTERED_PROCESS_EVENT_PREFIX, token));
- //
- // if (!registeredIntermediateEvents.remove(intermediateProcessEvent)) {
- // // Then it means the element that should be deleted was not in the list of registered Events
- // String errorMessage = "The event-based Xor Gateway was resumed by an event that it has not registered.";
- // logger.error(errorMessage);
- // throw new JodaEngineRuntimeException(errorMessage);
- // }
-
- // unsubscribingFrom(registeredIntermediateEvents);
-
Node nodeToSkip = intermediateProcessEvent.getFireringNode();
- // Define the new starting point of the token; the new starting point is one of the nodes that comes right after
- // that one
+
+ // Define where the token continue his execution
+ // In this case it starts at the outgoingbehavior of the node that represents the intermediateEvent
token.setCurrentNode(nodeToSkip);
+
+ // The ProcessEventGroup already takes care of unsubscribing from the other event
}
- private void unsubscribingFrom(List<ProcessIntermediateEvent> registeredIntermediateEvents) {
+ @Override
+ public void cancel(Token executingToken) {
- // Unsubscribing the other registered events; doing it as early as possible
+ // Extracting the variable
+ @SuppressWarnings("unchecked")
+ List<ProcessIntermediateEvent> registeredIntermediateEvents = (List<ProcessIntermediateEvent>) executingToken
+ .getInternalVariable(internalVariableId(REGISTERED_PROCESS_EVENT_PREFIX, executingToken));
- // TODO @Gerardo muss geändert werden keine ServiceFactory mehr - vielleicht im Token
+ // Unsubscribing from all processIntermediateEvents
EventSubscriptionManager eventManager = ServiceFactory.getCorrelationService();
for (ProcessIntermediateEvent registeredProcessEvent : registeredIntermediateEvents) {
eventManager.unsubscribeFromIntermediateEvent(registeredProcessEvent);
}
}
-
- @Override
- public void cancel(Token executingToken) {
-
- // TODO @Gerardo zuvor Test schreiben
- // TODO @Gerardo Implementing canceling all registered ProcessIntermediateEvents
-
- super.cancel(executingToken);
- }
}
View
7 engine-core-impl/src/main/java/org/jodaengine/node/activity/bpmn/BpmnTimerIntermediateEventActivity.java
@@ -43,8 +43,7 @@ protected void executeIntern(@Nonnull Token token) {
eventManager.registerIntermediateEvent(processEvent);
// the name should be unique, as the token can only work on one activity at a time.
- final String itemContextVariableId = internalVariableId(PROCESS_EVENT_PREFIX, token);
- token.setInternalVariable(itemContextVariableId, processEvent);
+ token.setInternalVariable(internalVariableId(PROCESS_EVENT_PREFIX, token), processEvent);
token.suspend();
}
@@ -52,10 +51,8 @@ protected void executeIntern(@Nonnull Token token) {
@Override
public void cancel(Token executingToken) {
- final String itemContextVariableId = internalVariableId(PROCESS_EVENT_PREFIX, executingToken);
-
ProcessIntermediateEvent intermediateEvent = (ProcessIntermediateEvent) executingToken
- .getInternalVariable(itemContextVariableId);
+ .getInternalVariable(internalVariableId(PROCESS_EVENT_PREFIX, executingToken));
EventSubscriptionManager eventManager = ServiceFactory.getCorrelationService();
eventManager.unsubscribeFromIntermediateEvent(intermediateEvent);
View
45 engine-core-impl/src/test/java/org/jodaengine/node/activity/bpmn/BpmnEventBasedXorGatewayTest.java
@@ -30,17 +30,14 @@
*/
public class BpmnEventBasedXorGatewayTest extends AbstractJodaEngineTest {
+ protected static final int WAITING_TIME = 100;
+
private static final String NAME_MANUAL_TRIGGER2 = "manualTrigger2";
private static final String NAME_MANUAL_TRIGGER1 = "manualTrigger1";
+
protected Token token;
protected Node eventBasedXorGatewayNode, intermediateEvent1Node, intermediateEvent2Node, endNode1, endNode2;
- // CHECKSTYLE:OFF
- protected static int waiting_time_1 = 300;
- protected static int waiting_time_2 = 600;
- // CHECKSTYLE:ON
- protected static final int LONG_WAITING_TIME_TEST = 1200;
-
/**
* SetUp.
*/
@@ -66,18 +63,21 @@ public void tearDown() {
ManualTriggeringAdapter.resetManualTriggeringAdapter();
}
+ // === Tests are following ===
+
/**
* The normal routing behavior.
*
* @throws Exception
+ * - if it fails
*/
@Test
- public void testRouting()
+ public void testNormalExecution()
throws Exception {
token.executeStep();
- Thread.sleep(LONG_WAITING_TIME_TEST);
+ Thread.sleep(WAITING_TIME);
ManualTriggeringAdapter.triggerManually(NAME_MANUAL_TRIGGER1);
@@ -95,6 +95,33 @@ public void testRouting()
}
/**
+ * Tests the behavior when the Activity is canceled while it is still active.
+ *
+ * @throws Exception
+ * - if it fails
+ */
+ @Test
+ public void testCancelation()
+ throws Exception {
+
+ token.executeStep();
+
+ Thread.sleep(WAITING_TIME);
+
+ // Canceling the execution
+ token.cancelExecution();
+
+ // Now any ProcessIntermediateEvents should have been registered
+ ManualTriggeringAdapter manualTriggeringAdapterToAssert1 = ManualTriggeringAdapter
+ .getManualTriggeringAdapter(NAME_MANUAL_TRIGGER1);
+ ManualTriggeringAdapter manualTriggeringAdapterToAssert2 = ManualTriggeringAdapter
+ .getManualTriggeringAdapter(NAME_MANUAL_TRIGGER2);
+
+ Assert.assertTrue(manualTriggeringAdapterToAssert1.getProcessEvents().isEmpty());
+ Assert.assertTrue(manualTriggeringAdapterToAssert2.getProcessEvents().isEmpty());
+ }
+
+ /**
* Builds the graph structure of the little test definition that should be tested.
*/
protected void buildProcessGraph() {
@@ -142,6 +169,8 @@ protected String errorMessage() {
*
* @param defBuilder
* - the {@link ProcessDefinitionBuilder} in order to build the {@link Node}
+ * @param name
+ * - the name of the {@link ManualTriggeringAdapter}
* @return the created {@link Node}
*/
protected static Node createBpmnManualTriggeringIntermediateEventNode(ProcessDefinitionBuilder defBuilder,
Please sign in to comment.
Something went wrong with that request. Please try again.