Search in sources :

Example 36 with SimulationModel

use of de.hpi.bpt.scylla.simulation.SimulationModel 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 37 with SimulationModel

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

the class TaskCancelEvent method addToLog.

@Override
protected void addToLog(ProcessInstance processInstance) {
    long timestamp = Math.round(getModel().presentTime().getTimeRounded(DateTimeUtils.getReferenceTimeUnit()));
    String taskName = displayName;
    Set<String> resources = new HashSet<String>();
    Set<ResourceObject> resourceObjects = processInstance.getAssignedResources().get(source).getResourceObjects();
    for (ResourceObject res : resourceObjects) {
        String resourceName = res.getResourceType() + "_" + res.getId();
        resources.add(resourceName);
    }
    ProcessNodeTransitionType transition = ProcessNodeTransitionType.CANCEL;
    SimulationModel model = (SimulationModel) getModel();
    ProcessModel processModel = processInstance.getProcessModel();
    String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
    ProcessNodeInfo info = new ProcessNodeInfo(nodeId, processScopeNodeId, source, timestamp, taskName, resources, transition);
    model.addNodeInfo(processModel, processInstance, info);
}
Also used : ResourceObject(de.hpi.bpt.scylla.simulation.ResourceObject) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ProcessNodeTransitionType(de.hpi.bpt.scylla.logger.ProcessNodeTransitionType) ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) HashSet(java.util.HashSet)

Example 38 with SimulationModel

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

the class TaskEnableEvent method addToLog.

@Override
protected void addToLog(ProcessInstance processInstance) {
    long timestamp = Math.round(getModel().presentTime().getTimeRounded(DateTimeUtils.getReferenceTimeUnit()));
    String taskName = displayName;
    Set<String> resources = new HashSet<String>();
    ProcessNodeTransitionType transition = ProcessNodeTransitionType.ENABLE;
    SimulationModel model = (SimulationModel) getModel();
    ProcessModel processModel = processInstance.getProcessModel();
    String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
    ProcessNodeInfo info = new ProcessNodeInfo(nodeId, processScopeNodeId, getName(), timestamp, taskName, resources, transition);
    model.addNodeInfo(processModel, processInstance, info);
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) ProcessNodeTransitionType(de.hpi.bpt.scylla.logger.ProcessNodeTransitionType) ProcessNodeInfo(de.hpi.bpt.scylla.logger.ProcessNodeInfo) SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel) HashSet(java.util.HashSet)

Example 39 with SimulationModel

use of de.hpi.bpt.scylla.simulation.SimulationModel 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 40 with SimulationModel

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

the class TaskEvent method eventRoutine.

@Override
public void eventRoutine(ProcessInstance processInstance) throws SuspendExecution {
    SimulationModel model = (SimulationModel) getModel();
    boolean outputLoggingIsOn = model.isOutputLoggingOn();
    if (outputLoggingIsOn) {
        addToLog(processInstance);
    }
}
Also used : SimulationModel(de.hpi.bpt.scylla.simulation.SimulationModel)

Aggregations

SimulationModel (de.hpi.bpt.scylla.simulation.SimulationModel)48 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)41 ScyllaRuntimeException (de.hpi.bpt.scylla.exception.ScyllaRuntimeException)21 NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)17 TimeSpan (desmoj.core.simulator.TimeSpan)17 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)15 Map (java.util.Map)15 ProcessNodeInfo (de.hpi.bpt.scylla.logger.ProcessNodeInfo)13 ProcessInstance (de.hpi.bpt.scylla.simulation.ProcessInstance)12 HashSet (java.util.HashSet)12 TimeInstant (desmoj.core.simulator.TimeInstant)11 ProcessSimulationComponents (de.hpi.bpt.scylla.simulation.ProcessSimulationComponents)10 ScyllaEvent (de.hpi.bpt.scylla.simulation.event.ScyllaEvent)8 HashMap (java.util.HashMap)8 EventDefinitionType (de.hpi.bpt.scylla.model.process.node.EventDefinitionType)7 ProcessNodeTransitionType (de.hpi.bpt.scylla.logger.ProcessNodeTransitionType)6 SimulationConfiguration (de.hpi.bpt.scylla.model.configuration.SimulationConfiguration)6 ResourceObject (de.hpi.bpt.scylla.simulation.ResourceObject)6 GatewayType (de.hpi.bpt.scylla.model.process.node.GatewayType)5 TimeUnit (java.util.concurrent.TimeUnit)5