Search in sources :

Example 6 with TaskTerminateEvent

use of de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent in project scylla by bptlab.

the class BatchCluster method taskCancelEvent.

public void taskCancelEvent(TaskCancelEvent event) throws ScyllaRuntimeException {
    for (TaskTerminateEvent pee : parentalEndEvents) {
        TaskCancelEvent cancelEvent = new TaskCancelEvent(pee.getModel(), pee.getSource(), pee.getSimulationTimeOfSource(), pee.getSimulationComponents(), pee.getProcessInstance(), pee.getNodeId());
        cancelEvent.schedule(pee.getProcessInstance());
    }
    parentalEndEvents.clear();
    BatchPluginUtils.getInstance().setClusterToTerminated(getResponsibleProcessInstance(), getBatchActivity().getNodeId());
}
Also used : TaskCancelEvent(de.hpi.bpt.scylla.simulation.event.TaskCancelEvent) TaskTerminateEvent(de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent)

Example 7 with TaskTerminateEvent

use of de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent in project scylla by bptlab.

the class BatchCluster method endEvent.

public void endEvent(BPMNEndEvent event) {
    ProcessInstance processInstance = event.getProcessInstance();
    BatchPluginUtils pluginInstance = BatchPluginUtils.getInstance();
    setProcessInstanceToFinished();
    // Schedule them only if either all process instances has passed the last event of the batch activity or the execution type is parallel
    if (isFinished()) {
        if (pluginInstance.isProcessInstanceCompleted(processInstance)) {
            List<TaskTerminateEvent> parentalEndEvents = getParentalEndEvents();
            for (TaskTerminateEvent pee : parentalEndEvents) {
                pee.schedule();
            }
            parentalEndEvents.clear();
            pluginInstance.setClusterToTerminated(getResponsibleProcessInstance(), getBatchActivity().getNodeId());
        }
        // Prevent parental task terminate event from scheduling, if there is any (from subprocess plugin)
        Map<Integer, ScyllaEvent> nextEventMap = event.getNextEventMap();
        if (!nextEventMap.isEmpty()) {
            // TODO this is currently not covered, when is it called?
            Map<Integer, TimeSpan> timeSpanToNextEventMap = event.getTimeSpanToNextEventMap();
            int indexOfParentalTaskTerminateEvent = 0;
            nextEventMap.remove(indexOfParentalTaskTerminateEvent);
            timeSpanToNextEventMap.remove(indexOfParentalTaskTerminateEvent);
        }
    }
}
Also used : TimeSpan(desmoj.core.simulator.TimeSpan) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent) TaskTerminateEvent(de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent)

Example 8 with TaskTerminateEvent

use of de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent in project scylla by bptlab.

the class SubprocessBPMNEEPlugin method eventRoutine.

@Override
public void eventRoutine(BPMNEndEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
    ProcessModel processModel = processInstance.getProcessModel();
    if (processModel.getParent() != null && processInstanceIsCompleted(processInstance)) {
        // works
        try {
            ProcessSimulationComponents simulationComponents = desmojEvent.getSimulationComponents();
            ProcessSimulationComponents parentDesmojObjects = simulationComponents.getParent();
            ProcessModel parentModel = processModel.getParent();
            int nodeIdInParent = processModel.getNodeIdInParent();
            ProcessInstance parentProcessInstance = processInstance.getParent();
            // behavior when sub-process sends events:
            // none -> back to normal flow
            // message -> "send it"
            // error -> to parent
            // escalation -> to parent
            // cancel -> nonono!
            // compensation -> ... not now
            // signal -> ... not now
            // terminate -> terminate sub-process (kill all events of sub-process instance (MI sub-process
            // not affected))
            // ...
            // timer -> special treatment
            Set<Integer> idsOfNextNodes = parentModel.getIdsOfNextNodes(nodeIdInParent);
            // normal flow: must not have more than one successor
            if (idsOfNextNodes.size() != 1) {
                int nodeId = desmojEvent.getNodeId();
                throw new ScyllaValidationException("Subprocess " + nodeId + " does not have 1 successor, but " + idsOfNextNodes.size() + ".");
            }
            Integer nextNodeId = idsOfNextNodes.iterator().next();
            // TODO let the parent create the next node, so remove the lines below
            List<ScyllaEvent> events = SimulationUtils.createEventsForNextNode(desmojEvent, parentDesmojObjects, parentProcessInstance, nextNodeId);
            // next event occurs immediately after start event
            TimeSpan timeSpan = new TimeSpan(0);
            String parentProcessInstanceName = parentProcessInstance.getName();
            SubprocessPluginUtils pluginInstance = SubprocessPluginUtils.getInstance();
            TaskTerminateEvent eventOfParent = pluginInstance.getEventsOnHold().get(parentProcessInstanceName).get(nodeIdInParent);
            if (eventOfParent != null) {
                events.add(eventOfParent);
                pluginInstance.getEventsOnHold().get(parentProcessInstanceName).remove(nodeIdInParent);
                pluginInstance.getNameOfEventsThatWereOnHold().add(eventOfParent.getName());
            }
            for (ScyllaEvent event : events) {
                int index = desmojEvent.getNewEventIndex();
                desmojEvent.getNextEventMap().put(index, event);
                desmojEvent.getTimeSpanToNextEventMap().put(index, timeSpan);
            }
        } catch (NodeNotFoundException | ScyllaValidationException | ScyllaRuntimeException e) {
            SimulationModel model = (SimulationModel) desmojEvent.getModel();
            int nodeId = desmojEvent.getNodeId();
            boolean showInTrace = model.traceIsOn();
            DebugLogger.error(e.getMessage());
            e.printStackTrace();
            SimulationUtils.abort(model, processInstance, nodeId, showInTrace);
        }
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent) TaskTerminateEvent(de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent) 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) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 9 with TaskTerminateEvent

use of de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent in project scylla by bptlab.

the class SubprocessTBPlugin method eventRoutine.

@Override
public void eventRoutine(TaskBeginEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
    ProcessModel processModel = processInstance.getProcessModel();
    int nodeId = desmojEvent.getNodeId();
    ProcessModel subProcess = processModel.getSubProcesses().get(nodeId);
    if (subProcess != null) {
        int indexOfTaskTerminateEvent = 0;
        desmojEvent.getTimeSpanToNextEventMap().remove(indexOfTaskTerminateEvent);
        TaskTerminateEvent event = (TaskTerminateEvent) desmojEvent.getNextEventMap().get(indexOfTaskTerminateEvent);
        String name = processInstance.getName();
        SubprocessPluginUtils pluginInstance = SubprocessPluginUtils.getInstance();
        Map<Integer, TaskTerminateEvent> eventsOnHoldMap = pluginInstance.getEventsOnHold().get(name);
        if (eventsOnHoldMap == null) {
            pluginInstance.getEventsOnHold().put(name, new HashMap<Integer, TaskTerminateEvent>());
        }
        pluginInstance.getEventsOnHold().get(name).put(nodeId, event);
        desmojEvent.getNextEventMap().remove(indexOfTaskTerminateEvent);
        String source = desmojEvent.getSource();
        ProcessSimulationComponents simulationComponents = desmojEvent.getSimulationComponents();
        SimulationModel model = (SimulationModel) desmojEvent.getModel();
        TimeInstant currentSimulationTime = model.presentTime();
        boolean showInTrace = model.traceIsOn();
        int processInstanceId = processInstance.getId();
        try {
            ProcessSimulationComponents desmojObjectsOfSubProcess = simulationComponents.getChildren().get(nodeId);
            Integer startNodeId = subProcess.getStartNode();
            ProcessInstance subProcessInstance = new ProcessInstance(model, subProcess, processInstanceId, showInTrace);
            subProcessInstance.setParent(processInstance);
            ScyllaEvent subProcessEvent = new BPMNStartEvent(model, source, currentSimulationTime, desmojObjectsOfSubProcess, subProcessInstance, startNodeId);
            TimeSpan timeSpan = new TimeSpan(0);
            int index = desmojEvent.getNewEventIndex();
            desmojEvent.getNextEventMap().put(index, subProcessEvent);
            desmojEvent.getTimeSpanToNextEventMap().put(index, timeSpan);
        } catch (NodeNotFoundException | MultipleStartNodesException | NoStartNodeException e) {
            DebugLogger.error(e.getMessage());
            DebugLogger.log("Start node of process model " + subProcess.getId() + " not found.");
            throw new ScyllaRuntimeException("Start node of process model " + subProcess.getId() + " not found.");
        }
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ScyllaEvent(de.hpi.bpt.scylla.simulation.event.ScyllaEvent) TaskTerminateEvent(de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent) MultipleStartNodesException(de.hpi.bpt.scylla.model.process.graph.exception.MultipleStartNodesException) TimeSpan(desmoj.core.simulator.TimeSpan) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) ProcessSimulationComponents(de.hpi.bpt.scylla.simulation.ProcessSimulationComponents) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance) BPMNStartEvent(de.hpi.bpt.scylla.simulation.event.BPMNStartEvent) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) TimeInstant(desmoj.core.simulator.TimeInstant) NoStartNodeException(de.hpi.bpt.scylla.model.process.graph.exception.NoStartNodeException)

Example 10 with TaskTerminateEvent

use of de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent in project scylla by bptlab.

the class SubprocessTCPlugin method eventRoutine.

@Override
public void eventRoutine(TaskCancelEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
    ProcessModel processModel = processInstance.getProcessModel();
    if (processModel.getParent() != null) {
        int nodeIdInParent = processModel.getNodeIdInParent();
        ProcessInstance parentProcessInstance = processInstance.getParent();
        String parentProcessInstanceName = parentProcessInstance.getName();
        SubprocessPluginUtils pluginInstance = SubprocessPluginUtils.getInstance();
        Map<Integer, TaskTerminateEvent> eventsOnHoldMap = pluginInstance.getEventsOnHold().get(parentProcessInstanceName);
        TaskTerminateEvent event = eventsOnHoldMap.get(nodeIdInParent);
        if (event != null) {
            SimulationModel model = (SimulationModel) event.getModel();
            String source = event.getSource();
            TaskCancelEvent cancelEvent = new TaskCancelEvent(model, source, event.getSimulationTimeOfSource(), event.getSimulationComponents(), event.getProcessInstance(), event.getNodeId());
            cancelEvent.schedule(parentProcessInstance, new TimeSpan(0));
            eventsOnHoldMap.remove(nodeIdInParent);
        }
    }
}
Also used : TimeSpan(desmoj.core.simulator.TimeSpan) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) TaskCancelEvent(de.hpi.bpt.scylla.simulation.event.TaskCancelEvent) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance) TaskTerminateEvent(de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Aggregations

TaskTerminateEvent (de.hpi.bpt.scylla.simulation.event.TaskTerminateEvent)10 ProcessInstance (de.hpi.bpt.scylla.simulation.ProcessInstance)8 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)7 ScyllaEvent (de.hpi.bpt.scylla.simulation.event.ScyllaEvent)6 TimeSpan (desmoj.core.simulator.TimeSpan)6 ProcessSimulationComponents (de.hpi.bpt.scylla.simulation.ProcessSimulationComponents)4 SimulationModel (de.hpi.bpt.scylla.simulation.SimulationModel)4 TaskCancelEvent (de.hpi.bpt.scylla.simulation.event.TaskCancelEvent)4 ScyllaRuntimeException (de.hpi.bpt.scylla.exception.ScyllaRuntimeException)3 BPMNStartEvent (de.hpi.bpt.scylla.simulation.event.BPMNStartEvent)3 NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)2 TaskBeginEvent (de.hpi.bpt.scylla.simulation.event.TaskBeginEvent)2 TimeInstant (desmoj.core.simulator.TimeInstant)2 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)1 ProcessNodeInfo (de.hpi.bpt.scylla.logger.ProcessNodeInfo)1 ProcessNodeTransitionType (de.hpi.bpt.scylla.logger.ProcessNodeTransitionType)1 MultipleStartNodesException (de.hpi.bpt.scylla.model.process.graph.exception.MultipleStartNodesException)1 NoStartNodeException (de.hpi.bpt.scylla.model.process.graph.exception.NoStartNodeException)1 ResourceObjectTuple (de.hpi.bpt.scylla.simulation.ResourceObjectTuple)1 BPMNEndEvent (de.hpi.bpt.scylla.simulation.event.BPMNEndEvent)1