Search in sources :

Example 6 with EventDefinitionType

use of de.hpi.bpt.scylla.model.process.node.EventDefinitionType in project scylla by bptlab.

the class BPMNEndEvent method eventRoutine.

@Override
public void eventRoutine(ProcessInstance processInstance) throws SuspendExecution {
    super.eventRoutine(processInstance);
    SimulationModel model = (SimulationModel) getModel();
    ProcessModel processModel = processInstance.getProcessModel();
    try {
        Map<EventDefinitionType, Map<String, String>> definitions = processModel.getEventDefinitions().get(nodeId);
        Set<String> messages = new HashSet<String>();
        for (EventDefinitionType definition : definitions.keySet()) {
            if (definition == EventDefinitionType.MESSAGE) {
                String message = "Message End Event: " + displayName;
                messages.add(message);
            } else if (definition == EventDefinitionType.ESCALATION) {
                String message = "Escalation End Event: " + displayName;
                messages.add(message);
            } else if (definition == EventDefinitionType.ERROR) {
                String message = "Error End Event: " + displayName;
                messages.add(message);
            } else if (definition == EventDefinitionType.CANCEL) {
                String message = "Cancel End Event: " + displayName;
                messages.add(message);
            // TODO for transaction subprocesses only
            } else if (definition == EventDefinitionType.COMPENSATION) {
                String message = "Compensation End Event: " + displayName;
                messages.add(message);
            // TODO run compensation
            } else if (definition == EventDefinitionType.SIGNAL) {
                String message = "Signal End Event: " + displayName;
                messages.add(message);
            } else if (definition == EventDefinitionType.TERMINATE) {
                String message = "Terminate End Event: " + displayName;
                messages.add(message);
                // unschedule events of this process instance
                processInstance.cancel();
            }
        }
        if (messages.isEmpty()) {
            String message = "None End Event: " + displayName;
            messages.add(message);
        }
        for (String message : messages) {
            sendTraceNote(message);
        }
        // unless current one is BPMN timer event with timerDuration
        BPMNEndEventPluggable.runPlugins(this, processInstance);
        scheduleNextEvents();
        if (!QueueManager.isAnyEventScheduledOrQueued(model)) {
            model.getExperiment().stop();
        }
    } catch (ScyllaRuntimeException e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) EventDefinitionType(de.hpi.bpt.scylla.model.process.node.EventDefinitionType) Map(java.util.Map) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) HashSet(java.util.HashSet)

Example 7 with EventDefinitionType

use of de.hpi.bpt.scylla.model.process.node.EventDefinitionType in project scylla by bptlab.

the class BPMNIntermediateEvent method eventRoutine.

@Override
public void eventRoutine(ProcessInstance processInstance) throws SuspendExecution {
    super.eventRoutine(processInstance);
    SimulationModel model = (SimulationModel) getModel();
    ProcessModel processModel = processInstance.getProcessModel();
    try {
        EventType type = processModel.getEventTypes().get(nodeId);
        // Long duration = null;
        // TimeUnit timeUnit = null;
        Map<EventDefinitionType, Map<String, String>> definitions = processModel.getEventDefinitions().get(nodeId);
        Set<String> messages = new HashSet<String>();
        for (EventDefinitionType definition : definitions.keySet()) {
            // TODO what about implicit throw events?
            if (definition == EventDefinitionType.CANCEL) {
                // TODO: cancel event only in transaction sub-process
                // isInterrupting?
                boolean cancelActivity = processModel.getCancelActivities().get(nodeId);
                if (type == EventType.BOUNDARY && cancelActivity) {
                    String message = "Boundary Cancel Event: " + displayName;
                    messages.add(message);
                } else {
                    SimulationUtils.sendElementNotSupportedTraceNote(model, processModel, displayName, nodeId);
                    SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
                    return;
                }
            } else if (definition == EventDefinitionType.COMPENSATION) {
                // isInterrupting?
                boolean cancelActivity = processModel.getCancelActivities().get(nodeId);
                if (type == EventType.BOUNDARY && cancelActivity) {
                    String message = "Boundary Compensation Event: " + displayName;
                    messages.add(message);
                } else {
                    SimulationUtils.sendElementNotSupportedTraceNote(model, processModel, displayName, nodeId);
                    SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
                    return;
                }
            } else if (definition == EventDefinitionType.CONDITIONAL) {
                if (type == EventType.BOUNDARY) {
                    // isInterrupting?
                    boolean cancelActivity = processModel.getCancelActivities().get(nodeId);
                    if (cancelActivity) {
                        String message = "Boundary Conditional Event (Interrupting): " + displayName;
                        messages.add(message);
                    } else {
                        String message = "Boundary Conditional Event (Non-Interrupting): " + displayName;
                        messages.add(message);
                    }
                } else if (type == EventType.INTERMEDIATE_CATCH) {
                    String message = "Intermediate Conditional Event (Catching): " + displayName;
                    messages.add(message);
                } else {
                    SimulationUtils.sendElementNotSupportedTraceNote(model, processModel, displayName, nodeId);
                    SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
                    return;
                }
            } else if (definition == EventDefinitionType.ERROR) {
                // isInterrupting?
                boolean cancelActivity = processModel.getCancelActivities().get(nodeId);
                if (type == EventType.BOUNDARY && cancelActivity) {
                    String message = "Boundary Error Event: " + displayName;
                    messages.add(message);
                } else {
                    SimulationUtils.sendElementNotSupportedTraceNote(model, processModel, displayName, nodeId);
                    SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
                    return;
                }
            } else if (definition == EventDefinitionType.ESCALATION) {
                if (type == EventType.BOUNDARY) {
                    // isInterrupting?
                    boolean cancelActivity = processModel.getCancelActivities().get(nodeId);
                    if (cancelActivity) {
                        String message = "Boundary Escalation Event (Interrupting): " + displayName;
                        messages.add(message);
                    } else {
                        String message = "Boundary Escalation Event (Non-Interrupting): " + displayName;
                        messages.add(message);
                    }
                } else if (type == EventType.INTERMEDIATE_THROW) {
                    String message = "Intermediate Escalation Event (Throwing): " + displayName;
                    messages.add(message);
                } else {
                    SimulationUtils.sendElementNotSupportedTraceNote(model, processModel, displayName, nodeId);
                    SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
                    return;
                }
            } else if (definition == EventDefinitionType.LINK) {
                if (type == EventType.INTERMEDIATE_CATCH) {
                    String message = "Intermediate Link Event (Catching): " + displayName;
                    messages.add(message);
                } else if (type == EventType.INTERMEDIATE_THROW) {
                    String message = "Intermediate Link Event (Throwing): " + displayName;
                    messages.add(message);
                } else {
                    SimulationUtils.sendElementNotSupportedTraceNote(model, processModel, displayName, nodeId);
                    SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
                    return;
                }
            } else if (definition == EventDefinitionType.MESSAGE) {
                if (type == EventType.BOUNDARY) {
                    // isInterrupting?
                    boolean cancelActivity = processModel.getCancelActivities().get(nodeId);
                    if (cancelActivity) {
                        String message = "Boundary Message Event (Interrupting): " + displayName;
                        messages.add(message);
                    } else {
                        String message = "Boundary Message Event (Non-Interrupting): " + displayName;
                        messages.add(message);
                    }
                } else if (type == EventType.INTERMEDIATE_CATCH) {
                    String message = "Intermediate Message Event (Catching): " + displayName;
                    messages.add(message);
                } else if (type == EventType.INTERMEDIATE_THROW) {
                    String message = "Intermediate Message Event (Throwing): " + displayName;
                    messages.add(message);
                } else {
                    SimulationUtils.sendElementNotSupportedTraceNote(model, processModel, displayName, nodeId);
                    SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
                    return;
                }
            } else if (definition == EventDefinitionType.SIGNAL) {
                if (type == EventType.BOUNDARY) {
                    // isInterrupting?
                    boolean cancelActivity = processModel.getCancelActivities().get(nodeId);
                    if (cancelActivity) {
                        String message = "Boundary Signal Event (Interrupting): " + displayName;
                        messages.add(message);
                    } else {
                        String message = "Boundary Signal Event (Non-Interrupting): " + displayName;
                        messages.add(message);
                    }
                } else if (type == EventType.INTERMEDIATE_CATCH) {
                    String message = "Intermediate Signal Event (Catching): " + displayName;
                    messages.add(message);
                } else if (type == EventType.INTERMEDIATE_THROW) {
                    String message = "Intermediate Signal Event (Throwing): " + displayName;
                    messages.add(message);
                } else {
                    SimulationUtils.sendElementNotSupportedTraceNote(model, processModel, displayName, nodeId);
                    SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
                    return;
                }
            } else if (definition == EventDefinitionType.TIMER) {
                if (type == EventType.BOUNDARY) {
                    // isInterrupting?
                    boolean cancelActivity = processModel.getCancelActivities().get(nodeId);
                    if (cancelActivity) {
                        String message = "Boundary Timer Event (Interrupting): " + displayName;
                        messages.add(message);
                    } else {
                        String message = "Boundary Timer Event (Non-Interrupting): " + displayName;
                        messages.add(message);
                    }
                } else if (type == EventType.INTERMEDIATE_CATCH) {
                    String message = "Intermediate Timer Event (Catching): " + displayName;
                    messages.add(message);
                } else {
                    SimulationUtils.sendElementNotSupportedTraceNote(model, processModel, displayName, nodeId);
                    SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
                    return;
                }
            } else {
                // None Event
                if (messages.isEmpty()) {
                    if (type == EventType.INTERMEDIATE_THROW) {
                        String message = "Intermediate None Event (Throwing): " + displayName;
                        messages.add(message);
                    } else {
                        SimulationUtils.sendElementNotSupportedTraceNote(model, processModel, displayName, nodeId);
                        SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
                    }
                }
            }
        }
        for (String message : messages) {
            sendTraceNote(message);
        }
        // get next node(s)
        Set<Integer> idsOfNextNodes = processModel.getIdsOfNextNodes(nodeId);
        // BPMN intermediate event must not have more than successor
        if (idsOfNextNodes.size() != 1) {
            throw new ScyllaValidationException("Event " + nodeId + " does not have 1 successor, but " + idsOfNextNodes.size() + ".");
        }
        Integer nextNodeId = idsOfNextNodes.iterator().next();
        // schedule event for next node
        List<ScyllaEvent> events = SimulationUtils.createEventsForNextNode(this, pSimComponents, processInstance, nextNodeId);
        // next event occurs immediately after start event
        TimeSpan timeSpan = new TimeSpan(0);
        for (ScyllaEvent event : events) {
            int index = getNewEventIndex();
            nextEventMap.put(index, event);
            timeSpanToNextEventMap.put(index, timeSpan);
        }
        // unless current one is BPMN timer event with timerDuration
        BPMNIntermediateEventPluggable.runPlugins(this, processInstance);
        scheduleNextEvents();
    } catch (NodeNotFoundException | ScyllaValidationException | ScyllaRuntimeException e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
        return;
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) EventType(de.hpi.bpt.scylla.model.process.node.EventType) EventDefinitionType(de.hpi.bpt.scylla.model.process.node.EventDefinitionType) TimeSpan(desmoj.core.simulator.TimeSpan) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) Map(java.util.Map) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) HashSet(java.util.HashSet)

Example 8 with EventDefinitionType

use of de.hpi.bpt.scylla.model.process.node.EventDefinitionType in project scylla by bptlab.

the class BPMNStartEvent method eventRoutine.

@Override
public void eventRoutine(ProcessInstance processInstance) throws SuspendExecution {
    super.eventRoutine(processInstance);
    SimulationModel model = (SimulationModel) getModel();
    ProcessModel processModel = processInstance.getProcessModel();
    Map<EventDefinitionType, Map<String, String>> definitions = processModel.getEventDefinitions().get(nodeId);
    Set<String> messages = new HashSet<String>();
    for (EventDefinitionType definition : definitions.keySet()) {
        if (definition == EventDefinitionType.MESSAGE) {
            String message = "Message Start Event: " + displayName;
            messages.add(message);
        } else if (definition == EventDefinitionType.TIMER) {
            String message = "Timer Start Event: " + displayName;
            messages.add(message);
        } else if (definition == EventDefinitionType.CONDITIONAL) {
            String message = "Conditional Start Event: " + displayName;
            messages.add(message);
        } else if (definition == EventDefinitionType.SIGNAL) {
            String message = "Signal Start Event: " + displayName;
            messages.add(message);
        }
    }
    if (messages.isEmpty()) {
        String message = "None Start Event: " + displayName;
        messages.add(message);
    }
    for (String message : messages) {
        sendTraceNote(message);
    }
    try {
        // get next node(s)
        Set<Integer> idsOfNextNodes = processModel.getIdsOfNextNodes(nodeId);
        // BPMN start event must not have more than successor
        if (idsOfNextNodes.size() != 1) {
            throw new ScyllaValidationException("Start event " + nodeId + " does not have 1 successor, but " + idsOfNextNodes.size() + ".");
        }
        Integer nextNodeId = idsOfNextNodes.iterator().next();
        List<ScyllaEvent> events = SimulationUtils.createEventsForNextNode(this, pSimComponents, processInstance, nextNodeId);
        // next event occurs immediately after start event
        TimeSpan timeSpan = new TimeSpan(0);
        for (ScyllaEvent event : events) {
            int index = getNewEventIndex();
            nextEventMap.put(index, event);
            timeSpanToNextEventMap.put(index, timeSpan);
        }
        // unless current one is BPMN timer event with timerDuration
        BPMNStartEventPluggable.runPlugins(this, processInstance);
        scheduleNextEvents();
    } catch (NodeNotFoundException | ScyllaValidationException | ScyllaRuntimeException e) {
        DebugLogger.error(e.getMessage());
        e.printStackTrace();
        SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
        return;
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) EventDefinitionType(de.hpi.bpt.scylla.model.process.node.EventDefinitionType) TimeSpan(desmoj.core.simulator.TimeSpan) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) Map(java.util.Map) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) HashSet(java.util.HashSet)

Example 9 with EventDefinitionType

use of de.hpi.bpt.scylla.model.process.node.EventDefinitionType in project scylla by bptlab.

the class BPMNErrorBPMNEEPlugin method eventRoutine.

@Override
public void eventRoutine(BPMNEndEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
    SimulationModel model = (SimulationModel) desmojEvent.getModel();
    ProcessModel processModel = processInstance.getProcessModel();
    int nodeId = desmojEvent.getNodeId();
    Map<EventDefinitionType, Map<String, String>> definitions = processModel.getEventDefinitions().get(nodeId);
    ProcessSimulationComponents desmojObjects = desmojEvent.getDesmojObjects();
    boolean showInTrace = model.traceIsOn();
    try {
        for (EventDefinitionType definition : definitions.keySet()) {
            if (definition == EventDefinitionType.ERROR) {
                if (processModel.getParent() != null) {
                    Map<String, String> eventAttributes = processModel.getEventDefinitions().get(nodeId).get(definition);
                    String errorRef = eventAttributes.get("errorRef");
                    // Map<String, Map<String, String>> errors = model.getCommonProcessElements().getErrors();
                    // Map<String, String> error = errors.get("errorRef");
                    ProcessSimulationComponents parentDesmojObjects = desmojObjects.getParent();
                    ProcessModel parentModel = processModel.getParent();
                    int nodeIdInParent = processModel.getNodeIdInParent();
                    Integer nextNodeId = null;
                    // find boundary event of parentModel which has the same errorRef
                    List<Integer> referencesToBoundaryEvents = parentModel.getReferencesToBoundaryEvents().get(nodeIdInParent);
                    for (int nId : referencesToBoundaryEvents) {
                        Map<EventDefinitionType, Map<String, String>> boundaryEventDefinitions = parentModel.getEventDefinitions().get(nId);
                        Map<String, String> boundaryErrorEventDefinition = boundaryEventDefinitions.get(EventDefinitionType.ERROR);
                        if (boundaryErrorEventDefinition != null) {
                            if (errorRef.equals(boundaryErrorEventDefinition.get("errorRef"))) {
                                nextNodeId = nId;
                                break;
                            }
                        }
                    }
                    if (nextNodeId == null) {
                        DebugLogger.error("Could not find referenced error " + errorRef + ".");
                        SimulationUtils.abort(model, processInstance, nodeId, showInTrace);
                        return;
                    }
                    ProcessInstance parentProcessInstance = processInstance.getParent();
                    List<ScyllaEvent> events = SimulationUtils.createEventsForNextNode(desmojEvent, parentDesmojObjects, parentProcessInstance, nextNodeId);
                    TimeSpan timeSpan = new TimeSpan(0);
                    /**
                     * first event in the map is the node that comes after the subprocess when normal behavior
                     * applies, so remove it;
                     */
                    int indexOfTaskTerminateEvent = 0;
                    desmojEvent.getNextEventMap().remove(indexOfTaskTerminateEvent);
                    desmojEvent.getTimeSpanToNextEventMap().remove(indexOfTaskTerminateEvent);
                    for (ScyllaEvent event : events) {
                        int index = desmojEvent.getNewEventIndex();
                        desmojEvent.getNextEventMap().put(index, event);
                        desmojEvent.getTimeSpanToNextEventMap().put(index, timeSpan);
                    }
                    processInstance.cancel();
                }
            }
        }
    } catch (NodeNotFoundException | ScyllaValidationException e) {
        DebugLogger.error(e.getMessage());
        e.printStackTrace();
        SimulationUtils.abort(model, processInstance, nodeId, showInTrace);
    }
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) EventDefinitionType(de.hpi.bpt.scylla.model.process.node.EventDefinitionType) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent) TimeSpan(desmoj.core.simulator.TimeSpan) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) ProcessSimulationComponents(de.hpi.bpt.scylla.simulation.ProcessSimulationComponents) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance) Map(java.util.Map) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Aggregations

EventDefinitionType (de.hpi.bpt.scylla.model.process.node.EventDefinitionType)9 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)8 Map (java.util.Map)8 SimulationModel (de.hpi.bpt.scylla.simulation.SimulationModel)7 TimeSpan (desmoj.core.simulator.TimeSpan)7 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)5 NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)5 ScyllaRuntimeException (de.hpi.bpt.scylla.exception.ScyllaRuntimeException)4 ProcessSimulationComponents (de.hpi.bpt.scylla.simulation.ProcessSimulationComponents)4 HashSet (java.util.HashSet)4 EventType (de.hpi.bpt.scylla.model.process.node.EventType)3 ProcessInstance (de.hpi.bpt.scylla.simulation.ProcessInstance)3 ScyllaEvent (de.hpi.bpt.scylla.simulation.event.ScyllaEvent)3 Duration (java.time.Duration)3 TimeUnit (java.util.concurrent.TimeUnit)3 DebugLogger (de.hpi.bpt.scylla.logger.DebugLogger)1 Graph (de.hpi.bpt.scylla.model.process.graph.Graph)1 MultipleStartNodesException (de.hpi.bpt.scylla.model.process.graph.exception.MultipleStartNodesException)1 NoStartNodeException (de.hpi.bpt.scylla.model.process.graph.exception.NoStartNodeException)1 DataObjectType (de.hpi.bpt.scylla.model.process.node.DataObjectType)1