Package org.switchyard.component.bpm.transaction

Examples of org.switchyard.component.bpm.transaction.AS7TransactionHelper


                    return null;
                } else if (Object.class.equals(method.getDeclaringClass())) {
                    return method.invoke(_internalTaskService, args);
                } else {
                    Object ret;
                    AS7TransactionHelper utx = new AS7TransactionHelper(true);
                    try {
                        utx.begin();
                        ret = method.invoke(_internalTaskService, args);
                        utx.commit();
                    } catch (Throwable t) {
                        utx.rollback();
                        throw t;
                    }
                    return ret;
                }
            }
View Full Code Here


        Integer sessionId = null;
        Long processInstanceId = null;
        Message inputMessage = exchange.getMessage();
        ExchangePattern exchangePattern = exchange.getContract().getProviderOperation().getExchangePattern();
        Map<String, Object> expressionVariables = new HashMap<String, Object>();
        AS7TransactionHelper utx = new AS7TransactionHelper(_persistent);
        BPMOperationType operationType = (BPMOperationType)operation.getType();
        switch (operationType) {
            case START_PROCESS: {
                try {
                    utx.begin();
                    KnowledgeSession session = getBPMSession(exchange, inputMessage);
                    sessionId = session.getId();
                    setGlobals(inputMessage, operation, session);
                    Map<String, Object> inputMap = getInputMap(inputMessage, operation, session);
                    ProcessInstance processInstance;
                    CorrelationKey correlationKey = getCorrelationKey(exchange, inputMessage);
                    if (correlationKey != null) {
                        processInstance = ((CorrelationAwareProcessRuntime)session.getStateful()).startProcess(_processId, correlationKey, inputMap);
                    } else {
                        processInstance = session.getStateful().startProcess(_processId, inputMap);
                    }
                    processInstanceId = Long.valueOf(processInstance.getId());
                    if (ExchangePattern.IN_OUT.equals(exchangePattern)) {
                        expressionVariables.putAll(getGlobalVariables(session));
                        expressionVariables.putAll(getProcessInstanceVariables(processInstance));
                    }
                    utx.commit();
                } catch (RuntimeException re) {
                    utx.rollback();
                    throw re;
                }
                break;
            }
            case SIGNAL_EVENT:
            case SIGNAL_EVENT_ALL: {
                try {
                    utx.begin();
                    KnowledgeSession session = getBPMSession(exchange, inputMessage);
                    sessionId = session.getId();
                    setGlobals(inputMessage, operation, session);
                    Object eventObject = getInput(inputMessage, operation, session);
                    String eventId = operation.getEventId();
                    if (BPMOperationType.SIGNAL_EVENT.equals(operationType)) {
                        processInstanceId = getProcessInstanceId(exchange, inputMessage, session);
                        if (processInstanceId == null) {
                            throw BPMMessages.MESSAGES.cannotSignalEventUnknownProcessInstanceIdOrUnknownunmatchedCorrelationKey();
                        }
                        if (ExchangePattern.IN_OUT.equals(exchangePattern)) {
                            ProcessInstance processInstance = session.getStateful().getProcessInstance(processInstanceId);
                            processInstance.signalEvent(eventId, eventObject);
                            expressionVariables.putAll(getGlobalVariables(session));
                            expressionVariables.putAll(getProcessInstanceVariables(processInstance));
                        } else {
                            session.getStateful().signalEvent(eventId, eventObject, processInstanceId);
                        }
                    } else if (BPMOperationType.SIGNAL_EVENT_ALL.equals(operationType)) {
                        session.getStateful().signalEvent(eventId, eventObject);
                        if (ExchangePattern.IN_OUT.equals(exchangePattern)) {
                            expressionVariables.putAll(getGlobalVariables(session));
                        }
                    }
                    utx.commit();
                } catch (RuntimeException re) {
                    utx.rollback();
                    throw re;
                }
                break;
            }
            case ABORT_PROCESS_INSTANCE: {
                try {
                    utx.begin();
                    KnowledgeSession session = getBPMSession(exchange, inputMessage);
                    sessionId = session.getId();
                    processInstanceId = getProcessInstanceId(exchange, inputMessage, session);
                    if (processInstanceId == null) {
                        throw BPMMessages.MESSAGES.cannotAbortProcessInstance();
                    }
                    if (ExchangePattern.IN_OUT.equals(exchangePattern)) {
                        expressionVariables.putAll(getGlobalVariables(session));
                        ProcessInstance processInstance = session.getStateful().getProcessInstance(processInstanceId);
                        expressionVariables.putAll(getProcessInstanceVariables(processInstance));
                    }
                    session.getStateful().abortProcessInstance(processInstanceId);
                    utx.commit();
                } catch (RuntimeException re) {
                    utx.rollback();
                    throw re;
                }
                break;
            }
            default: {
View Full Code Here

TOP

Related Classes of org.switchyard.component.bpm.transaction.AS7TransactionHelper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.