Search in sources :

Example 21 with ScyllaRuntimeException

use of de.hpi.bpt.scylla.exception.ScyllaRuntimeException in project scylla by bptlab.

the class TaskBeginEvent method eventRoutine.

@Override
public void eventRoutine(ProcessInstance processInstance) throws SuspendExecution {
    super.eventRoutine(processInstance);
    SimulationModel model = (SimulationModel) getModel();
    TimeInstant currentSimulationTime = model.presentTime();
    ProcessModel processModel = processInstance.getProcessModel();
    ProcessModel subProcess = processModel.getSubProcesses().get(nodeId);
    TaskType type = processModel.getTasks().get(nodeId);
    String message = null;
    if (subProcess != null) {
        message = "Begin Subprocess: " + displayName;
    } else if (type == TaskType.DEFAULT) {
        message = "Begin Default Task: " + displayName;
    } else if (type == TaskType.SERVICE) {
        message = "Begin Service Task: " + displayName;
    } else if (type == TaskType.SEND) {
        message = "Begin Send Task: " + displayName;
    } else if (type == TaskType.RECEIVE) {
        message = "Begin Receive Task: " + displayName;
    } else if (type == TaskType.USER) {
        message = "Begin User Task: " + displayName;
    } else if (type == TaskType.MANUAL) {
        message = "Begin Manual Task: " + displayName;
    } else if (type == TaskType.BUSINESS_RULE) {
        message = "Begin Business Rule: " + displayName;
    } else if (type == TaskType.SCRIPT) {
        message = "Begin Script Task: " + displayName;
    } else {
        SimulationUtils.sendElementNotSupportedTraceNote(model, processModel, displayName, nodeId);
        SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
        return;
    }
    sendTraceNote(message);
    try {
        double duration = pSimComponents.getDistributionSample(nodeId);
        TimeUnit unit = pSimComponents.getDistributionTimeUnit(nodeId);
        ScyllaEvent event = new TaskTerminateEvent(model, source, currentSimulationTime, pSimComponents, processInstance, nodeId);
        TimeSpan timeSpan = new TimeSpan(duration, unit);
        ResourceObjectTuple tuple = processInstance.getAssignedResources().get(source);
        TimeInstant nextEventTime = DateTimeUtils.getTaskTerminationTime(timeSpan, currentSimulationTime, tuple, event);
        timeSpan = new TimeSpan(nextEventTime.getTimeAsDouble() - currentSimulationTime.getTimeAsDouble());
        int index = getNewEventIndex();
        nextEventMap.put(index, event);
        timeSpanToNextEventMap.put(index, timeSpan);
        TaskBeginEventPluggable.runPlugins(this, processInstance);
        scheduleNextEvents();
    } catch (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) TimeSpan(desmoj.core.simulator.TimeSpan) ResourceObjectTuple(de.hpi.bpt.scylla.simulation.ResourceObjectTuple) TaskType(de.hpi.bpt.scylla.model.process.node.TaskType) TimeUnit(java.util.concurrent.TimeUnit) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) TimeInstant(desmoj.core.simulator.TimeInstant)

Example 22 with ScyllaRuntimeException

use of de.hpi.bpt.scylla.exception.ScyllaRuntimeException in project scylla by bptlab.

the class TaskEnableEvent method eventRoutine.

@Override
public void eventRoutine(ProcessInstance processInstance) throws SuspendExecution {
    super.eventRoutine(processInstance);
    SimulationModel model = (SimulationModel) getModel();
    source = getName();
    TimeInstant currentSimulationTime = model.presentTime();
    ProcessModel processModel = processInstance.getProcessModel();
    // int processInstanceId = processInstance.getId();
    ProcessModel subProcess = processModel.getSubProcesses().get(nodeId);
    TaskType type = processModel.getTasks().get(nodeId);
    String message = null;
    if (subProcess != null) {
        message = "Enable Subprocess: " + displayName;
    } else if (type == TaskType.DEFAULT) {
        message = "Enable Default Task: " + displayName;
    } else if (type == TaskType.SERVICE) {
        message = "Enable Service Task: " + displayName;
    } else if (type == TaskType.SEND) {
        message = "Enable Send Task: " + displayName;
    } else if (type == TaskType.RECEIVE) {
        message = "Enable Receive Task: " + displayName;
    } else if (type == TaskType.USER) {
        message = "Enable User Task: " + displayName;
    } else if (type == TaskType.MANUAL) {
        message = "Enable Manual Task: " + displayName;
    } else if (type == TaskType.BUSINESS_RULE) {
        message = "Enable Business Rule: " + displayName;
    } else if (type == TaskType.SCRIPT) {
        message = "Enable Script Task: " + displayName;
    } else {
        SimulationUtils.sendElementNotSupportedTraceNote(model, processModel, displayName, nodeId);
        SimulationUtils.abort(model, processInstance, nodeId, traceIsOn());
        return;
    }
    sendTraceNote(message);
    try {
        // poll available resources and if not available, put TaskBeginEvent on hold
        ScyllaEvent event = new TaskBeginEvent(model, source, currentSimulationTime, pSimComponents, processInstance, nodeId);
        ResourceObjectTuple resources = QueueManager.getResourcesForEvent(model, event);
        if (resources == null) {
            QueueManager.addToEventQueues(model, event);
            sendTraceNote("Not enough resources available, task " + displayName + " is put in a queue.");
        } else {
            QueueManager.assignResourcesToEvent(model, event, resources);
            TimeSpan timeSpan = new TimeSpan(0);
            int index = getNewEventIndex();
            nextEventMap.put(index, event);
            timeSpanToNextEventMap.put(index, timeSpan);
        }
        TaskEnableEventPluggable.runPlugins(this, processInstance);
        scheduleNextEvents();
    } catch (ScyllaRuntimeException e) {
        DebugLogger.error(e.getMessage());
        DebugLogger.log("Simulation aborted.");
    }
}
Also used : ResourceObjectTuple(de.hpi.bpt.scylla.simulation.ResourceObjectTuple) TimeSpan(desmoj.core.simulator.TimeSpan) ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) TaskType(de.hpi.bpt.scylla.model.process.node.TaskType) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) TimeInstant(desmoj.core.simulator.TimeInstant)

Example 23 with ScyllaRuntimeException

use of de.hpi.bpt.scylla.exception.ScyllaRuntimeException in project scylla by bptlab.

the class BatchPluginUtils method logTaskEventForNonResponsiblePI.

// If the execution type is parallel this makes the entry for the not really simulated process instances for tasks
void logTaskEventForNonResponsiblePI(TaskEvent event, ProcessInstance processInstance) throws ScyllaRuntimeException {
    ProcessInstance parentProcessInstance = processInstance.getParent();
    if (parentProcessInstance != null) {
        ProcessModel processModel = processInstance.getProcessModel();
        int parentNodeId = processModel.getNodeIdInParent();
        BatchPluginUtils pluginInstance = BatchPluginUtils.getInstance();
        BatchCluster cluster = pluginInstance.getRunningCluster(parentProcessInstance, parentNodeId);
        if (cluster != null && cluster.getBatchActivity().getExecutionType().equals(BatchClusterExecutionType.PARALLEL)) {
            SimulationModel model = (SimulationModel) event.getModel();
            long timestamp = Math.round(model.presentTime().getTimeRounded(DateTimeUtils.getReferenceTimeUnit()));
            String taskName = event.getDisplayName();
            int nodeId = event.getNodeId();
            String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
            String source = event.getSource();
            ProcessNodeTransitionType transition;
            Set<String> resources = new HashSet<String>();
            if (event instanceof TaskEnableEvent) {
                transition = ProcessNodeTransitionType.ENABLE;
            } else if (event instanceof TaskBeginEvent) {
                transition = ProcessNodeTransitionType.BEGIN;
                Set<ResourceObject> resourceObjects = processInstance.getAssignedResources().get(source).getResourceObjects();
                for (ResourceObject res : resourceObjects) {
                    String resourceName = res.getResourceType() + "_" + res.getId();
                    resources.add(resourceName);
                }
                tasksAndResources.put(source, resources);
            } else if (event instanceof TaskCancelEvent) {
                transition = ProcessNodeTransitionType.CANCEL;
                resources = tasksAndResources.get(source);
                tasksAndResources.remove(source);
            } else if (event instanceof TaskTerminateEvent) {
                transition = ProcessNodeTransitionType.TERMINATE;
                resources = tasksAndResources.get(source);
                tasksAndResources.remove(source);
            } else {
                throw new ScyllaRuntimeException("Task event type not supported.");
            }
            int sourceSuffix = 0;
            List<ProcessInstance> processInstances = cluster.getProcessInstances();
            for (ProcessInstance pi : processInstances) {
                if (!processInstance.getParent().equals(pi)) {
                    // the source attribute comes from an event, but we did not really simulate the events for the
                    // non-responsible process instances, so we mock a source attribute value
                    String mockSource = source + "##" + ++sourceSuffix;
                    ProcessNodeInfo info;
                    info = new ProcessNodeInfo(nodeId, processScopeNodeId, mockSource, timestamp, taskName, resources, transition);
                    model.addNodeInfo(processModel, pi, info);
                }
            }
        }
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ResourceObject(de.hpi.bpt.scylla.simulation.ResourceObject) HashSet(java.util.HashSet) Set(java.util.Set) ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) ProcessNodeTransitionType(de.hpi.bpt.scylla.logger.ProcessNodeTransitionType) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) HashSet(java.util.HashSet)

Example 24 with ScyllaRuntimeException

use of de.hpi.bpt.scylla.exception.ScyllaRuntimeException in project scylla by bptlab.

the class BoundaryEventPluginUtils method scheduleBoundaryEvents.

private void scheduleBoundaryEvents(SimulationModel model, double startOfInterval, double endOfInterval) {
    Set<String> boundaryObjectsToRemove = new HashSet<>();
    for (String taskEnableEventName : boundaryObjects.keySet()) {
        // boolean isInterruptingEvent = false;
        BoundaryObject bo = boundaryObjects.get(taskEnableEventName);
        TreeMap<Double, List<BPMNIntermediateEvent>> boundaryEventsToSchedule = bo.getBoundaryEventsToSchedule();
        Iterator<Double> iterator = boundaryEventsToSchedule.keySet().iterator();
        Set<Double> elementsToRemove = new HashSet<>();
        ProcessInstance processInstance = bo.getProcessInstance();
        while (iterator.hasNext()) {
            Double timeToSchedule = iterator.next();
            if (timeToSchedule > endOfInterval) {
                // We will not have prepared events for scheduling which are beyond endOfInterval.
                break;
            }
            List<BPMNIntermediateEvent> events = boundaryEventsToSchedule.get(timeToSchedule);
            // Now take all events and schedule them.
            for (BPMNIntermediateEvent event : events) {
                double durationRelativeToEventStart = timeToSchedule - startOfInterval;
                if (durationRelativeToEventStart < 0)
                    continue;
                TimeUnit unit = TimeUnit.SECONDS;
                TimeSpan timeSpan = new TimeSpan(durationRelativeToEventStart, unit);
                // Schedule the event.
                try {
                    SimulationUtils.scheduleEvent(event, timeSpan);
                } catch (ScyllaRuntimeException exception) {
                    exception.printStackTrace();
                }
            /*ProcessModel processModel = processInstance.getProcessModel();
                    int nodeId = event.getNodeId();
                    boolean cancelActivity = processModel.getCancelActivities().get(nodeId);
                    if (cancelActivity) {
                        isInterruptingEvent = true;
                    }*/
            }
            // TreeMap<Double, List<String>> messagesOfBoundaryEventsToSchedule = bo.getMessagesOfBoundaryEventsToSchedule();
            // Took this out, see rest in createNonTimerBoundaryEvents.
            /*List<String> messages = messagesOfBoundaryEventsToSchedule.get(timeToSchedule);
                for (String message : messages) {
                    model.sendTraceNote(message);
                }*/
            // clean up
            elementsToRemove.add(timeToSchedule);
        // Not needed anymore, alreday done in creation.
        /*if (isInterruptingEvent) {
                    boundaryObjectsToRemove.add(taskEnableEventName);
                    // if (bo.getSource().equals(desmojEvent.getSource())) {
                    // normalBehavior = false;
                    // }
                    // processInstance.cancel();
                    break;
                }*/
        }
        for (Double timeToSchedule : elementsToRemove) {
            boundaryEventsToSchedule.remove(timeToSchedule);
            // messagesOfBoundaryEventsToSchedule.remove(timeToSchedule);
            if (boundaryEventsToSchedule.isEmpty()) {
                boundaryObjectsToRemove.add(taskEnableEventName);
            }
        }
    }
    // Delete all boudnaryObjects, which are compeltetly scheduled.
    for (String taskEnableEventName : boundaryObjectsToRemove) {
        boundaryObjects.remove(taskEnableEventName);
    }
}
Also used : ScyllaRuntimeException(de.hpi.bpt.scylla.exception.ScyllaRuntimeException) BPMNIntermediateEvent(de.hpi.bpt.scylla.simulation.event.BPMNIntermediateEvent) TimeSpan(desmoj.core.simulator.TimeSpan) TimeUnit(java.util.concurrent.TimeUnit) ArrayList(java.util.ArrayList) List(java.util.List) ProcessInstance(de.hpi.bpt.scylla.simulation.ProcessInstance) HashSet(java.util.HashSet)

Aggregations

ScyllaRuntimeException (de.hpi.bpt.scylla.exception.ScyllaRuntimeException)24 SimulationModel (de.hpi.bpt.scylla.simulation.SimulationModel)21 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)18 TimeSpan (desmoj.core.simulator.TimeSpan)13 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)10 NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)10 TimeInstant (desmoj.core.simulator.TimeInstant)8 HashSet (java.util.HashSet)8 ProcessInstance (de.hpi.bpt.scylla.simulation.ProcessInstance)7 Map (java.util.Map)7 ProcessSimulationComponents (de.hpi.bpt.scylla.simulation.ProcessSimulationComponents)5 ScyllaEvent (de.hpi.bpt.scylla.simulation.event.ScyllaEvent)5 ProcessNodeInfo (de.hpi.bpt.scylla.logger.ProcessNodeInfo)4 EventDefinitionType (de.hpi.bpt.scylla.model.process.node.EventDefinitionType)4 TaskType (de.hpi.bpt.scylla.model.process.node.TaskType)4 ArrayList (java.util.ArrayList)4 EventType (de.hpi.bpt.scylla.model.process.node.EventType)3 BPMNIntermediateEvent (de.hpi.bpt.scylla.simulation.event.BPMNIntermediateEvent)3 HashMap (java.util.HashMap)3 List (java.util.List)3