Package org.apache.ode.bpel.dao

Examples of org.apache.ode.bpel.dao.CorrelatorDAO


        if (_instantiatingMessageExchange != null && _dao.getState() == ProcessState.STATE_READY) {
            if (BpelProcess.__log.isDebugEnabled()) {
                BpelProcess.__log.debug("SELECT: " + pickResponseChannel + ": CHECKING for NEW INSTANCE match");
            }
            for (int i = 0; i < correlators.size(); ++i) {
                CorrelatorDAO ci = correlators.get(i);
                if (ci.equals(_dao.getInstantiatingCorrelator())) {
                    inputMsgMatch(pickResponseChannelStr, i, _instantiatingMessageExchange);
                    if (BpelProcess.__log.isDebugEnabled()) {
                        BpelProcess.__log.debug("SELECT: " + pickResponseChannel
                                + ": FOUND match for NEW instance mexRef=" + _instantiatingMessageExchange);
                    }
                    return;
                }
            }
        }

        // if (BpelProcess.__log.isDebugEnabled()) {
        // BpelProcess.__log.debug("SELECT: " + pickResponseChannel
        // + ": NEW instance match NOT FOUND; CHECKING MESSAGES. ");
        // }
        //
        //
        // for (int i = 0; i < selectors.length; ++i) {
        // CorrelatorDAO correlator = correlators.get(i);
        // Selector selector = selectors[i];
        // MessageExchangeDAO mexdao = correlator
        // .dequeueMessage(selector.correlationKey);
        // if (mexdao != null) {
        // // Found message matching one of our selectors.
        // if (BpelProcess.__log.isDebugEnabled()) {
        // BpelProcess.__log.debug("SELECT: " + pickResponseChannel
        // + ": FOUND match to MESSAGE " + mexdao + " on CKEY "
        // + selector.correlationKey);
        // }
        //
        // MyRoleMessageExchangeImpl mex = new MyRoleMessageExchangeImpl(
        // _bpelProcess._engine, mexdao);
        //
        // inputMsgMatch(pickResponseChannel.export(), i, mex);
        // return;
        // }
        // }
        //
        // if (BpelProcess.__log.isDebugEnabled()) {
        // BpelProcess.__log.debug("SELECT: " + pickResponseChannel
        // + ": MESSAGE match NOT FOUND.");
        // }

        if (timeout != null) {
            registerTimer(pickResponseChannel, timeout);
            if (BpelProcess.__log.isDebugEnabled()) {
                BpelProcess.__log.debug("SELECT: " + pickResponseChannel + "REGISTERED TIMEOUT for " + timeout);
            }
        }

        for (int i = 0; i < selectors.length; ++i) {
            CorrelatorDAO correlator = correlators.get(i);
            Selector selector = selectors[i];

            correlator.addRoute(pickResponseChannel.export(), _dao, i, selector.correlationKey);
            scheduleCorrelatorMatcher(correlator.getCorrelatorId(), selector.correlationKey);

            if (BpelProcess.__log.isDebugEnabled()) {
                BpelProcess.__log.debug("SELECT: " + pickResponseChannel + ": ADDED ROUTE " + correlator.getCorrelatorId() + ": "
                        + selector.correlationKey + " --> " + _dao.getInstanceId());
            }
        }

View Full Code Here


     */
    public void matcherEvent(String correlatorId, CorrelationKey ckey) {
        if (BpelProcess.__log.isDebugEnabled()) {
            __log.debug("MatcherEvent handling: correlatorId=" + correlatorId + ", ckey=" + ckey);
        }
        CorrelatorDAO correlator = _dao.getProcess().getCorrelator(correlatorId);

        // Find the route first, this is a SELECT FOR UPDATE on the "selector" row,
        // So we want to acquire the lock before we do anthing else.
        MessageRouteDAO mroute = correlator.findRoute(ckey);
        if (mroute == null) {
            // Ok, this means that a message arrived before we did, so nothing to do.
            __log.debug("MatcherEvent handling: nothing to do, route no longer in DB");
            return;
        }

        // Now see if there is a message that matches this selector.
        MessageExchangeDAO mexdao = correlator.dequeueMessage(ckey);
        if (mexdao != null) {
            __log.debug("MatcherEvent handling: found matching message in DB (i.e. message arrived before <receive>)");

            // We have a match, so we can get rid of the routing entries.
            correlator.removeRoutes(mroute.getGroupId(),_dao);

            // Found message matching one of our selectors.
            if (BpelProcess.__log.isDebugEnabled()) {
                BpelProcess.__log.debug("SELECT: " + mroute.getGroupId() + ": matched to MESSAGE " + mexdao
                        + " on CKEY " + ckey);
View Full Code Here

        // Get the correlator, a persisted communnication-reduction data
        // structure
        // supporting correlation correlationKey matching!
        String correlatorId = BpelProcess.genCorrelatorId(_plinkDef, operation.getName());

        CorrelatorDAO correlator = _process.getProcessDAO().getCorrelator(correlatorId);

        CorrelationKey[] keys;
        MessageRouteDAO messageRoute = null;

        // We need to compute the correlation keys (based on the operation
        // we can  infer which correlation keys to compute - this is merely a set
        // consisting of each correlationKey used in each correlation sets
        // that is ever referenced in an <receive>/<onMessage> on this
        // partnerlink/operation.
        try {
            keys = computeCorrelationKeys(mex);
        } catch (InvalidMessageException ime) {
            // We'd like to do a graceful exit here, no sense in rolling back due to a
            // a message format problem.
            __log.debug("Unable to evaluate correlation keys, invalid message format. ",ime);
            mex.setFailure(MessageExchange.FailureType.FORMAT_ERROR, ime.getMessage(), null);
            return;
        }

        String mySessionId = mex.getProperty(MessageExchange.PROPERTY_SEP_MYROLE_SESSIONID);
        String partnerSessionId = mex.getProperty(MessageExchange.PROPERTY_SEP_PARTNERROLE_SESSIONID);
        if (__log.isDebugEnabled()) {
            __log.debug("INPUTMSG: " + correlatorId + ": MSG RCVD keys="
                    + ArrayUtils.makeCollection(HashSet.class, keys) + " mySessionId=" + mySessionId
                    + " partnerSessionId=" + partnerSessionId);
        }

        CorrelationKey matchedKey = null;

        // Try to find a route for one of our keys.
        for (CorrelationKey key : keys) {
            messageRoute = correlator.findRoute(key);
            if (messageRoute != null) {
                if (__log.isDebugEnabled()) {
                    __log.debug("INPUTMSG: " + correlatorId + ": ckey " + key + " route is to " + messageRoute);
                }
                matchedKey = key;
                break;
            }
        }

        // TODO - ODE-58

        // If no luck, and this operation qualifies for create-instance
        // treatment, then create a new process
        // instance.
        if (messageRoute == null && isCreateInstnace) {
            if (__log.isDebugEnabled()) {
                __log.debug("INPUTMSG: " + correlatorId + ": routing failed, CREATING NEW INSTANCE");
            }
            ProcessDAO processDAO = _process.getProcessDAO();

            if (_process._pconf.getState() == ProcessState.RETIRED) {
                throw new InvalidProcessException("Process is retired.", InvalidProcessException.RETIRED_CAUSE_CODE);
            }

            if (!_process.processInterceptors(mex, InterceptorInvoker.__onNewInstanceInvoked)) {
                __log.debug("Not creating a new instance for mex " + mex + "; interceptor prevented!");
                return;
            }

            ProcessInstanceDAO newInstance = processDAO.createInstance(correlator);

            BpelRuntimeContextImpl instance = _process
                    .createRuntimeContext(newInstance, new PROCESS(_process.getOProcess()), mex);

            // send process instance event
            NewProcessInstanceEvent evt = new NewProcessInstanceEvent(new QName(_process.getOProcess().targetNamespace,
                    _process.getOProcess().getName()), _process.getProcessDAO().getProcessId(), newInstance.getInstanceId());
            evt.setPortType(mex.getPortType().getQName());
            evt.setOperation(operation.getName());
            evt.setMexId(mex.getMessageExchangeId());
            _process._debugger.onEvent(evt);
            _process.saveEvent(evt, newInstance);
            mex.setCorrelationStatus(MyRoleMessageExchange.CorrelationStatus.CREATE_INSTANCE);
            mex.getDAO().setInstance(newInstance);

            instance.execute();
        } else if (messageRoute != null) {
            if (__log.isDebugEnabled()) {
                __log.debug("INPUTMSG: " + correlatorId + ": ROUTING to instance "
                        + messageRoute.getTargetInstance().getInstanceId());
            }

            ProcessInstanceDAO instanceDao = messageRoute.getTargetInstance();

            // Reload process instance for DAO.
            BpelRuntimeContextImpl instance = _process.createRuntimeContext(instanceDao, null, null);
            instance.inputMsgMatch(messageRoute.getGroupId(), messageRoute.getIndex(), mex);

            // Kill the route so some new message does not get routed to
            // same process instance.
            correlator.removeRoutes(messageRoute.getGroupId(), instanceDao);

            // send process instance event
            CorrelationMatchEvent evt = new CorrelationMatchEvent(new QName(_process.getOProcess().targetNamespace,
                    _process.getOProcess().getName()), _process.getProcessDAO().getProcessId(),
                    instanceDao.getInstanceId(), matchedKey);
            evt.setPortType(mex.getPortType().getQName());
            evt.setOperation(operation.getName());
            evt.setMexId(mex.getMessageExchangeId());

            _process._debugger.onEvent(evt);
            // store event
            _process.saveEvent(evt, instanceDao);

            // EXPERIMENTAL -- LOCK
            // instanceDao.lock();

            mex.setCorrelationStatus(MyRoleMessageExchange.CorrelationStatus.MATCHED);
            mex.getDAO().setInstance(messageRoute.getTargetInstance());
            instance.execute();
        } else {
            if (__log.isDebugEnabled()) {
                __log.debug("INPUTMSG: " + correlatorId + ": SAVING to DB (no match) ");
            }

            if (!mex.isAsynchronous()) {
                mex.setFailure(MessageExchange.FailureType.NOMATCH, "No process instance matching correlation keys.", null);

            } else {
                // send event
                CorrelationNoMatchEvent evt = new CorrelationNoMatchEvent(mex.getPortType().getQName(), mex
                        .getOperation().getName(), mex.getMessageExchangeId(), keys);

                evt.setProcessId(_process.getProcessDAO().getProcessId());
                evt.setProcessName(new QName(_process.getOProcess().targetNamespace, _process.getOProcess().getName()));
                _process._debugger.onEvent(evt);

                mex.setCorrelationStatus(MyRoleMessageExchange.CorrelationStatus.QUEUED);

                // No match, means we add message exchange to the queue.
                correlator.enqueueMessage(mex.getDAO(), keys);

            }
        }

        // Now we have to update our message exchange status. If the <reply>
View Full Code Here

    public QName getProcessId() {
        return _processId;
    }

    public CorrelatorDAO getCorrelator(String cid) {
        CorrelatorDAO ret = _correlators.get(cid);
        if (ret == null) {
            throw new IllegalArgumentException("no such correlator: " + cid);
        }
        return ret;
    }
View Full Code Here

    assertNotNull(p.getProcessId());
    assertEquals( p.getVersion() , 1 );
    assertTrue( p.getNumInstances() > 0 );
   
    // Assert the CorrelatorDAO
    CorrelatorDAO corr = p.getCorrelator(CORRELATOR_ID1);
    assertNotNull( corr );
    assertEquals(corr.getCorrelatorId(),CORRELATOR_ID1);
   
    // Assert the MessageRouteDAO
    MessageRouteDAO route = corr.findRoute(key1);
    assertNotNull( route );
    assertEquals(route.getGroupId(),"testRoute" );
    assertEquals(route.getIndex() , 1 );
    assertNotNull(route.getTargetInstance() );

    // Assert the ProcessInstanceDAO
    for ( ProcessInstanceDAO inst : insts ) {
      Long id = inst.getInstanceId();
      assertNotNull( id );
     
      ProcessInstanceDAO inst2 = conn.getInstance(id);
      assertSame(inst2,inst);
     
      ProcessInstanceDAO inst3 = p.getInstance(id);
      assertSame( inst3 , inst );
     
      Long mon = inst.genMonotonic();
      assertEquals(inst.getActivityFailureCount() , 2);
      assertNotNull(inst.getActivityFailureDateTime() );
      assertNotNull(inst.getCreateTime() );
      assertTrue(inst.getExecutionState().length > 0 );
      assertNotNull(inst.getLastActiveTime() );
      assertSame(inst.getProcess() , p );
      assertEquals(inst.getPreviousState() , 0);
      assertEquals(inst.getState() , 1);
     
      // Assert the Root ScopeDAO
      ScopeDAO rs = inst.getRootScope();
      assertNotNull( rs );
      assertNotNull(rs.getChildScopes());
      ScopeDAO child1 = null;
      for ( ScopeDAO childItr : rs.getChildScopes()){
        child1 = childItr;
        break;
      }
      assertNotNull(child1);
      assertNotNull(rs.getCorrelationSets());
      assertEquals(rs.getCorrelationSets().size() , 0 );
      assertEquals(rs.getModelId(),1);
      assertEquals(rs.getName(),"Root");
      assertTrue(rs.getParentScope() == null);
      assertNotNull(rs.getPartnerLinks());
      assertEquals(rs.getPartnerLinks().size() ,0);
      assertSame(rs.getProcessInstance(),inst);
      assertNotNull(rs.getScopeInstanceId());
      assertEquals(rs.getState(),ScopeStateEnum.ACTIVE);
      assertNotNull(rs.getVariables());
      assertEquals(rs.getVariables().size(),0);
     
   
      // Assert the ActivityRecoveryDAO
      assertNotNull(inst.getActivityRecoveries());
      ActivityRecoveryDAO rec1 = null;
      for (ActivityRecoveryDAO recItr : inst.getActivityRecoveries()) {
        rec1 = recItr;
        break;
      }
      assertNotNull(rec1);
      String tmpAct = rec1.getActions();
//      assertEquals(rec1.getActionsList(),actions);
      assertEquals(rec1.getActivityId(),3);
      assertEquals(rec1.getChannel(),"testChannel1");
      assertNotNull(rec1.getDateTime());
//      assertNotNull(rec1.getDetails());
      assertEquals(rec1.getReason(),"testReason1");
      assertEquals(rec1.getRetries(),2);
     
      // Assert the CorrelationSetDAO
      //assertNotNull(inst.getCorrelationSets());
      //CorrelationSetDAO cs1 = null;
      //for ( CorrelationSetDAO csItr : inst.getCorrelationSets() ) {
      //  cs1 = csItr;
      //  break;
      //}
      //assertNotNull(cs1);
     
      // Assert the FaultDAO
      FaultDAO fault = inst.getFault();
      assertNotNull(fault);
      assertEquals(fault.getActivityId(),1);
      assertNotNull(fault.getData());
      assertEquals(fault.getExplanation(),"testExplanation");
      assertEquals(fault.getLineNo(),1);
      assertEquals(fault.getName(),new QName(TEST_NS,"testFault"));
     
      // Assert MessageExchangeDAO
      CorrelatorDAO ic = inst.getInstantiatingCorrelator();
      assertNotNull(ic);
      assertEquals(ic.getCorrelatorId(),CORRELATOR_ID1);
      // The message is dequeued but not persisted
      MessageExchangeDAO me = ic.dequeueMessage(key1);
      assertNotNull(me);
      assertEquals(me.getCallee(),new QName(TEST_NS,"testCallee"));
      assertEquals(me.getPropagateTransactionFlag(),false);
      assertEquals(me.getChannel(),"testChannel");
      assertEquals(me.getCorrelationId(),"testCorrelationId");
View Full Code Here

        if (_instantiatingMessageExchange != null && _dao.getState() == ProcessState.STATE_READY) {
            if (BpelProcess.__log.isDebugEnabled()) {
                BpelProcess.__log.debug("SELECT: " + pickResponseChannel + ": CHECKING for NEW INSTANCE match");
            }
            for (int i = 0; i < correlators.size(); ++i) {
                CorrelatorDAO ci = correlators.get(i);
                if (ci.equals(_dao.getInstantiatingCorrelator())) {
                    inputMsgMatch(pickResponseChannelStr, i, _instantiatingMessageExchange);
                    if (BpelProcess.__log.isDebugEnabled()) {
                        BpelProcess.__log.debug("SELECT: " + pickResponseChannel
                                + ": FOUND match for NEW instance mexRef=" + _instantiatingMessageExchange);
                    }
                    return;
                }
            }
        }

        // if (BpelProcess.__log.isDebugEnabled()) {
        // BpelProcess.__log.debug("SELECT: " + pickResponseChannel
        // + ": NEW instance match NOT FOUND; CHECKING MESSAGES. ");
        // }
        //
        //
        // for (int i = 0; i < selectors.length; ++i) {
        // CorrelatorDAO correlator = correlators.get(i);
        // Selector selector = selectors[i];
        // MessageExchangeDAO mexdao = correlator
        // .dequeueMessage(selector.correlationKey);
        // if (mexdao != null) {
        // // Found message matching one of our selectors.
        // if (BpelProcess.__log.isDebugEnabled()) {
        // BpelProcess.__log.debug("SELECT: " + pickResponseChannel
        // + ": FOUND match to MESSAGE " + mexdao + " on CKEY "
        // + selector.correlationKey);
        // }
        //
        // MyRoleMessageExchangeImpl mex = new MyRoleMessageExchangeImpl(
        // _bpelProcess._engine, mexdao);
        //
        // inputMsgMatch(pickResponseChannel.export(), i, mex);
        // return;
        // }
        // }
        //
        // if (BpelProcess.__log.isDebugEnabled()) {
        // BpelProcess.__log.debug("SELECT: " + pickResponseChannel
        // + ": MESSAGE match NOT FOUND.");
        // }

        if (timeout != null) {
            registerTimer(pickResponseChannel, timeout);
            if (BpelProcess.__log.isDebugEnabled()) {
                BpelProcess.__log.debug("SELECT: " + pickResponseChannel + "REGISTERED TIMEOUT for " + timeout);
            }
        }

        for (int i = 0; i < selectors.length; ++i) {
            CorrelatorDAO correlator = correlators.get(i);
            Selector selector = selectors[i];

            correlator.addRoute(pickResponseChannel.export(), _dao, i, selector.correlationKey);
            scheduleCorrelatorMatcher(correlator.getCorrelatorId(), selector.correlationKey);

            if (BpelProcess.__log.isDebugEnabled()) {
                BpelProcess.__log.debug("SELECT: " + pickResponseChannel + ": ADDED ROUTE " + correlator.getCorrelatorId() + ": "
                        + selector.correlationKey + " --> " + _dao.getInstanceId());
            }
        }

View Full Code Here

     */
    public void matcherEvent(String correlatorId, CorrelationKey ckey) {
        if (BpelProcess.__log.isDebugEnabled()) {
            __log.debug("MatcherEvent handling: correlatorId=" + correlatorId + ", ckey=" + ckey);
        }
        CorrelatorDAO correlator = _dao.getProcess().getCorrelator(correlatorId);

        // Find the route first, this is a SELECT FOR UPDATE on the "selector" row,
        // So we want to acquire the lock before we do anthing else.
        MessageRouteDAO mroute = correlator.findRoute(ckey);
        if (mroute == null) {
            // Ok, this means that a message arrived before we did, so nothing to do.
            __log.debug("MatcherEvent handling: nothing to do, route no longer in DB");
            return;
        }

        // Now see if there is a message that matches this selector.
        MessageExchangeDAO mexdao = correlator.dequeueMessage(ckey);
        if (mexdao != null) {
            __log.debug("MatcherEvent handling: found matching message in DB (i.e. message arrived before <receive>)");

            // We have a match, so we can get rid of the routing entries.
            correlator.removeRoutes(mroute.getGroupId(),_dao);

            // Found message matching one of our selectors.
            if (BpelProcess.__log.isDebugEnabled()) {
                BpelProcess.__log.debug("SELECT: " + mroute.getGroupId() + ": matched to MESSAGE " + mexdao
                        + " on CKEY " + ckey);
View Full Code Here

        // now, the tricks begin: when a message arrives we have to see if there
        // is anyone waiting for it. Get the correlator, a persisted communication-reduction
        // data structure supporting correlation correlationKey matching!
        String correlatorId = BpelProcess.genCorrelatorId(_plinkDef, operation.getName());

        CorrelatorDAO correlator = _process.getProcessDAO().getCorrelator(correlatorId);

        CorrelationKey[] keys;
        MessageRouteDAO messageRoute = null;

        // We need to compute the correlation keys (based on the operation
        // we can  infer which correlation keys to compute - this is merely a set
        // consisting of each correlationKey used in each correlation sets
        // that is ever referenced in an <receive>/<onMessage> on this
        // partnerlink/operation.
        try {
            keys = computeCorrelationKeys(mex);
        } catch (InvalidMessageException ime) {
            // We'd like to do a graceful exit here, no sense in rolling back due to a
            // a message format problem.
            __log.debug("Unable to evaluate correlation keys, invalid message format. ",ime);
            mex.setFailure(MessageExchange.FailureType.FORMAT_ERROR, ime.getMessage(), null);
            return null;
        }

        String mySessionId = mex.getProperty(MessageExchange.PROPERTY_SEP_MYROLE_SESSIONID);
        String partnerSessionId = mex.getProperty(MessageExchange.PROPERTY_SEP_PARTNERROLE_SESSIONID);
        if (__log.isDebugEnabled()) {
            __log.debug("INPUTMSG: " + correlatorId + ": MSG RCVD keys="
                    + ArrayUtils.makeCollection(HashSet.class, keys) + " mySessionId=" + mySessionId
                    + " partnerSessionId=" + partnerSessionId);
        }

        CorrelationKey matchedKey = null;

        // Try to find a route for one of our keys.
        for (CorrelationKey key : keys) {
            messageRoute = correlator.findRoute(key);
            if (messageRoute != null) {
                if (__log.isDebugEnabled()) {
                    __log.debug("INPUTMSG: " + correlatorId + ": ckey " + key + " route is to " + messageRoute);
                }
                matchedKey = key;
View Full Code Here

    public QName getProcessId() {
        return _processId;
    }

    public CorrelatorDAO getCorrelator(String cid) {
        CorrelatorDAO ret = _correlators.get(cid);
        if (ret == null) {
            throw new IllegalArgumentException("no such correlator: " + cid);
        }
        return ret;
    }
View Full Code Here

        // now, the tricks begin: when a message arrives we have to see if there
        // is anyone waiting for it. Get the correlator, a persisted communication-reduction
        // data structure supporting correlation correlationKey matching!
        String correlatorId = BpelProcess.genCorrelatorId(_plinkDef, operation.getName());

        CorrelatorDAO correlator = _process.getProcessDAO().getCorrelator(correlatorId);

        CorrelationKey[] keys;
        MessageRouteDAO messageRoute = null;

        // We need to compute the correlation keys (based on the operation
        // we can  infer which correlation keys to compute - this is merely a set
        // consisting of each correlationKey used in each correlation sets
        // that is ever referenced in an <receive>/<onMessage> on this
        // partnerlink/operation.
        try {
            keys = computeCorrelationKeys(mex);
        } catch (InvalidMessageException ime) {
            // We'd like to do a graceful exit here, no sense in rolling back due to a
            // a message format problem.
            __log.debug("Unable to evaluate correlation keys, invalid message format. ",ime);
            mex.setFailure(MessageExchange.FailureType.FORMAT_ERROR, ime.getMessage(), null);
            return null;
        }

        String mySessionId = mex.getProperty(MessageExchange.PROPERTY_SEP_MYROLE_SESSIONID);
        String partnerSessionId = mex.getProperty(MessageExchange.PROPERTY_SEP_PARTNERROLE_SESSIONID);
        if (__log.isDebugEnabled()) {
            __log.debug("INPUTMSG: " + correlatorId + ": MSG RCVD keys="
                    + CollectionUtils.makeCollection(HashSet.class, keys) + " mySessionId=" + mySessionId
                    + " partnerSessionId=" + partnerSessionId);
        }

        CorrelationKey matchedKey = null;

        // Try to find a route for one of our keys.
        for (CorrelationKey key : keys) {
            messageRoute = correlator.findRoute(key);
            if (messageRoute != null) {
                if (__log.isDebugEnabled()) {
                    __log.debug("INPUTMSG: " + correlatorId + ": ckey " + key + " route is to " + messageRoute);
                }
                matchedKey = key;
View Full Code Here

TOP

Related Classes of org.apache.ode.bpel.dao.CorrelatorDAO

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.