Examples of InvokerBean


Examples of org.apache.sandesha2.storage.beans.InvokerBean

    public void tearDown() throws Exception {
      transaction.commit();
    }

    public void testDelete() throws SandeshaStorageException {
        mgr.insert(new InvokerBean("Key1", 1001, "SeqId1"));
        mgr.delete("Key1");
        assertNull(mgr.retrieve("Key1"));
    }
View Full Code Here

Examples of org.apache.sandesha2.storage.beans.InvokerBean

        mgr.delete("Key1");
        assertNull(mgr.retrieve("Key1"));
    }

    public void testFind() throws SandeshaStorageException {
        mgr.insert(new InvokerBean("Key2", 1002, "SeqId2"));
        mgr.insert(new InvokerBean("Key3", 1003, "SeqId2"));

        InvokerBean bean = new InvokerBean();
        bean.setSequenceID("SeqId2");

        Iterator iter = mgr.find(bean).iterator();
        InvokerBean tmp = (InvokerBean) iter.next();

        if (tmp.getMessageContextRefKey().equals("Key2")) {
            tmp = (InvokerBean) iter.next();
            assertTrue(tmp.getMessageContextRefKey().equals("Key3"));
        } else {
            tmp = (InvokerBean) iter.next();
            assertTrue(tmp.getMessageContextRefKey().equals("Key2"));

        }
    }
View Full Code Here

Examples of org.apache.sandesha2.storage.beans.InvokerBean

        }
    }

    public void testInsert() throws SandeshaStorageException {
        mgr.insert(new InvokerBean("Key4", 1004, "SeqId4"));
        InvokerBean tmp = mgr.retrieve("Key4");
        assertTrue(tmp.getMessageContextRefKey().equals("Key4"));
    }
View Full Code Here

Examples of org.apache.sandesha2.storage.beans.InvokerBean

        assertTrue(tmp.getMessageContextRefKey().equals("Key4"));
    }

    public void testRetrieve() throws SandeshaStorageException {
        assertNull(mgr.retrieve("Key5"));
        mgr.insert(new InvokerBean("Key5", 1004, "SeqId5"));
        assertNotNull(mgr.retrieve("Key5"));
    }
View Full Code Here

Examples of org.apache.sandesha2.storage.beans.InvokerBean

        mgr.insert(new InvokerBean("Key5", 1004, "SeqId5"));
        assertNotNull(mgr.retrieve("Key5"));
    }

    public void testUpdate() throws SandeshaStorageException {
        InvokerBean bean = new InvokerBean("Key6", 1006, "SeqId6");
        mgr.insert(bean);
        bean.setMsgNo(1007);
        mgr.update(bean);
        InvokerBean tmp = mgr.retrieve("Key6");
        assertTrue(tmp.getMsgNo() == 1007);
    }
View Full Code Here

Examples of org.apache.sandesha2.storage.beans.InvokerBean

        result = InvocationResponse.SUSPEND;
      }
      InvokerBeanMgr storageMapMgr = storageManager.getInvokerBeanMgr();

      storageManager.storeMessageContext(key, rmMsgCtx.getMessageContext());
      storageMapMgr.insert(new InvokerBean(key, msgNo, sequenceId));

      // This will avoid performing application processing more than once.
      rmMsgCtx.setProperty(Sandesha2Constants.APPLICATION_PROCESSING_DONE, "true");

    }
View Full Code Here

Examples of org.apache.sandesha2.storage.beans.InvokerBean

      InvokerBeanMgr invokerBeanMgr = storageManager.getInvokerBeanMgr();
     
      //starting a transaction
      transaction = storageManager.getTransaction();
     
      InvokerBean invokerBean = invokerBeanMgr.retrieve(messageContextKey);
     
      msgToInvoke = storageManager.retrieveMessageContext(messageContextKey, configurationContext);
      RMMsgContext rmMsg = MsgInitializer.initializeMessage(msgToInvoke);

      // ending the transaction before invocation.
      if(transaction != null) {
        transaction.commit();
        transaction = null;
      }
         
      //starting a transaction for the invocation work.
      transaction = storageManager.getTransaction();
      // Lock the RMD Bean just to avoid deadlocks
      SandeshaUtil.getRMDBeanFromSequenceId(storageManager, invokerBean.getSequenceID());
      // Depending on the transaction  support, the service will be invoked only once.
      // Therefore we delete the invoker bean and message now, ahead of time
      invokerBeanMgr.delete(messageContextKey);
      // removing the corresponding message context as well.
      storageManager.removeMessageContext(messageContextKey);

      try {

        boolean postFailureInvocation = false;

        // StorageManagers should st following property to
        // true, to indicate that the message received comes
        // after a failure.
        String postFaulureProperty = (String) msgToInvoke
            .getProperty(Sandesha2Constants.POST_FAILURE_MESSAGE);
        if (postFaulureProperty != null
            && Sandesha2Constants.VALUE_TRUE.equals(postFaulureProperty))
          postFailureInvocation = true;

        AxisEngine engine = new AxisEngine(msgToInvoke.getConfigurationContext());
        if (postFailureInvocation) {
          makeMessageReadyForReinjection(msgToInvoke);
          if (log.isDebugEnabled())
            log.debug("Receiving message, key=" + messageContextKey + ", msgCtx="
                + msgToInvoke.getEnvelope().getHeader());
          engine.receive(msgToInvoke);
        } else {
          if (log.isDebugEnabled())
            log.debug("Resuming message, key=" + messageContextKey + ", msgCtx="
                + msgToInvoke.getEnvelope().getHeader());
          msgToInvoke.setPaused(false);
          engine.resumeReceive(msgToInvoke);
        }
       
        if(transaction!=null){
          transaction.commit();
          transaction = storageManager.getTransaction();
        }
      } catch (Exception e) {
        if (log.isDebugEnabled())
          log.debug("Exception :", e);

        handleFault(rmMsg, e);
      }


     
      if (rmMsg.getMessageType() == Sandesha2Constants.MessageTypes.APPLICATION) {
        Sequence sequence = (Sequence) rmMsg
            .getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE);
       
        boolean highestMessage = false;
        if (sequence.getLastMessage() != null) {
          //this will work for RM 1.0 only
          highestMessage = true;
        } else {
          RMDBean rmdBean = SandeshaUtil.getRMDBeanFromSequenceId(storageManager, invokerBean.getSequenceID());
         
          if (rmdBean!=null && rmdBean.isTerminated()) {
            long highestInMsgNo = rmdBean.getHighestInMessageNumber();
            if (invokerBean.getMsgNo()==highestInMsgNo)
              highestMessage = true;
          }
        }
       
        if (highestMessage) {
          //do cleaning stuff that hs to be done after the invocation of the last message.
          TerminateManager.cleanReceivingSideAfterInvocation(invokerBean.getSequenceID(), storageManager);
          // exit from current iteration. (since an entry
          // was removed)
          if(log.isDebugEnabled()) log.debug("Exit: InvokerWorker::run Last message return");         
          return;
        }
      }
     
      if(!ignoreNextMsg){
        // updating the next msg to invoke
        RMDBean rMDBean = storageManager.getRMDBeanMgr().retrieve(invokerBean.getSequenceID());
        long nextMsgNo = rMDBean.getNextMsgNoToProcess();
       
        if (!(invokerBean.getMsgNo()==nextMsgNo)) {
          String message = "Operated message number is different from the Next Message Number to invoke";
          throw new SandeshaException (message);
        }
       
        nextMsgNo++;
View Full Code Here

Examples of org.apache.sandesha2.storage.beans.InvokerBean

       
        //The outOfOrder window is the set of known sequence messages (including those
        //that are missing) at the time the button is pressed.
        long firstMessageInOutOfOrderWindow = rMDBean.getNextMsgNoToProcess();
     
        InvokerBean selector = new InvokerBean();
        selector.setSequenceID(sequenceID);
        Iterator stMapIt = storageMapMgr.find(selector).iterator();
       
        long highestMsgNumberInvoked = 0;
        Transaction transaction = null;
       
        //invoke each bean in turn.
        //NOTE: here we are breaking ordering
        while(stMapIt.hasNext()){
          //invoke the app
          try{
            transaction = storageManager.getTransaction();
            InvokerBean invoker = (InvokerBean)stMapIt.next();
           
            // start a new worker thread and let it do the invocation.
            String workId = sequenceID + "::" + invoker.getMsgNo(); //creating a workId to uniquely identify the
             //piece of work that will be assigned to the Worker.
           
            String messageContextKey = invoker.getMessageContextRefKey();
            InvokerWorker worker = new InvokerWorker(context,
                messageContextKey,
                true); //want to ignore the enxt msg number
           
            worker.setLock(getWorkerLock());
            worker.setWorkId(workId);
           
            //before we execute we need to set the
           
            threadPool.execute(worker);
         
            //adding the workId to the lock after assigning it to a thread makes sure
            //that all the workIds in the Lock are handled by threads.
            getWorkerLock().addWork(workId);

            long msgNumber = invoker.getMsgNo();
            //if necessary, update the "next message number" bean under this transaction
            if(msgNumber>highestMsgNumberInvoked){
              highestMsgNumberInvoked = invoker.getMsgNo();
              rMDBean.setNextMsgNoToProcess(highestMsgNumberInvoked+1);
             
              if(allowLaterDeliveryOfMissingMessages){
                //we also need to update the sequence OUT_OF_ORDER_RANGES property
                //so as to include our latest view of this outOfOrder range.
View Full Code Here

Examples of org.apache.sandesha2.storage.beans.InvokerBean

   
    if(rmdBean != null && rmdBean.getOutOfOrderRanges() != null){
      RangeString rangeString = rmdBean.getOutOfOrderRanges();
      //we now have the set of ranges that can be delivered out of order.
      //Look for any invokable message that lies in one of those ranges
      InvokerBean selector = new InvokerBean();
      selector.setSequenceID(sequenceID);
      Iterator invokerBeansIterator =
        storageManager.getInvokerBeanMgr().find(selector).iterator();
     
      while(invokerBeansIterator.hasNext()){
        InvokerBean invokerBean = (InvokerBean)invokerBeansIterator.next();
       
        if(rangeString.isMessageNumberInRanges(invokerBean.getMsgNo())){
          //an invoker bean that has not been deleted and lies in an out
          //or order range - we can add this to the list
          list.add(invokerBean);
        }
      }
View Full Code Here

Examples of org.apache.sandesha2.storage.beans.InvokerBean

            SandeshaMessageKeys.invalidMsgNumber, Long
                .toString(nextMsgno));
        throw new SandeshaException(message);
      }

      InvokerBean selector = new InvokerBean();
      selector.setSequenceID(sequenceId);
      selector.setMsgNo(nextMsgno);
      List invokerBeans = storageMapMgr.find(selector);
     
      //add any msgs that belong to out of order windows
      addOutOfOrderInvokerBeansToList(sequenceId,
          storageManager, invokerBeans);
     
      // If there aren't any beans to process then move on to the next sequence
      if (invokerBeans.size() == 0) {
        if (log.isDebugEnabled()) log.debug("Exit: Invoker::internalRun, no beans to invoke on sequence " + sequenceId + ", sleep " + sleep);
        return sleep;
      }
     
      Iterator stMapIt = invokerBeans.iterator();

      //TODO correct the locking mechanism to have one lock per sequence.
      //TODO should this be a while, not an if?
      if (stMapIt.hasNext()) { //some invokation work is present
       
        InvokerBean bean = (InvokerBean) stMapIt.next();
        //see if this is an out of order msg
        boolean beanIsOutOfOrderMsg = bean.getMsgNo()!=nextMsgno;
       
        String workId = sequenceId + "::" + bean.getMsgNo();
                                  //creating a workId to uniquely identify the
                                 //piece of work that will be assigned to the Worker.
                 
        //check whether the bean is already assigned to a worker.
        if (getWorkerLock().isWorkPresent(workId)) {
          // As there is already a worker assigned we are probably dispatching
          // messages too quickly, so we sleep before trying the next sequence.
          sleep = true;
          String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.workAlreadyAssigned, workId);
          if (log.isDebugEnabled()) log.debug("Exit: Invoker::internalRun, " + message + ", sleep " + sleep);
          return sleep;
        }

        String messageContextKey = bean.getMessageContextRefKey();
       
        if(transaction != null) {
          transaction.commit();
          transaction = null;
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.