Search in sources :

Example 41 with ProcessModel

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

the class InclusiveGatewayEventPlugin method eventRoutine.

// @SuppressWarnings("unchecked")
@Override
public void eventRoutine(GatewayEvent desmojEvent, ProcessInstance processInstance) throws ScyllaRuntimeException {
    SimulationModel model = (SimulationModel) desmojEvent.getModel();
    ProcessModel processModel = processInstance.getProcessModel();
    int nodeId = desmojEvent.getNodeId();
    boolean showInTrace = desmojEvent.traceIsOn();
    GatewayType type = processModel.getGateways().get(nodeId);
    try {
        Set<Integer> idsOfNextNodes = processModel.getIdsOfNextNodes(nodeId);
        if (idsOfNextNodes.size() > 1) {
            // split
            if (type == GatewayType.INCLUSIVE) {
            // TODO this is incomplete, must find corresponding join gateway and define behavior for it
            // Map<Integer, Object> branchingDistributions = desmojObjects.getDistributionsExtensional()
            // .get(getName());
            // Map<Integer, BoolDistBernoulli> distributions = (Map<Integer, BoolDistBernoulli>)
            // branchingDistributions
            // .get(nodeId);
            // Set<Integer> idsOfNodesToBeActivated = new HashSet<Integer>();
            // for (Integer nextFlowId : distributions.keySet()) {
            // BoolDistBernoulli distribution = distributions.get(nextFlowId);
            // if (!processModel.getIdentifiers().keySet().contains(nextFlowId)) {
            // throw new ScyllaValidationException("Flow with id " + nextFlowId + " does not exist.");
            // }
            // boolean activateOutgoingFlow = distribution.sample();
            // if (activateOutgoingFlow) {
            // Set<Integer> nodeIds = processModel.getTargetObjectIds(nextFlowId);
            // if (nodeIds.size() != 1) {
            // throw new ScyllaValidationException("Flow " + nextFlowId
            // + " does not connect to 1 node, but" + nodeIds.size() + " .");
            // }
            // int nextNodeId = nodeIds.iterator().next();
            // 
            // idsOfNodesToBeActivated.add(nextNodeId);
            // }
            // // TODO default flow
            // }
            // 
            // Map<Integer, ScyllaEvent> nextEventMap = desmojEvent.getNextEventMap();
            // List<Integer> indicesOfEventsToKeep = new ArrayList<Integer>();
            // for (int index : nextEventMap.keySet()) {
            // ScyllaEvent eventCandidate = nextEventMap.get(index);
            // int nodeIdOfCandidate = eventCandidate.getNodeId();
            // if (idsOfNodesToBeActivated.contains(nodeIdOfCandidate)) {
            // indicesOfEventsToKeep.add(index);
            // }
            // }
            // Map<Integer, TimeSpan> timeSpanToNextEventMap = desmojEvent.getTimeSpanToNextEventMap();
            // nextEventMap.keySet().retainAll(indicesOfEventsToKeep);
            // timeSpanToNextEventMap.keySet().retainAll(indicesOfEventsToKeep);
            }
        }
    } catch (NodeNotFoundException | ScyllaValidationException e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        SimulationUtils.abort(model, processInstance, nodeId, showInTrace);
        return;
    }
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) NodeNotFoundException(de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException) GatewayType(de.hpi.bpt.scylla.model.process.node.GatewayType) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Example 42 with ProcessModel

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

the class InclusiveGatewaySCParserPlugin method parse.

@Override
public Map<String, Object> parse(SimulationConfiguration simulationInput, Element sim) throws ScyllaValidationException {
    Map<Integer, BranchingBehavior> branchingBehaviors = new HashMap<Integer, BranchingBehavior>();
    Namespace simNamespace = sim.getNamespace();
    ProcessModel processModel = simulationInput.getProcessModel();
    for (Element el : sim.getChildren()) {
        String elementName = el.getName();
        if (elementName.equals("inclusiveGateway")) {
            String identifier = el.getAttributeValue("id");
            if (identifier == null) {
                DebugLogger.log("Warning: Simulation configuration definition element '" + elementName + "' does not have an identifier, skip.");
                // no matching element in process, so skip definition
                continue;
            }
            Integer nodeId = processModel.getIdentifiersToNodeIds().get(identifier);
            if (nodeId == null) {
                DebugLogger.log("Simulation configuration definition for process element '" + identifier + "', but not available in process, skip.");
                // no matching element in process, so skip definition
                continue;
            }
            List<Element> outgoingSequenceFlows = el.getChildren("outgoingSequenceFlow", simNamespace);
            if (outgoingSequenceFlows.size() > 0) {
                Map<Integer, Double> branchingProbabilities = new HashMap<Integer, Double>();
                for (Element elem : outgoingSequenceFlows) {
                    Integer nodeIdOfSequenceFlow = processModel.getIdentifiersToNodeIds().get(elem.getAttributeValue("id"));
                    if (nodeIdOfSequenceFlow != null) {
                        Double branchingProbability = Double.valueOf(elem.getChildText("branchingProbability", simNamespace));
                        if (branchingProbability < 0 || branchingProbability > 1) {
                            throw new ScyllaValidationException("Inclusive gateway branching probability for " + identifier + " is out of bounds [0,1].");
                        }
                        branchingProbabilities.put(nodeIdOfSequenceFlow, branchingProbability);
                    }
                }
                BranchingBehavior branchingBehavior = new BranchingBehavior(branchingProbabilities);
                branchingBehaviors.put(nodeId, branchingBehavior);
            }
        }
    }
    HashMap<String, Object> extensionAttributes = new HashMap<String, Object>();
    extensionAttributes.put("branchingBehaviors", branchingBehaviors);
    return extensionAttributes;
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) HashMap(java.util.HashMap) BranchingBehavior(de.hpi.bpt.scylla.model.configuration.BranchingBehavior) Element(org.jdom2.Element) Namespace(org.jdom2.Namespace) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException)

Example 43 with ProcessModel

use of de.hpi.bpt.scylla.model.process.ProcessModel 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 desmojObjects = desmojEvent.getDesmojObjects();
            ProcessSimulationComponents parentDesmojObjects = desmojObjects.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 44 with ProcessModel

use of de.hpi.bpt.scylla.model.process.ProcessModel 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 desmojObjects = desmojEvent.getDesmojObjects();
        SimulationModel model = (SimulationModel) desmojEvent.getModel();
        TimeInstant currentSimulationTime = model.presentTime();
        boolean showInTrace = model.traceIsOn();
        int processInstanceId = processInstance.getId();
        try {
            ProcessSimulationComponents desmojObjectsOfSubProcess = desmojObjects.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 45 with ProcessModel

use of de.hpi.bpt.scylla.model.process.ProcessModel 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.getDesmojObjects(), 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

ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)73 SimulationModel (de.hpi.bpt.scylla.simulation.SimulationModel)42 TimeSpan (desmoj.core.simulator.TimeSpan)26 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)22 NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)19 ScyllaRuntimeException (de.hpi.bpt.scylla.exception.ScyllaRuntimeException)18 ProcessInstance (de.hpi.bpt.scylla.simulation.ProcessInstance)18 ScyllaEvent (de.hpi.bpt.scylla.simulation.event.ScyllaEvent)16 Map (java.util.Map)16 HashMap (java.util.HashMap)14 ProcessNodeInfo (de.hpi.bpt.scylla.logger.ProcessNodeInfo)13 ProcessSimulationComponents (de.hpi.bpt.scylla.simulation.ProcessSimulationComponents)13 Element (org.jdom2.Element)13 TimeInstant (desmoj.core.simulator.TimeInstant)12 HashSet (java.util.HashSet)12 SimulationConfiguration (de.hpi.bpt.scylla.model.configuration.SimulationConfiguration)10 TimeUnit (java.util.concurrent.TimeUnit)10 EventDefinitionType (de.hpi.bpt.scylla.model.process.node.EventDefinitionType)8 ArrayList (java.util.ArrayList)8 Namespace (org.jdom2.Namespace)8