Package org.apache.sandesha2.storage.beans

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<InvokerBean> 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;
           
            InvokerWorker worker = new InvokerWorker(ctx, invoker);
            worker.forceOutOfOrder();
            worker.setPooled();
            worker.setWorkId(workId);
           
            // Wrap the invoker worker with the correct context, if needed.
            Runnable work = worker;
            ContextManager contextMgr = SandeshaUtil.getContextManager(ctx);
            if(contextMgr != null) {
              work = contextMgr.wrapWithContext(work, invoker.getContext());
            }
           
            // Setup the lock for the new worker
            worker.getLock().addWork(workId, worker);
            ctx.getThreadPool().execute(work);

            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


   
    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<InvokerBean> 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

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

      InvokerBean selector = new InvokerBean();
      selector.setSequenceID(sequenceId);
      selector.setMsgNo(nextMsgno);
      List<InvokerBean> 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);
       
        if(transaction != null && transaction.isActive()) transaction.commit();
        transaction = null;

        return sleep;
      }
     
      Iterator<InvokerBean> 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;
                 
        //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);
         
          if(transaction != null) {
            transaction.commit();
            transaction = null;
          }
         
          return sleep;
        }

        if(transaction != null) {
          transaction.commit();
          transaction = null;
        }

        // start a new worker thread and let it do the invocation.
        InvokerWorker worker = new InvokerWorker(context, bean);
        if(beanIsOutOfOrderMsg) worker.forceOutOfOrder();
        worker.setPooled();
        worker.setWorkId(workId);
       
        // Wrap the invoker worker with the correct context, if needed.
        Runnable work = worker;
        ContextManager contextMgr = SandeshaUtil.getContextManager(context);
        if(contextMgr != null) {
          work = contextMgr.wrapWithContext(work, bean.getContext());
        }
        try {
          // Set the lock up before we start the thread, but roll it back
          // if we hit any problems
          if(worker.getLock().addWork(workId, worker))
View Full Code Here

    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configContext);
    SequencePropertyBeanMgr sequencePropertyBeanMgr = storageManager.getSequencePropretyBeanMgr();
    InvokerBeanMgr storageMapBeanMgr = storageManager.getStorageMapBeanMgr();

    //removing storageMap entries
    InvokerBean findStorageMapBean = new InvokerBean ();
    findStorageMapBean.setSequenceId(sequenceID);
    Collection collection = storageMapBeanMgr.find(findStorageMapBean);
    Iterator iterator = collection.iterator();
    while (iterator.hasNext()) {
      InvokerBean storageMapBean = (InvokerBean) iterator.next();
      storageMapBeanMgr.delete(storageMapBean.getKey());
    }
   
    SequencePropertyBean allSequenceBean = sequencePropertyBeanMgr.retrieve(Sandesha2Constants.SequenceProperties.ALL_SEQUENCES,Sandesha2Constants.SequenceProperties.INCOMING_SEQUENCE_LIST);
    ArrayList allSequenceList = (ArrayList) allSequenceBean.getValue();
   
View Full Code Here

        //saving the message.
        try {
          String key = SandeshaUtil.storeMessageContext(rmMsgCtx
              .getMessageContext());
          storageMapMgr.insert(new InvokerBean(key, msgNo,
              sequenceId));

          //This will avoid performing application processing more
          // than
          // once.
View Full Code Here

  public Collection find(InvokerBean bean) {
    ArrayList beans = new ArrayList();
    Iterator iterator = table.values().iterator();

    InvokerBean temp = new InvokerBean();
    while (iterator.hasNext()) {
      temp = (InvokerBean) iterator.next();
      boolean select = true;

      if (bean.getKey() != null && !bean.getKey().equals(temp.getKey()))
        select = false;

      if (bean.getMsgNo() != 0 && bean.getMsgNo() != temp.getMsgNo())
        select = false;

      if (bean.getSequenceId() != null
          && !bean.getSequenceId().equals(temp.getSequenceId()))
        select = false;

      if (select)
        beans.add(temp);
    }
View Full Code Here

          if (nextMsgno <= 0)
            throw new SandeshaException(
                "Invalid messaage number for the nextMsgNo");

          Iterator stMapIt = storageMapMgr.find(
              new InvokerBean(null, nextMsgno, sequenceId))
              .iterator();

          while (stMapIt.hasNext()) {

            InvokerBean stMapBean = (InvokerBean) stMapIt
                .next();
            String key = stMapBean.getKey();

            MessageContext msgToInvoke = SandeshaUtil
                .getStoredMessageContext(key);

            RMMsgContext rmMsg = MsgInitializer
                .initializeMessage(msgToInvoke);
            Sequence seq = (Sequence) rmMsg
                .getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE);
            long msgNo = seq.getMessageNumber().getMessageNumber();

            try {
              //Invoking the message.
              new AxisEngine(msgToInvoke.getConfigurationContext())
                  .receive(msgToInvoke);

              ServiceContext serviceContext = msgToInvoke
                  .getServiceContext();
              Object debug = null;
              if (serviceContext != null) {
                debug = msgToInvoke
                    .getProperty(Sandesha2ClientAPI.SANDESHA_DEBUG_MODE);
                if (debug != null && "on".equals(debug)) {
                  System.out
                      .println("DEBUG: Invoker invoking a '"
                          + SandeshaUtil
                              .getMessageTypeString(rmMsg
                                  .getMessageType())
                          + "' message.");
                }
              }

              //deleting the message entry.
              storageMapMgr.delete(key);

            } catch (AxisFault e) {
              throw new SandeshaException(e.getMessage());
            }

            //undating the next mst to invoke
            nextMsgno++;
            stMapIt = storageMapMgr
                .find(
                    new InvokerBean(null, nextMsgno,
                        sequenceId)).iterator();

            //terminate (AfterInvocation)
            if (rmMsg.getMessageType() == Sandesha2Constants.MessageTypes.APPLICATION) {
              Sequence sequence = (Sequence) rmMsg
View Full Code Here

        StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configCtx);
        mgr = storageManager.getStorageMapBeanMgr();
    }

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

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

    public void testFind() {
        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.getKey().equals("Key2")) {
            tmp = (InvokerBean) iter.next();
            assertTrue(tmp.getKey().equals("Key3"));
        } else {
            tmp = (InvokerBean) iter.next();
            assertTrue(tmp.getKey().equals("Key2"));

        }
    }
View Full Code Here

        }
    }

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

TOP

Related Classes of org.apache.sandesha2.storage.beans.InvokerBean

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.