Package org.apache.sandesha2.storage

Examples of org.apache.sandesha2.storage.Transaction


   */
  public static void forceDispatchOfInboundMessages(ConfigurationContext configContext,
      String sequenceID,
      boolean allowLaterDeliveryOfMissingMessages)throws SandeshaException{

    Transaction reportTransaction = null;

    try {
      StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configContext, configContext.getAxisConfiguration());
      reportTransaction = storageManager.getTransaction();

      //only do this if we are running inOrder
      if(SandeshaUtil.getPropertyBean(configContext.getAxisConfiguration()).isInOrder()){
        Invoker invoker = (Invoker)SandeshaUtil.getSandeshaStorageManager(configContext, configContext.getAxisConfiguration()).getInvoker();
        if (invoker==null){
          throw new SandeshaException(SandeshaMessageHelper.getMessage(
            SandeshaMessageKeys.invokerNotFound, sequenceID));
        }
       
        invoker.forceInvokeOfAllMessagesCurrentlyOnSequence(configContext, sequenceID, allowLaterDeliveryOfMissingMessages);     
      }
     
      if(reportTransaction != null && reportTransaction.isActive()) reportTransaction.commit();
      reportTransaction = null;

    } catch (Exception e) {
      // Just log the exception
      if(log.isDebugEnabled()) log.debug("Exception", e);
    } finally {
      if(reportTransaction != null && reportTransaction.isActive()) reportTransaction.rollback();
    }
  }
View Full Code Here


    }

    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configurationContext,configurationContext.getAxisConfiguration());
   
    // Get a transaction for getting the sequence properties
    Transaction transaction = null;
    String sequenceID = null;
   
    try
    {
      transaction = storageManager.getTransaction();
      sequenceID = SandeshaUtil.getSequenceIDFromInternalSequenceID(internalSequenceID, storageManager);
    }
    finally
    {
      // Commit the tran whatever happened
      if(transaction != null) transaction.commit();
    }
   
    if (sequenceID == null)
      sequenceID = Sandesha2Constants.TEMP_SEQUENCE_ID; 
View Full Code Here

  public static SequenceReport getIncomingSequenceReport(String sequenceID, ConfigurationContext configCtx)
      throws SandeshaException {

    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configCtx,configCtx.getAxisConfiguration());

    Transaction reportTransaction = null;

    try {
      reportTransaction = storageManager.getTransaction();

      SequenceReport sequenceReport = new SequenceReport();

      RMDBean rmdBean = SandeshaUtil.getRMDBeanFromSequenceId(storageManager, sequenceID);

      List completedMessageList = rmdBean.getServerCompletedMessages().getContainedElementsAsNumbersList();
     
      Iterator iter = completedMessageList.iterator();
      while (iter.hasNext()) {
        sequenceReport.addCompletedMessage((Long) iter.next());
      }

      sequenceReport.setSequenceID(sequenceID);
      sequenceReport.setInternalSequenceID(sequenceID); // for the
                                // incoming side
                                // internalSequenceID=sequenceID
      sequenceReport.setSequenceDirection(SequenceReport.SEQUENCE_DIRECTION_IN);

      sequenceReport.setSequenceStatus(getServerSequenceStatus(sequenceID, storageManager));

      if(rmdBean.getSecurityTokenData() != null) sequenceReport.setSecureSequence(true);
     
      if (reportTransaction!=null && reportTransaction.isActive()) reportTransaction.commit();
      reportTransaction = null;

      return sequenceReport;

    } catch (Exception e) {
      // Just log the exception
      if(log.isDebugEnabled()) log.debug("Exception", e);
    } finally {
      if(reportTransaction != null && reportTransaction.isActive()) {
        reportTransaction.rollback();
      }
    }

    return null;
  }
View Full Code Here

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

    // Get a transaction to obtain sequence information
    Transaction transaction = null;
    String sequenceID = null;
   
    try
    {
      transaction = storageManager.getTransaction();
      sequenceID = SandeshaUtil.getSequenceIDFromInternalSequenceID(internalSequenceID, storageManager);
    }
    finally
    {
      // Commit the tran whatever happened
      if(transaction != null) transaction.commit();
    }
   
    if (sequenceID == null)
      sequenceID = Sandesha2Constants.TEMP_SEQUENCE_ID; 
   
View Full Code Here

    ConfigurationContext configurationContext = serviceContext.getConfigurationContext();

    // Get the in use storage manager and the sequence property bean manager
    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configurationContext,configurationContext.getAxisConfiguration());
   
    Transaction transaction = null;
    Exception resultException = null;
   
    try
    {
      transaction = storageManager.getTransaction();
      RMSBean bean = SandeshaUtil.getRMSBeanFromInternalSequenceId(storageManager, internalSequenceId);
     
      if (bean != null) {           
        resultException = bean.getLastSendError();
      }
    }
    finally
    {
      // Commit the tran whatever happened
      if(transaction != null) transaction.commit();
    }
   
    if (log.isDebugEnabled())
      log.debug("Exit: SandeshaClient::getLastSendError, " + resultException);
   
View Full Code Here

    // Get the in use storage manager and the sequence property bean manager
    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configurationContext,configurationContext.getAxisConfiguration());
   
    // Create a transaction for the retrieve operation
    Transaction transaction = null;
    long resultTime = -1;

    try
    {
      transaction = storageManager.getTransaction();
     
      RMSBean bean = SandeshaUtil.getRMSBeanFromInternalSequenceId(storageManager, internalSequenceId);
     
      if (bean != null) {           
        resultTime = bean.getLastSendErrorTimestamp();
      }
    }
    finally
    {
      // commit the transaction as it was only a retrieve
      if(transaction != null) transaction.commit();
    }
   
    if (log.isDebugEnabled())
      log.debug("Exit: SandeshaClient::getLastSendErrorTimestamp, " + resultTime);
   
View Full Code Here

  private static final String getSOAPNamespaceURI(StorageManager storageManager, String internalSequenceID) throws SandeshaException {
    String soapNamespaceURI = null;
   
    // Get the RMSBean for this sequence.
    Transaction transaction = null;
   
    try {
      transaction = storageManager.getTransaction();
      RMSBean rmsBean = SandeshaUtil.getRMSBeanFromInternalSequenceId(storageManager, internalSequenceID);
      if (rmsBean.getSoapVersion() == Sandesha2Constants.SOAPVersion.v1_2)
        soapNamespaceURI = SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI;
    } finally {
      if(transaction != null) transaction.commit();
    }
   
    return soapNamespaceURI;
  }
View Full Code Here

      return response;
   
    SOAPFault faultPart = envelope.getBody().getFault();

    if (faultPart != null) {
      Transaction transaction = null;

      try {
        transaction = storageManager.getTransaction();

        // constructing the fault
        AxisFault axisFault = getAxisFaultFromFromSOAPFault(faultPart);
        response = manageIncomingFault (axisFault, rmMsgCtx, faultPart);
       
        if(transaction != null && transaction.isActive()) transaction.commit();
        transaction = null;
      } finally {
        if (transaction != null && transaction.isActive())
          transaction.rollback();
      }
    }
    return response;
  }
View Full Code Here

  }
 
  public void run() {
    if(log.isDebugEnabled()) log.debug("Enter: InvokerWorker::run");
   
    Transaction transaction = null;
    MessageContext msgToInvoke = null;
   
    try {
     
      StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configurationContext,configurationContext.getAxisConfiguration());
      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++;
        rMDBean.setNextMsgNoToProcess(nextMsgNo);
        storageManager.getRMDBeanMgr().update(rMDBean);
      }
     
      if(transaction != null && transaction.isActive()) transaction.commit();
      transaction = null;
     
    } catch (Exception e) {
      if (log.isErrorEnabled())
        log.error(e.toString(), e);
    } finally {
      if (workId !=null && lock!=null) {
        lock.removeWork(workId);
      }

      if (transaction!=null && transaction.isActive()) {
        try {
          transaction.rollback();
        } catch (SandeshaStorageException e) {
          if (log.isWarnEnabled())
            log.warn("Caught exception rolling back transaction", e);
        }
      }
View Full Code Here

        return returnValue;
      }
    }
    if (log.isDebugEnabled()) log.debug("SandeshaInHandler::invoke Continuing beyond basic checks");

    Transaction transaction = null;

    try {
      StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(context, context.getAxisConfiguration());
      transaction = storageManager.getTransaction();

      AxisService axisService = msgCtx.getAxisService();
      if (axisService == null) {
        String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.axisServiceIsNull);
        log.debug(message);
        throw new AxisFault(message);
      }

      RMMsgContext rmMsgCtx = null;
     
      if (msgCtx.getProperty(Sandesha2Constants.MessageContextProperties.RM_MESSAGE_CONTEXT) != null)
        rmMsgCtx = (RMMsgContext)msgCtx.getProperty(Sandesha2Constants.MessageContextProperties.RM_MESSAGE_CONTEXT);
      else
        rmMsgCtx = MsgInitializer.initializeMessage(msgCtx);

      // validating the message
      MessageValidator.validateIncomingMessage(rmMsgCtx, storageManager);
     
      // commit the current transaction
      if(transaction != null && transaction.isActive()) transaction.commit();
      transaction = storageManager.getTransaction();

      // Process Ack headers in the message
      AcknowledgementProcessor ackProcessor = new AcknowledgementProcessor();
      ackProcessor.processAckHeaders(rmMsgCtx);

      // commit the current transaction
      if(transaction != null && transaction.isActive()) transaction.commit();
      transaction = storageManager.getTransaction();

      // Process Ack Request headers in the message
      AckRequestedProcessor reqProcessor = new AckRequestedProcessor();
      if(reqProcessor.processAckRequestedHeaders(rmMsgCtx)){
        returnValue = InvocationResponse.SUSPEND;
      }
     
      // Process MessagePending headers
      MessagePendingProcessor pendingProcessor = new MessagePendingProcessor();
      pendingProcessor.processMessagePendingHeaders(rmMsgCtx);

      // commit the current transaction
      if(transaction != null && transaction.isActive()) transaction.commit();
      transaction = storageManager.getTransaction();

      // Process the Sequence header, if there is one
      SequenceProcessor seqProcessor = new SequenceProcessor();
      returnValue = seqProcessor.processSequenceHeader(rmMsgCtx, transaction);

      // commit the current transaction
      if(transaction != null && transaction.isActive()) transaction.commit();
      transaction = null;
     
    } catch (Exception e) {
      if (log.isDebugEnabled())
        log.debug("SandeshaInHandler::invoke Exception caught during processInMessage", e);
      // message should not be sent in a exception situation.
      msgCtx.pause();
      returnValue = InvocationResponse.SUSPEND;
     
      // Rethrow the original exception if it is an AxisFault
      if (e instanceof AxisFault)
        throw (AxisFault)e;
     
      String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.inMsgError, e.toString());
      throw new AxisFault(message, e);
    }
    finally {
      if (log.isDebugEnabled()) log.debug("SandeshaInHandler::invoke Doing final processing");
      if (transaction != null && transaction.isActive()) {
        try {
          transaction.rollback();
          transaction = null;
        } catch (Exception e) {
          String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.rollbackError, e.toString());
          log.debug(message, e);
        }
View Full Code Here

TOP

Related Classes of org.apache.sandesha2.storage.Transaction

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.