Search in sources :

Example 1 with EventNodeInterface

use of org.jbpm.workflow.core.node.EventNodeInterface in project jbpm by kiegroup.

the class CompositeNodeInstance method signalEvent.

@Override
public void signalEvent(String type, Object event) {
    List<NodeInstance> currentView = new ArrayList<NodeInstance>(this.nodeInstances);
    super.signalEvent(type, event);
    for (Node node : getCompositeNode().internalGetNodes()) {
        if (node instanceof EventNodeInterface) {
            if (((EventNodeInterface) node).acceptsEvent(type, event)) {
                if (node instanceof EventNode && ((EventNode) node).getFrom() == null) {
                    EventNodeInstanceInterface eventNodeInstance = (EventNodeInstanceInterface) getNodeInstance(node);
                    eventNodeInstance.signalEvent(type, event);
                } else if (node instanceof EventSubProcessNode) {
                    EventNodeInstanceInterface eventNodeInstance = (EventNodeInstanceInterface) getNodeInstance(node);
                    eventNodeInstance.signalEvent(type, event);
                } else {
                    List<NodeInstance> nodeInstances = getNodeInstances(node.getId(), currentView);
                    if (nodeInstances != null && !nodeInstances.isEmpty()) {
                        for (NodeInstance nodeInstance : nodeInstances) {
                            ((EventNodeInstanceInterface) nodeInstance).signalEvent(type, event);
                        }
                    }
                }
            }
        }
    }
}
Also used : AsyncEventNode(org.jbpm.workflow.core.node.AsyncEventNode) EventNode(org.jbpm.workflow.core.node.EventNode) EventNodeInterface(org.jbpm.workflow.core.node.EventNodeInterface) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) StateBasedNode(org.jbpm.workflow.core.node.StateBasedNode) StartNode(org.jbpm.workflow.core.node.StartNode) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) AsyncEventNode(org.jbpm.workflow.core.node.AsyncEventNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) EndNode(org.jbpm.workflow.core.node.EndNode) EventNode(org.jbpm.workflow.core.node.EventNode) Node(org.kie.api.definition.process.Node) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) NodeInstance(org.jbpm.workflow.instance.NodeInstance)

Example 2 with EventNodeInterface

use of org.jbpm.workflow.core.node.EventNodeInterface in project jbpm by kiegroup.

the class WorkflowProcessInstanceImpl method signalEvent.

@SuppressWarnings("unchecked")
public void signalEvent(String type, Object event) {
    logger.debug("Signal {} received with data {} in process instance {}", type, event, getId());
    synchronized (this) {
        if (getState() != ProcessInstance.STATE_ACTIVE) {
            return;
        }
        if ("timerTriggered".equals(type)) {
            TimerInstance timer = (TimerInstance) event;
            if (timer.getId() == slaTimerId) {
                handleSLAViolation();
                // no need to pass the event along as it was purely for SLA tracking
                return;
            }
        }
        if ("slaViolation".equals(type)) {
            handleSLAViolation();
            // no need to pass the event along as it was purely for SLA tracking
            return;
        }
        List<NodeInstance> currentView = new ArrayList<NodeInstance>(this.nodeInstances);
        try {
            this.activatingNodeIds = new ArrayList<String>();
            List<EventListener> listeners = eventListeners.get(type);
            if (listeners != null) {
                for (EventListener listener : listeners) {
                    listener.signalEvent(type, event);
                }
            }
            listeners = externalEventListeners.get(type);
            if (listeners != null) {
                for (EventListener listener : listeners) {
                    listener.signalEvent(type, event);
                }
            }
            for (Node node : getWorkflowProcess().getNodes()) {
                if (node instanceof EventNodeInterface) {
                    if (((EventNodeInterface) node).acceptsEvent(type, event, (e) -> resolveVariable(e))) {
                        if (node instanceof EventNode && ((EventNode) node).getFrom() == null) {
                            EventNodeInstance eventNodeInstance = (EventNodeInstance) getNodeInstance(node);
                            eventNodeInstance.signalEvent(type, event);
                        } else {
                            if (node instanceof EventSubProcessNode && ((resolveVariables(((EventSubProcessNode) node).getEvents()).contains(type)))) {
                                EventSubProcessNodeInstance eventNodeInstance = (EventSubProcessNodeInstance) getNodeInstance(node);
                                eventNodeInstance.signalEvent(type, event);
                            }
                            if (node instanceof DynamicNode && type.equals(((DynamicNode) node).getActivationEventName())) {
                                DynamicNodeInstance dynamicNodeInstance = (DynamicNodeInstance) getNodeInstance(node);
                                dynamicNodeInstance.signalEvent(type, event);
                            } else {
                                List<NodeInstance> nodeInstances = getNodeInstances(node.getId(), currentView);
                                if (nodeInstances != null && !nodeInstances.isEmpty()) {
                                    for (NodeInstance nodeInstance : nodeInstances) {
                                        ((EventNodeInstanceInterface) nodeInstance).signalEvent(type, event);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (((org.jbpm.workflow.core.WorkflowProcess) getWorkflowProcess()).isDynamic()) {
                for (Node node : getWorkflowProcess().getNodes()) {
                    if (type.equals(node.getName()) && node.getIncomingConnections().isEmpty()) {
                        NodeInstance nodeInstance = getNodeInstance(node);
                        if (event != null) {
                            Map<String, Object> dynamicParams = new HashMap<>();
                            if (event instanceof Map) {
                                dynamicParams.putAll((Map<String, Object>) event);
                            } else {
                                dynamicParams.put("Data", event);
                            }
                            ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).setDynamicParameters(dynamicParams);
                        }
                        ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).trigger(null, NodeImpl.CONNECTION_DEFAULT_TYPE);
                    }
                }
            }
        } finally {
            if (this.activatingNodeIds != null) {
                this.activatingNodeIds.clear();
                this.activatingNodeIds = null;
            }
        }
    }
}
Also used : DynamicNodeInstance(org.jbpm.workflow.instance.node.DynamicNodeInstance) TimerInstance(org.jbpm.process.instance.timer.TimerInstance) HashMap(java.util.HashMap) EventNodeInterface(org.jbpm.workflow.core.node.EventNodeInterface) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) DynamicNode(org.jbpm.workflow.core.node.DynamicNode) AsyncEventNode(org.jbpm.workflow.core.node.AsyncEventNode) StateBasedNode(org.jbpm.workflow.core.node.StateBasedNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) EndNode(org.jbpm.workflow.core.node.EndNode) EventNode(org.jbpm.workflow.core.node.EventNode) Node(org.kie.api.definition.process.Node) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) EventSubProcessNodeInstance(org.jbpm.workflow.instance.node.EventSubProcessNodeInstance) AsyncEventNode(org.jbpm.workflow.core.node.AsyncEventNode) EventNode(org.jbpm.workflow.core.node.EventNode) EventNodeInstanceInterface(org.jbpm.workflow.instance.node.EventNodeInstanceInterface) DynamicNode(org.jbpm.workflow.core.node.DynamicNode) EventListener(org.kie.api.runtime.process.EventListener) EventSubProcessNodeInstance(org.jbpm.workflow.instance.node.EventSubProcessNodeInstance) DynamicNodeInstance(org.jbpm.workflow.instance.node.DynamicNodeInstance) EndNodeInstance(org.jbpm.workflow.instance.node.EndNodeInstance) NodeInstance(org.jbpm.workflow.instance.NodeInstance) EventNodeInstance(org.jbpm.workflow.instance.node.EventNodeInstance) CompositeNodeInstance(org.jbpm.workflow.instance.node.CompositeNodeInstance) EventNodeInstance(org.jbpm.workflow.instance.node.EventNodeInstance) WorkflowProcess(org.kie.api.definition.process.WorkflowProcess) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ArrayList (java.util.ArrayList)2 ActionNode (org.jbpm.workflow.core.node.ActionNode)2 AsyncEventNode (org.jbpm.workflow.core.node.AsyncEventNode)2 EndNode (org.jbpm.workflow.core.node.EndNode)2 EventNode (org.jbpm.workflow.core.node.EventNode)2 EventNodeInterface (org.jbpm.workflow.core.node.EventNodeInterface)2 EventSubProcessNode (org.jbpm.workflow.core.node.EventSubProcessNode)2 StateBasedNode (org.jbpm.workflow.core.node.StateBasedNode)2 NodeInstance (org.jbpm.workflow.instance.NodeInstance)2 Node (org.kie.api.definition.process.Node)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 TimerInstance (org.jbpm.process.instance.timer.TimerInstance)1 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)1 DynamicNode (org.jbpm.workflow.core.node.DynamicNode)1 StartNode (org.jbpm.workflow.core.node.StartNode)1 CompositeNodeInstance (org.jbpm.workflow.instance.node.CompositeNodeInstance)1 DynamicNodeInstance (org.jbpm.workflow.instance.node.DynamicNodeInstance)1