Package org.apache.sandesha2.storage.beans

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


      lastMessageInvoked = invokeMessage(null);

      // Look for the next message, so long as we are still processing normally
      while(!ignoreNextMsg && lastMessageInvoked) {
        if(log.isDebugEnabled()) log.debug("InvokerWorker:: looking for next msg to invoke");
        InvokerBean finder = new InvokerBean();
        finder.setSequenceID(sequence);
        finder.setMsgNo(messageNumber + 1);

        StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configurationContext,configurationContext.getAxisConfiguration());
        tran = storageManager.getTransaction();

        InvokerBeanMgr mgr = storageManager.getInvokerBeanMgr();
        InvokerBean nextBean = mgr.findUnique(finder);

        if(nextBean != null) {
          if(pooledThread) {
            if(log.isDebugEnabled()) log.debug("InvokerWorker:: pooledThread");
            initializeFromBean(nextBean);
            final Transaction theTran = tran;
            Runnable work = new Runnable() {
              public void run() {
                lastMessageInvoked = invokeMessage(theTran);
              }
            };

            // Wrap the work with the correct context, if needed.
            ContextManager contextMgr = SandeshaUtil.getContextManager(configurationContext);
            if(contextMgr != null) {
              work = contextMgr.wrapWithContext(work, nextBean.getContext());
            }

            // Finally do the work
            work.run();

            tran = null;
          } else {
            if(log.isDebugEnabled()) log.debug("InvokerWorker:: not pooled thread");
            nextWorker = new InvokerWorker(configurationContext, nextBean);
            nextWorker.setPooled();
            nextWorker.setWorkId(workId);

            // Wrap the invoker worker with the correct context, if needed.
            ContextManager contextMgr = SandeshaUtil.getContextManager(configurationContext);
            if(contextMgr != null) {
              nextRunnable = contextMgr.wrapWithContext(nextWorker, nextBean.getContext());
            } else {
              nextRunnable = nextWorker;
            }
          }
        }
View Full Code Here

        transaction = storageManager.getTransaction();
      } else {
        transaction = tran;
      }
     
      InvokerBean invokerBean = invokerBeanMgr.retrieve(messageContextKey);

      msgToInvoke = storageManager.retrieveMessageContext(messageContextKey, configurationContext);
      if(msgToInvoke==null){
        //return since there is nothing to do
        if(log.isDebugEnabled()) log.debug("null msg");
        return false;
      }

      // ending the transaction before invocation.
      if(transaction != null) {
        transaction.commit();
        transaction = storageManager.getTransaction();
      }

      RMMsgContext rmMsg = MsgInitializer.initializeMessage(msgToInvoke);

      // Lock the RMD Bean just to avoid deadlocks
      RMDBean rMDBean = SandeshaUtil.getRMDBeanFromSequenceId(storageManager, invokerBean.getSequenceID());

      boolean highestMessage = false;

      if(!ignoreNextMsg){
        // updating the next msg to invoke
        long nextMsgNo = rMDBean.getNextMsgNoToProcess();
       
        if (!(invokerBean.getMsgNo()==nextMsgNo)) {
          //someone else has invoked this before us - this run should now stop
          if(log.isDebugEnabled()) log.debug("Operated message number is different from the Next Message Number to invoke");
          return false;
        }
       
        nextMsgNo++;
        rMDBean.setNextMsgNoToProcess(nextMsgNo);
        storageManager.getRMDBeanMgr().update(rMDBean);
      }
     
      // Check if this is the last message
      if (rmMsg.getMessageType() == Sandesha2Constants.MessageTypes.APPLICATION) {
        Sequence sequence = rmMsg.getSequence();
       
        if (sequence.getLastMessage()) {
          //this will work for RM 1.0 only
          highestMessage = true;
        } else {
          if (rMDBean!=null && rMDBean.isTerminated()) {
            long highestInMsgNo = rMDBean.getHighestInMessageNumber();
            if (invokerBean.getMsgNo()==highestInMsgNo)
              highestMessage = true;
          }
        }
      }

      // 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;

        InvocationResponse response = null;
        if (postFailureInvocation) {
          makeMessageReadyForReinjection(msgToInvoke);
          if (log.isDebugEnabled())
            log.debug("Receiving message, key=" + messageContextKey + ", msgCtx="
                + msgToInvoke.getEnvelope().getHeader());
          response = AxisEngine.receive(msgToInvoke);
        } else {
          if (log.isDebugEnabled())
            log.debug("Resuming message, key=" + messageContextKey + ", msgCtx="
                + msgToInvoke.getEnvelope().getHeader());
          msgToInvoke.setPaused(false);
          response = AxisEngine.resumeReceive(msgToInvoke);
        }

        if(!InvocationResponse.SUSPEND.equals(response)) {
          // Performance work - need to close the XMLStreamReader to prevent GC thrashing.
          SOAPEnvelope env = msgToInvoke.getEnvelope();
          if(env!=null){
            StAXBuilder sb = (StAXBuilder)msgToInvoke.getEnvelope().getBuilder();
            if(sb!=null){
              sb.close();
            }
          }
        }

        if (transaction != null && transaction.isActive()) {
          transaction.commit();
          transaction = storageManager.getTransaction();
        }

        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::invokeMessage Last message return " + messageInvoked);         
          return messageInvoked;
        }
View Full Code Here

    // then we should hand the message over to the invoker thread. If not, we can invoke
    // it directly ourselves.
    InvokerWorker worker = null;
    if (SandeshaUtil.isInOrder(msgCtx)) {
      String key = SandeshaUtil.getUUID(); // key to store the message.
      InvokerBean invokerBean = new InvokerBean(key, msgNo, sequenceId);
      ContextManager contextMgr = SandeshaUtil.getContextManager(configCtx);

      if(contextMgr != null) invokerBean.setContext(contextMgr.storeContext());

      boolean wasAdded = storageManager.getInvokerBeanMgr().insert(invokerBean);

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

    if(LoggingControl.isAnyTracingEnabled() && log.isDebugEnabled()) log.debug("Enter: TerminateManager::cleanReceivingSideAfterInvocation " +sequenceId);
   
    InvokerBeanMgr invokerBeanMgr = storageManager.getInvokerBeanMgr();

    // removing InvokerBean entries
    InvokerBean invokerFindBean = new InvokerBean();
    invokerFindBean.setSequenceID(sequenceId);
    Collection<InvokerBean> collection = invokerBeanMgr.find(invokerFindBean);
    Iterator<InvokerBean> iterator = collection.iterator();
    while (iterator.hasNext()) {
      InvokerBean invokerBean = (InvokerBean) iterator.next();
      String messageStoreKey = invokerBean.getMessageContextRefKey();
      invokerBeanMgr.delete(messageStoreKey);

      // removing the respective message context from the message store.
      storageManager.removeMessageContext(messageStoreKey);
    }
View Full Code Here

    super(mgr, context, Sandesha2Constants.BeanMAPs.STORAGE_MAP);
  }

  public boolean insert(InvokerBean bean) throws SandeshaStorageException {
    //first check that an invoker bean does not already exist with the same msg and seq numbers
    InvokerBean finder = new InvokerBean();
    finder.setMsgNo(bean.getMsgNo());
    finder.setSequenceID(bean.getSequenceID());
    lock.lock();
    boolean result = false;
    if(super.findUnique(finder)!=null){
      if(LoggingControl.isAnyTracingEnabled() && log.isDebugEnabled()) log.debug("InMemoryInvokerBeanMgr insert failed due to existing invoker bean");
      result = false;
View Full Code Here

    return sql.toString();
  }

  private InvokerBean getInvokerBean(ResultSet rs)
      throws Exception {
    InvokerBean invokerBean = new InvokerBean();
    invokerBean.setMessageContextRefKey(rs.getString("message_context_ref_key"));
    invokerBean.setSequenceID(rs.getString("sequence_id"));
    invokerBean.setMsgNo(rs.getLong("msg_no"));
    invokerBean.setFlags(rs.getInt("flags"));
    invokerBean.setContext((Serializable) getObject(rs, "context"));
    return invokerBean;
  }
View Full Code Here

    return true;
  }

  public InvokerBean retrieve(String key)
      throws SandeshaStorageException {
    InvokerBean invokerBean = null;
    try {
      Statement stmt = getDbConnection().createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
      ResultSet rs = stmt.executeQuery("select * from wsrm_invoker where message_context_ref_key='" + key + "'");
      if (! rs.next()) return invokerBean;
      invokerBean = getInvokerBean(rs);
View Full Code Here

  }

  public InvokerBean findUnique(InvokerBean bean)
      throws SandeshaException {
    String sql = requestForModel(bean);
    InvokerBean result = null;
    try {
      Statement stmt = getDbConnection().createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
      ResultSet rs = stmt.executeQuery(sql);
      while (rs.next()) {
        if (result == null) {
          result = getInvokerBean(rs);
        } else {
          String message = SandeshaMessageHelper.getMessage(
              SandeshaMessageKeys.nonUniqueResult,
              result.toString(),
              getInvokerBean(rs).toString());
          log.error(message);
          throw new SandeshaException(message);
        }
      }
View Full Code Here

           
          boolean isDuplicate = true;
          //still allow this msg if we have no corresponding invoker bean for it and we are inOrder
          if(SandeshaUtil.isInOrder(rmMsgCtx.getMessageContext()))
          {
              InvokerBean finderBean = new InvokerBean();
              finderBean.setMsgNo(msgNo);
              finderBean.setSequenceID(sequenceId);
              List<InvokerBean> invokerBeanList = storageManager.getInvokerBeanMgr().find(finderBean);
              if((invokerBeanList==null || invokerBeanList.size()==0)
                  && bean.getNextMsgNoToProcess()<=msgNo){
                isDuplicate = false;
                if (LoggingControl.isAnyTracingEnabled() && log.isDebugEnabled())
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.