Package org.apache.sandesha2.storage

Examples of org.apache.sandesha2.storage.Transaction


      }
     
      return;
    }

    Transaction lastUpdatedTimeTransaction = storageManager.getTransaction();
   
    //updating the last activated time of the sequence.
    SequenceManager.updateLastActivatedTime(sequenceId,configCtx);
    lastUpdatedTimeTransaction.commit();
   
    Transaction updataMsgStringTransaction = storageManager
        .getTransaction();
   
    SequencePropertyBean msgsBean = seqPropMgr.retrieve(sequenceId,
        Sandesha2Constants.SequenceProperties.SERVER_COMPLETED_MESSAGES);

    long msgNo = sequence.getMessageNumber().getMessageNumber();
    if (msgNo == 0) {
      String message = "Wrong message number";
      log.debug(message);
      throw new SandeshaException(message);
    }
   
    String key = SandeshaUtil.getUUID()//key to store the message.
   
    //updating the Highest_In_Msg_No property which gives the highest message number retrieved from this sequence.
    String highetsInMsgNoStr = SandeshaUtil.getSequenceProperty(sequenceId,Sandesha2Constants.SequenceProperties.HIGHEST_IN_MSG_NUMBER,configCtx);
    String highetsInMsgKey = SandeshaUtil.getSequenceProperty(sequenceId,Sandesha2Constants.SequenceProperties.HIGHEST_IN_MSG_KEY,configCtx);
   
    long highestInMsgNo=0;
    if (highetsInMsgNoStr!=null) {
      highestInMsgNo = Long.parseLong(highetsInMsgNoStr);
    }
   
    if (msgNo>highestInMsgNo) {
      highestInMsgNo = msgNo;
     
      String str = new Long(msgNo).toString();
      SequencePropertyBean highestMsgNoBean = new SequencePropertyBean (sequenceId,Sandesha2Constants.SequenceProperties.HIGHEST_IN_MSG_NUMBER,str);
      SequencePropertyBean highestMsgKeyBean = new SequencePropertyBean (sequenceId,Sandesha2Constants.SequenceProperties.HIGHEST_IN_MSG_KEY,key);
     
      if (highetsInMsgNoStr!=null) {
        seqPropMgr.update(highestMsgNoBean);
        seqPropMgr.update(highestMsgKeyBean);
      }else{
        seqPropMgr.insert(highestMsgNoBean);
        seqPropMgr.insert(highestMsgKeyBean);
      }
    }
   
    String messagesStr = "";
    if (msgsBean!=null)
      messagesStr = (String) msgsBean.getValue();
    else {
      msgsBean = new SequencePropertyBean ();
      msgsBean.setSequenceID(sequenceId);
      msgsBean.setName(Sandesha2Constants.SequenceProperties.SERVER_COMPLETED_MESSAGES);
      msgsBean.setValue(messagesStr);
    }
     

    if (msgNoPresentInList(messagesStr, msgNo)
        && (Sandesha2Constants.QOS.InvocationType.DEFAULT_INVOCATION_TYPE == Sandesha2Constants.QOS.InvocationType.EXACTLY_ONCE)) {
      //this is a duplicate message and the invocation type is
      // EXACTLY_ONCE.
      rmMsgCtx.pause();
    }

    if (messagesStr != "" && messagesStr != null)
      messagesStr = messagesStr + "," + Long.toString(msgNo);
    else
      messagesStr = Long.toString(msgNo);

    msgsBean.setValue(messagesStr);
    seqPropMgr.update(msgsBean);

    updataMsgStringTransaction.commit();

    Transaction invokeTransaction = storageManager.getTransaction();

    //  Pause the messages bean if not the right message to invoke.
    NextMsgBeanMgr mgr = storageManager.getNextMsgBeanMgr();
    NextMsgBean bean = mgr.retrieve(sequenceId);

    if (bean == null)
      throw new SandeshaException("Error- The sequence does not exist");

    InvokerBeanMgr storageMapMgr = storageManager.getStorageMapBeanMgr();
   
    //inorder invocation is still a global property
    boolean inOrderInvocation = SandeshaUtil.getPropertyBean(msgCtx.getConfigurationContext().getAxisConfiguration()).isInOrder();
   
    if (inOrderInvocation) {
     
      //pause the message
      rmMsgCtx.pause();
     
      SequencePropertyBean incomingSequenceListBean = (SequencePropertyBean) seqPropMgr
          .retrieve(
              Sandesha2Constants.SequenceProperties.ALL_SEQUENCES,
              Sandesha2Constants.SequenceProperties.INCOMING_SEQUENCE_LIST);

      if (incomingSequenceListBean == null) {
        ArrayList incomingSequenceList = new ArrayList();
        incomingSequenceListBean = new SequencePropertyBean();
        incomingSequenceListBean
            .setSequenceID(Sandesha2Constants.SequenceProperties.ALL_SEQUENCES);
        incomingSequenceListBean
            .setName(Sandesha2Constants.SequenceProperties.INCOMING_SEQUENCE_LIST);
        incomingSequenceListBean.setValue(incomingSequenceList
            .toString());

        seqPropMgr.insert(incomingSequenceListBean);
      }

      ArrayList incomingSequenceList = SandeshaUtil
          .getArrayListFromString(incomingSequenceListBean.getValue());

      //Adding current sequence to the incoming sequence List.
      if (!incomingSequenceList.contains(sequenceId)) {
        incomingSequenceList.add(sequenceId);

        //saving the property.
        incomingSequenceListBean.setValue(incomingSequenceList
            .toString());
        seqPropMgr.insert(incomingSequenceListBean);
      }

      //saving the message.
      try {
        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");

      } catch (Exception ex) {
        throw new SandeshaException(ex.getMessage());
      }

      //Starting the invoker if stopped.
      SandeshaUtil
          .startInvokerForTheSequence(msgCtx.getConfigurationContext(),sequenceId);

    }

    invokeTransaction.commit();

    //Sending acknowledgements
    sendAckIfNeeded(rmMsgCtx, messagesStr);

  }
View Full Code Here


   
    //retrieving the the storage manager
    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configContext);
    SequencePropertyBeanMgr seqPropMgr = storageManager.getSequencePropretyBeanMgr();

    Transaction outHandlerTransaction = storageManager.getTransaction();
    boolean serverSide = msgContext.isServerSide()

    // setting message Id if null
    if (msgContext.getMessageID() == null)
      msgContext.setMessageID(SandeshaUtil.getUUID());

    // find internal sequence id
    String internalSequenceId = null;

    String storageKey = SandeshaUtil.getUUID()//the key which will be used to store this message.
   
    /* Internal sequence id is the one used to refer to the sequence (since
    actual sequence id is not available when first msg arrives)
    server side - a derivation of the sequenceId of the incoming sequence
    client side - a derivation of wsaTo & SeequenceKey */

    boolean lastMessage = false;
    if (serverSide) {
      // getting the request message and rmMessage.
      MessageContext reqMsgCtx;
      try {
        reqMsgCtx = msgContext.getOperationContext().getMessageContext(OperationContextFactory.MESSAGE_LABEL_IN_VALUE);
      } catch (AxisFault e) {
        throw new SandeshaException (e);
      }

      RMMsgContext requestRMMsgCtx = MsgInitializer.initializeMessage(reqMsgCtx);

      Sequence reqSequence = (Sequence) requestRMMsgCtx.getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE);
      if (reqSequence == null) {
        String message = "Sequence part is null";
        log.debug(message);
        throw new SandeshaException(message);
      }

      String incomingSeqId = reqSequence.getIdentifier().getIdentifier();
      if (incomingSeqId == null || incomingSeqId == "") {
        String message = "Invalid seqence Id";
        log.debug(message);
        throw new SandeshaException(message);
      }

      long requestMsgNo = reqSequence.getMessageNumber().getMessageNumber();
     
      internalSequenceId = SandeshaUtil.getOutgoingSideInternalSequenceID(incomingSeqId);
     
      //deciding weather the last message.
      String requestLastMsgNoStr = SandeshaUtil.getSequenceProperty(incomingSeqId,Sandesha2Constants.SequenceProperties.LAST_IN_MESSAGE_NO,configContext);
      if (requestLastMsgNoStr!=null) {
        long requestLastMsgNo = Long.parseLong(requestLastMsgNoStr);
        if (requestLastMsgNo==requestMsgNo)
          lastMessage = true;
      }

    } else {
      // set the internal sequence id for the client side.
      EndpointReference toEPR = msgContext.getTo();
      if (toEPR == null || toEPR.getAddress() == null || "".equals(toEPR.getAddress())) {
        String message = "TO End Point Reference is not set correctly. This is a must for the sandesha client side.";
        log.debug(message);
        throw new SandeshaException(message);
      }

      String to = toEPR.getAddress();
      String sequenceKey = (String) msgContext.getProperty(SandeshaClientConstants.SEQUENCE_KEY);
      internalSequenceId = SandeshaUtil.getInternalSequenceID(to,sequenceKey);
     
      String lastAppMessage = (String) msgContext.getProperty(SandeshaClientConstants.LAST_MESSAGE);
      if (lastAppMessage!=null && "true".equals(lastAppMessage))
        lastMessage = true;
    }

    /* checking weather the user has given the messageNumber (most of the cases this will not be the case where
       the system will generate the message numbers */

    //User should set it as a long object.
    Long messageNumberLng = (Long) msgContext.getProperty(SandeshaClientConstants.MESSAGE_NUMBER);
   
    long givenMessageNumber = -1;
    if (messageNumberLng!=null) {
      givenMessageNumber = messageNumberLng.longValue();
      if (givenMessageNumber<=0) {
        throw new SandeshaException ("The givem message number value is invalid (has to be larger than zero)");
      }
    }
   
    //the message number that was last used.
    long systemMessageNumber = getPreviousMsgNo(configContext, internalSequenceId);
   
    //The number given by the user has to be larger than the last stored number.
    if (givenMessageNumber>0 && givenMessageNumber<=systemMessageNumber) {
      String message = "The given message number is not larger than value of the last sent message.";
      throw new SandeshaException (message);
    }
   
    //Finding the correct message number.
    long messageNumber = -1;
    if (givenMessageNumber>0)          // if given message number is valid use it. (this is larger than the last stored due to the last check)
      messageNumber = givenMessageNumber;
    else if (systemMessageNumber>0) {  //if system message number is valid use it.
      messageNumber = systemMessageNumber+1;
    } else {         //This is the fist message (systemMessageNumber = -1)
      messageNumber = 1;
    }
   
    //A dummy message is a one which will not be processed as a actual application message.
    //The RM handlers will simply let these go.
    String dummyMessageString = (String) msgContext.getOptions().getProperty(SandeshaClientConstants.DUMMY_MESSAGE);
    boolean dummyMessage = false;
    if (dummyMessageString!=null && Sandesha2Constants.VALUE_TRUE.equals(dummyMessageString))
      dummyMessage = true;
   
    //saving the used message number
    if (!dummyMessage)
      setNextMsgNo(configContext,internalSequenceId,messageNumber);
     
    //set this as the response highest message.
    SequencePropertyBean responseHighestMsgBean = new SequencePropertyBean (
        internalSequenceId,
        Sandesha2Constants.SequenceProperties.HIGHEST_OUT_MSG_NUMBER,
        new Long (messageNumber).toString()
    );
    seqPropMgr.insert(responseHighestMsgBean);
   
    if (lastMessage) {
 
      SequencePropertyBean responseHighestMsgKeyBean = new SequencePropertyBean (
          internalSequenceId,
          Sandesha2Constants.SequenceProperties.HIGHEST_OUT_MSG_KEY,
          storageKey
      )
     
      SequencePropertyBean responseLastMsgKeyBean = new SequencePropertyBean (
          internalSequenceId,
          Sandesha2Constants.SequenceProperties.LAST_OUT_MESSAGE_NO,
          new Long (messageNumber).toString()
      )
     
      seqPropMgr.insert(responseHighestMsgKeyBean);
      seqPropMgr.insert(responseLastMsgKeyBean);
    }
   
    boolean sendCreateSequence = false;

    SequencePropertyBean outSeqBean = seqPropMgr.retrieve(
        internalSequenceId,
        Sandesha2Constants.SequenceProperties.OUT_SEQUENCE_ID);

    // setting async ack endpoint for the server side. (if present)
    if (serverSide) {
      String incomingSequenceID = SandeshaUtil
          .getServerSideIncomingSeqIdFromInternalSeqId(internalSequenceId);
      SequencePropertyBean incomingToBean = seqPropMgr.retrieve(
          incomingSequenceID,
          Sandesha2Constants.SequenceProperties.TO_EPR);
      if (incomingToBean != null) {
        String incomingTo = incomingToBean.getValue();
        msgContext.setProperty(SandeshaClientConstants.AcksTo, incomingTo);
      }
    }

   
    //FINDING THE SPEC VERSION
    String specVersion = null;
    if (msgContext.isServerSide()) {
      //in the server side, get the RM version from the request sequence.
      MessageContext requestMessageContext;
      try {
        requestMessageContext = msgContext.getOperationContext().getMessageContext(AxisOperationFactory.MESSAGE_LABEL_IN_VALUE);
      } catch (AxisFault e) {
        throw new SandeshaException (e);
      }
     
      if (requestMessageContext==null)
        throw new SandeshaException ("Request message context is null, cant find out the request side sequenceID");
     
      RMMsgContext requestRMMsgCtx = MsgInitializer.initializeMessage(requestMessageContext);
      Sequence sequence = (Sequence) requestRMMsgCtx.getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE);
     
      String requestSequenceID = sequence.getIdentifier().getIdentifier();
      SequencePropertyBean specVersionBean = seqPropMgr.retrieve(requestSequenceID,Sandesha2Constants.SequenceProperties.RM_SPEC_VERSION);
      if (specVersionBean==null)
        throw new SandeshaException ("SpecVersion sequence property bean is not available for the incoming sequence. Cant find the RM version for outgoing side");
     
      specVersion = specVersionBean.getValue();
    } else {
      //in the client side, user will set the RM version.
      specVersion = (String) msgContext.getProperty(SandeshaClientConstants.RM_SPEC_VERSION);
    }
   
    if (specVersion==null)
      specVersion = SpecSpecificConstants.getDefaultSpecVersion();   //TODO change the default to v1_1.
   
    if (messageNumber == 1) {
      if (outSeqBean == null) { // out sequence will be set for the server side, in the case of an offer.
        sendCreateSequence = true;   // message number being one and not having an out sequence, implies that a create sequence has to be send.
      }

      // if fist message - setup the sending side sequence - both for the server and the client sides
      SequenceManager.setupNewClientSequence(msgContext, internalSequenceId,specVersion);
    }

    ServiceContext serviceContext = msgContext.getServiceContext();
    OperationContext operationContext = msgContext.getOperationContext();
   
    //SENDING THE CREATE SEQUENCE.
    if (sendCreateSequence) {
      SequencePropertyBean responseCreateSeqAdded = seqPropMgr
          .retrieve(internalSequenceId,Sandesha2Constants.SequenceProperties.OUT_CREATE_SEQUENCE_SENT);

      String addressingNamespaceURI = SandeshaUtil.getSequenceProperty(internalSequenceId,Sandesha2Constants.SequenceProperties.ADDRESSING_NAMESPACE_VALUE,configContext);
      String anonymousURI = SpecSpecificConstants.getAddressingAnonymousURI(addressingNamespaceURI);
     
      if (responseCreateSeqAdded == null) {
        responseCreateSeqAdded = new SequencePropertyBean(
            internalSequenceId,Sandesha2Constants.SequenceProperties.OUT_CREATE_SEQUENCE_SENT,"true");
        seqPropMgr.insert(responseCreateSeqAdded);

        String acksTo = null;
        if (serviceContext != null)
          acksTo = (String) msgContext.getProperty(SandeshaClientConstants.AcksTo);

        if (msgContext.isServerSide()) {
          // we do not set acksTo value to anonymous when the create
          // sequence is send from the server.
          MessageContext requestMessage;
          try {
            requestMessage = operationContext.getMessageContext(OperationContextFactory.MESSAGE_LABEL_IN_VALUE);
          } catch (AxisFault e) {
            throw new SandeshaException (e);
          }
         
          if (requestMessage == null) {
            String message = "Request message is not present";
            log.debug(message);
            throw new SandeshaException(message);
          }
          acksTo = requestMessage.getTo().getAddress();

        } else {
          if (acksTo == null)
            acksTo = anonymousURI;
        }

        if (!anonymousURI.equals(acksTo) && !serverSide) {
          String transportIn = (String) configContext   //TODO verify
              .getProperty(MessageContext.TRANSPORT_IN);
          if (transportIn == null)
            transportIn = org.apache.axis2.Constants.TRANSPORT_HTTP;
        } else if (acksTo == null && serverSide) {
          String incomingSequencId = SandeshaUtil.getServerSideIncomingSeqIdFromInternalSeqId(internalSequenceId);
          SequencePropertyBean bean = seqPropMgr.retrieve(
              incomingSequencId,Sandesha2Constants.SequenceProperties.REPLY_TO_EPR);
          if (bean != null) {
            EndpointReference acksToEPR = new EndpointReference(bean.getValue());
            if (acksToEPR != null)
              acksTo = (String) acksToEPR.getAddress();
          }
        } else if (anonymousURI.equals(acksTo)) {
          // set transport in.
          Object trIn = msgContext.getProperty(MessageContext.TRANSPORT_IN);
          if (trIn == null) {
            //TODO
          }
        }
        addCreateSequenceMessage(rmMsgCtx, internalSequenceId, acksTo);
      }
    }

    SOAPEnvelope env = rmMsgCtx.getSOAPEnvelope();
    if (env == null) {
      SOAPEnvelope envelope = SOAPAbstractFactory.getSOAPFactory(
          SandeshaUtil.getSOAPVersion(env)).getDefaultEnvelope();
      rmMsgCtx.setSOAPEnvelop(envelope);
    }

    SOAPBody soapBody = rmMsgCtx.getSOAPEnvelope().getBody();
    if (soapBody == null) {
      String message = "Invalid SOAP message. Body is not present";
      log.debug(message);
      throw new SandeshaException(message);
    }

    String messageId1 = SandeshaUtil.getUUID();
    if (rmMsgCtx.getMessageId() == null) {
      rmMsgCtx.setMessageId(messageId1);
    }


    if (serverSide) {
      // let the request end with 202 if a ack has not been
      // written in the incoming thread.
     
      MessageContext reqMsgCtx = null;
      try {
        reqMsgCtx = msgContext.getOperationContext().getMessageContext(OperationContextFactory.MESSAGE_LABEL_IN_VALUE);
      } catch (AxisFault e) {
        throw new SandeshaException (e);
      }

      if (reqMsgCtx.getProperty(Sandesha2Constants.ACK_WRITTEN) == null
          || !"true".equals(reqMsgCtx.getProperty(Sandesha2Constants.ACK_WRITTEN)))
        reqMsgCtx.getOperationContext().setProperty(org.apache.axis2.Constants.RESPONSE_WRITTEN, "false");
    }
   
    EndpointReference toEPR = msgContext.getTo();
    if (toEPR == null) {
      String message = "To EPR is not found";
      log.debug(message);
      throw new SandeshaException(message);
    }
   
    //setting default actions.
    String to = toEPR.getAddress();
    String operationName = msgContext.getOperationContext().getAxisOperation().getName().getLocalPart();
    if (msgContext.getWSAAction() == null) {
      msgContext.setWSAAction(to + "/" + operationName);
    }
    if (msgContext.getSoapAction() == null) {
      msgContext.setSoapAction("\"" + to + "/" + operationName + "\"");
    }
   
    // processing the response if not an dummy.
    if (!dummyMessage)
      processResponseMessage(rmMsgCtx, internalSequenceId, messageNumber,storageKey);
   
    msgContext.pause()// the execution will be stopped.
    outHandlerTransaction.commit();   

  }
View Full Code Here

   
    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configurationContext);
    SequencePropertyBeanMgr seqPropMgr = storageManager.getSequencePropretyBeanMgr();
    CreateSeqBeanMgr createSeqMgr = storageManager.getCreateSeqBeanMgr();
   
    Transaction reportTransaction = storageManager.getTransaction();
   
    sequenceReport.setInternalSequenceID(internalSequenceID);
   
    CreateSeqBean createSeqFindBean = new CreateSeqBean ();
    createSeqFindBean.setInternalSequenceID(internalSequenceID);
   
    CreateSeqBean createSeqBean = createSeqMgr.findUnique(createSeqFindBean);
   
    //if data not is available sequence has to be terminated or timedOut.
    if (createSeqBean==null) {
     
      //check weather this is an terminated sequence.
      if (isSequenceTerminated(internalSequenceID,seqPropMgr)) {
        fillTerminatedOutgoingSequenceInfo (sequenceReport,internalSequenceID,seqPropMgr);
       
        return sequenceReport;
      }
     
      if (isSequenceTimedout(internalSequenceID,seqPropMgr)) {
        fillTimedoutOutgoingSequenceInfo (sequenceReport,internalSequenceID,seqPropMgr);
       
        return sequenceReport;
      }
   
      //sequence must hv been timed out before establiching. No other posibility I can think of.
      //this does not get recorded since there is no key (which is normally the sequenceID) to store it.
      //(properties with key as the internalSequenceID get deleted in timing out)
     
      //so, setting the sequence status to INITIAL
      sequenceReport.setSequenceStatus(SequenceReport.SEQUENCE_STATUS_INITIAL);
     
      //returning the current sequence report.
      return sequenceReport;
    }
   
    String outSequenceID = createSeqBean.getSequenceID();
    if (outSequenceID==null) {
       sequenceReport.setInternalSequenceID(internalSequenceID);
       sequenceReport.setSequenceStatus(SequenceReport.SEQUENCE_STATUS_INITIAL);
       sequenceReport.setSequenceDirection(SequenceReport.SEQUENCE_DIRECTION_OUT);
      
       return sequenceReport;
    }
   
    sequenceReport.setSequenceStatus(SequenceReport.SEQUENCE_STATUS_ESTABLISHED);
    fillOutgoingSequenceInfo(sequenceReport,outSequenceID,seqPropMgr);
   
    reportTransaction.commit();
   
    return sequenceReport; 
  }
View Full Code Here

    return sequenceTimedOut;
  }
 
  public static long getOutGoingSequenceAckedMessageCount (String internalSequenceID,ConfigurationContext configurationContext) throws SandeshaException {
    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configurationContext);
    Transaction transaction = storageManager.getTransaction();
    SequencePropertyBeanMgr seqPropBeanMgr = storageManager.getSequencePropretyBeanMgr();
   
    SequencePropertyBean findSeqIDBean = new SequencePropertyBean ();
    findSeqIDBean.setValue(internalSequenceID);
    findSeqIDBean.setName(Sandesha2Constants.SequenceProperties.INTERNAL_SEQUENCE_ID);
    Collection seqIDBeans = seqPropBeanMgr.find(findSeqIDBean);
   
    if (seqIDBeans.size()==0) {
      String message = "A sequence with give data has not been created";
      log.debug(message);
      throw new SandeshaException (message);
    }
   
    if (seqIDBeans.size()>1) {
      String message = "Sequence data is not unique. Cant generate report";
      log.debug(message);
      throw new SandeshaException (message);
    }
   
    SequencePropertyBean seqIDBean = (SequencePropertyBean) seqIDBeans.iterator().next();
    String sequenceID = seqIDBean.getSequenceID();

    SequencePropertyBean ackedMsgBean = seqPropBeanMgr.retrieve(sequenceID,Sandesha2Constants.SequenceProperties.NO_OF_OUTGOING_MSGS_ACKED);
    if (ackedMsgBean==null)
      return 0; //No acknowledgement has been received yet.
   
    long noOfMessagesAcked = Long.parseLong(ackedMsgBean.getValue());
    transaction.commit();
   
    return noOfMessagesAcked;
  }
View Full Code Here

    return noOfMessagesAcked;
  }
 
  public static boolean isOutGoingSequenceCompleted (String internalSequenceID,ConfigurationContext configurationContext) throws SandeshaException {
    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configurationContext);
    Transaction transaction = storageManager.getTransaction();
    SequencePropertyBeanMgr seqPropBeanMgr = storageManager.getSequencePropretyBeanMgr();
   
    SequencePropertyBean findSeqIDBean = new SequencePropertyBean ();
    findSeqIDBean.setValue(internalSequenceID);
    findSeqIDBean.setName(Sandesha2Constants.SequenceProperties.INTERNAL_SEQUENCE_ID);
    Collection seqIDBeans = seqPropBeanMgr.find(findSeqIDBean);
   
    if (seqIDBeans.size()==0) {
      String message = "A sequence with give data has not been created";
      log.debug(message);
      throw new SandeshaException (message);
    }
   
    if (seqIDBeans.size()>1) {
      String message = "Sequence data is not unique. Cant generate report";
      log.debug(message);
      throw new SandeshaException (message);
    }
   
    SequencePropertyBean seqIDBean = (SequencePropertyBean) seqIDBeans.iterator().next();
    String sequenceID = seqIDBean.getSequenceID();
   
    SequencePropertyBean terminateAddedBean = seqPropBeanMgr.retrieve(sequenceID,Sandesha2Constants.SequenceProperties.TERMINATE_ADDED);
    if (terminateAddedBean==null)
      return false;
   
    if ("true".equals(terminateAddedBean.getValue()))
      return true;

    transaction.commit();
    return false;
  }
View Full Code Here

  }
 
  public static boolean isIncomingSequenceCompleted (String sequenceID, ConfigurationContext configurationContext) throws SandeshaException {
   
    StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configurationContext);
    Transaction transaction = storageManager.getTransaction();
    SequencePropertyBeanMgr seqPropBeanMgr = storageManager.getSequencePropretyBeanMgr();
   
    SequencePropertyBean terminateReceivedBean = seqPropBeanMgr.retrieve(sequenceID,Sandesha2Constants.SequenceProperties.TERMINATE_RECEIVED);
    boolean complete = false;
   
    if (terminateReceivedBean!=null && "true".equals(terminateReceivedBean.getValue()))
      complete = true;
   
    transaction.commit();
    return complete;
  }
View Full Code Here

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

      Transaction asyncAckTransaction = storageManager.getTransaction();

      SenderBeanMgr retransmitterBeanMgr = storageManager
          .getRetransmitterBeanMgr();

      String key = SandeshaUtil.getUUID();
     
      //dumping to the storage will be done be Sandesha2 Transport Sender
      //storageManager.storeMessageContext(key,ackMsgCtx);
     
      SenderBean ackBean = new SenderBean();
      ackBean.setMessageContextRefKey(key);
      ackBean.setMessageID(ackMsgCtx.getMessageID());
      ackBean.setReSend(false);
      ackBean.setSequenceID(sequenceID);
     
      //this will be set to true in the sender.
      ackBean.setSend(true);
     
      ackMsgCtx.setProperty(Sandesha2Constants.QUALIFIED_FOR_SENDING,
          Sandesha2Constants.VALUE_FALSE);
     
      ackBean.setMessageType(Sandesha2Constants.MessageTypes.ACK);
     
      //the internalSequenceId value of the retransmitter Table for the
      // messages related to an incoming
      //sequence is the actual sequence ID

      //operation is the lowest level, Sandesha2 can be engaged.
      SandeshaPropertyBean propertyBean = SandeshaUtil.getPropertyBean(msgContext.getAxisOperation());
     
     
      long ackInterval = propertyBean.getAcknowledgementInaterval();
     
      //Ack will be sent as stand alone, only after the retransmitter
      // interval.
      long timeToSend = System.currentTimeMillis() + ackInterval;

      //removing old acks.
      SenderBean findBean = new SenderBean();
      findBean.setMessageType(Sandesha2Constants.MessageTypes.ACK);
     
      //this will be set to true in the sandesha2TransportSender.
      findBean.setSend(true);
      findBean.setReSend(false);
      Collection coll = retransmitterBeanMgr.find(findBean);
      Iterator it = coll.iterator();

      if (it.hasNext()) {
        SenderBean oldAckBean = (SenderBean) it.next();
        timeToSend = oldAckBean.getTimeToSend();    //If there is an old ack. This ack will be sent in the old timeToSend.
        retransmitterBeanMgr.delete(oldAckBean.getMessageID());
      }
     
      ackBean.setTimeToSend(timeToSend);

      storageManager.storeMessageContext(key,ackMsgCtx);
     
      //inserting the new ack.
      retransmitterBeanMgr.insert(ackBean);

      asyncAckTransaction.commit();

      //passing the message through sandesha2sender

      ackMsgCtx.setProperty(Sandesha2Constants.ORIGINAL_TRANSPORT_OUT_DESC,ackMsgCtx.getTransportOut());
      ackMsgCtx.setProperty(Sandesha2Constants.SET_SEND_TO_TRUE,Sandesha2Constants.VALUE_TRUE);
View Full Code Here

    }
   
        String internalSequenceID = SandeshaUtil.getSequenceProperty(outSequenceId,Sandesha2Constants.SequenceProperties.INTERNAL_SEQUENCE_ID,configCtx);
   
        //updating the last activated time of the sequence.
    Transaction lastUpdatedTimeTransaction = storageManager.getTransaction();
    SequenceManager.updateLastActivatedTime(internalSequenceID,rmMsgCtx.getMessageContext().getConfigurationContext());
    lastUpdatedTimeTransaction.commit();
   
    //Starting transaction
    Transaction ackTransaction = storageManager.getTransaction();

    SequencePropertyBean internalSequenceBean = seqPropMgr.retrieve(
        outSequenceId, Sandesha2Constants.SequenceProperties.INTERNAL_SEQUENCE_ID);

    if (internalSequenceBean == null || internalSequenceBean.getValue() == null) {
      String message = "TempSequenceId is not set correctly";
      log.debug(message);
      throw new SandeshaException(message);
    }

    String internalSequenceId = (String) internalSequenceBean.getValue();

    //Following happens in the SandeshaGlobal handler
    rmMsgCtx.getMessageContext()
        .setProperty(Sandesha2Constants.ACK_PROCSSED, "true");

    //Removing relatesTo - Some v1_0 endpoints tend to set relatesTo value for ack messages.
    //Because of this dispatching may go wrong. So we set relatesTo value to null for ackMessages.
    //(this happens in the SandeshaGlobal handler). Do this only if this is a standalone ACK.
//    if (rmMsgCtx.getMessageType() == Sandesha2Constants.MessageTypes.ACK)
//      rmMsgCtx.setRelatesTo(null);

    SenderBean input = new SenderBean();
    input.setSend(true);
    input.setReSend(true);
    Collection retransmitterEntriesOfSequence = retransmitterMgr
        .find(input);

    ArrayList ackedMessagesList = new ArrayList ();
    while (ackRangeIterator.hasNext()) {
      AcknowledgementRange ackRange = (AcknowledgementRange) ackRangeIterator
          .next();
      long lower = ackRange.getLowerValue();
      long upper = ackRange.getUpperValue();

      for (long messageNo = lower; messageNo <= upper; messageNo++) {
        SenderBean retransmitterBean = getRetransmitterEntry(
            retransmitterEntriesOfSequence, messageNo);
        if (retransmitterBean != null)
          retransmitterMgr.delete(retransmitterBean.getMessageID());
       
        ackedMessagesList.add(new Long (messageNo));
      }
    }

    while (nackIterator.hasNext()) {
      Nack nack = (Nack) nackIterator.next();
      long msgNo = nack.getNackNumber();

      //TODO - Process Nack
    }
   
    //setting acked message date.
    //TODO add details specific to each message.
    long noOfMsgsAcked = getNoOfMessagesAcked(sequenceAck.getAcknowledgementRanges().iterator());
    SequencePropertyBean noOfMsgsAckedBean = seqPropMgr.retrieve(outSequenceId,Sandesha2Constants.SequenceProperties.NO_OF_OUTGOING_MSGS_ACKED);
    boolean added = false;
   
    if (noOfMsgsAckedBean==null) {
      added = true;
      noOfMsgsAckedBean = new SequencePropertyBean ();
      noOfMsgsAckedBean.setSequenceID(outSequenceId);
      noOfMsgsAckedBean.setName(Sandesha2Constants.SequenceProperties.NO_OF_OUTGOING_MSGS_ACKED);
    }
   
    noOfMsgsAckedBean.setValue(Long.toString(noOfMsgsAcked));
   
    if (added)
      seqPropMgr.insert(noOfMsgsAckedBean);
    else
      seqPropMgr.update(noOfMsgsAckedBean);
   
   
    //setting the completed_messages list. This gives all the messages of the sequence that were acked.
    SequencePropertyBean allCompletedMsgsBean = seqPropMgr.retrieve(internalSequenceId,Sandesha2Constants.SequenceProperties.CLIENT_COMPLETED_MESSAGES);
    if (allCompletedMsgsBean==null) {
      allCompletedMsgsBean = new SequencePropertyBean ();
      allCompletedMsgsBean.setSequenceID(internalSequenceId);
      allCompletedMsgsBean.setName(Sandesha2Constants.SequenceProperties.CLIENT_COMPLETED_MESSAGES);
     
      seqPropMgr.insert(allCompletedMsgsBean);
    }
       
    String str = ackedMessagesList.toString();
    allCompletedMsgsBean.setValue(str);
   
    seqPropMgr.update(allCompletedMsgsBean);   
   
    //commiting transaction
    ackTransaction.commit();
   
    String lastOutMsgNoStr = SandeshaUtil.getSequenceProperty(internalSequenceId,Sandesha2Constants.SequenceProperties.LAST_OUT_MESSAGE_NO,configCtx);
    if (lastOutMsgNoStr!=null ) {
      long highestOutMsgNo = 0;
      if (lastOutMsgNoStr!=null) {
View Full Code Here

      .getMessageContext().getConfigurationContext();   
    StorageManager storageManager = SandeshaUtil
      .getSandeshaStorageManager(configCtx);
   
    //Processing for ack if available
    Transaction ackProcessTransaction = storageManager.getTransaction();
   
    SequenceAcknowledgement sequenceAck = (SequenceAcknowledgement) createSeqResponseRMMsgCtx
        .getMessagePart(Sandesha2Constants.MessageParts.SEQ_ACKNOWLEDGEMENT);
    if (sequenceAck != null) {
      AcknowledgementProcessor ackProcessor = new AcknowledgementProcessor();
      ackProcessor.processInMessage(createSeqResponseRMMsgCtx);
    }

    ackProcessTransaction.commit();
   
    //Processing the create sequence response.
   
    Transaction createSeqResponseTransaction = storageManager.getTransaction();
   
    CreateSequenceResponse createSeqResponsePart = (CreateSequenceResponse) createSeqResponseRMMsgCtx
        .getMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ_RESPONSE);
    if (createSeqResponsePart == null) {
      String message = "Create Sequence Response part is null";
      log.debug(message);
      throw new SandeshaException(message);
    }

    String newOutSequenceId = createSeqResponsePart.getIdentifier()
        .getIdentifier();
    if (newOutSequenceId == null) {
      String message = "New sequence Id is null";
      log.debug(message);
      throw new SandeshaException(message);
    }

    RelatesTo relatesTo = createSeqResponseRMMsgCtx.getMessageContext()
                    .getRelatesTo();
    if (relatesTo==null) {
      String message = "Invalid create sequence message. RelatesTo part is not available";
      log.error("Invalid create sequence response message. RelatesTo part is not available");
      throw new SandeshaException ("Invalid create sequence message. RelatesTo part is not available");
    }
    String createSeqMsgId = relatesTo.getValue();


    SenderBeanMgr retransmitterMgr = storageManager
        .getRetransmitterBeanMgr();
    CreateSeqBeanMgr createSeqMgr = storageManager.getCreateSeqBeanMgr();

    CreateSeqBean createSeqBean = createSeqMgr.retrieve(createSeqMsgId);
    if (createSeqBean == null) {
      String message = "Create Sequence entry is not found";
      log.debug(message);
      throw new SandeshaException(message);
    }

    String internalSequenceId = createSeqBean.getInternalSequenceID();
    if (internalSequenceId == null || "".equals(internalSequenceId)) {
      String message = "TempSequenceId has is not set";
      log.debug(message);
      throw new SandeshaException(message);
    }
   
    createSeqBean.setSequenceID(newOutSequenceId);
    createSeqMgr.update(createSeqBean);

    //deleting the create sequence entry.
    retransmitterMgr.delete(createSeqMsgId);

    //storing new out sequence id
    SequencePropertyBeanMgr sequencePropMgr = storageManager
        .getSequencePropretyBeanMgr();
    SequencePropertyBean outSequenceBean = new SequencePropertyBean(
        internalSequenceId, Sandesha2Constants.SequenceProperties.OUT_SEQUENCE_ID,
        newOutSequenceId);
    SequencePropertyBean internalSequenceBean = new SequencePropertyBean(
        newOutSequenceId,
        Sandesha2Constants.SequenceProperties.INTERNAL_SEQUENCE_ID, internalSequenceId);
   
   
    sequencePropMgr.insert(outSequenceBean);
    sequencePropMgr.insert(internalSequenceBean);

    createSeqResponseTransaction.commit();
   
   
    Transaction offerProcessTransaction = storageManager.getTransaction();
   
    //processing for accept (offer has been sent)
    Accept accept = createSeqResponsePart.getAccept();
    if (accept != null) {
      //Find offered sequence from internal sequence id.
      SequencePropertyBean offeredSequenceBean = sequencePropMgr
          .retrieve(internalSequenceId,
              Sandesha2Constants.SequenceProperties.OFFERED_SEQUENCE);

      //TODO this should be detected in the Fault manager.
      if (offeredSequenceBean == null) {
        String message = "No offered sequence entry. But an accept was received";
        log.debug(message);
        throw new SandeshaException(message);
      }

      String offeredSequenceId = (String) offeredSequenceBean.getValue();

      EndpointReference acksToEPR = accept.getAcksTo().getAddress()
          .getEpr();
      SequencePropertyBean acksToBean = new SequencePropertyBean();
      acksToBean.setName(Sandesha2Constants.SequenceProperties.ACKS_TO_EPR);
      acksToBean.setSequenceID(offeredSequenceId);
      acksToBean.setValue(acksToEPR.getAddress());

      sequencePropMgr.insert(acksToBean);

      NextMsgBean nextMsgBean = new NextMsgBean();
      nextMsgBean.setSequenceID(offeredSequenceId);
      nextMsgBean.setNextMsgNoToProcess(1);

      NextMsgBeanMgr nextMsgMgr = storageManager.getNextMsgBeanMgr();
      nextMsgMgr.insert(nextMsgBean);
     
      String rmSpecVersion = createSeqResponseRMMsgCtx.getRMSpecVersion();
     
      SequencePropertyBean specVersionBean = new SequencePropertyBean (
          offeredSequenceId,Sandesha2Constants.SequenceProperties.RM_SPEC_VERSION,rmSpecVersion);
      sequencePropMgr.insert(specVersionBean);
     
      SequencePropertyBean receivedMsgBean = new SequencePropertyBean(
          offeredSequenceId, Sandesha2Constants.SequenceProperties.SERVER_COMPLETED_MESSAGES, "");
      sequencePropMgr.insert(receivedMsgBean);
     
      SequencePropertyBean msgsBean = new SequencePropertyBean();
      msgsBean.setSequenceID(offeredSequenceId);
      msgsBean.setName(Sandesha2Constants.SequenceProperties.CLIENT_COMPLETED_MESSAGES);
      msgsBean.setValue("");
      sequencePropMgr.insert(msgsBean);
     
     
      //setting the addressing version.
      String addressingNamespace = createSeqResponseRMMsgCtx.getAddressingNamespaceValue();
      SequencePropertyBean addressingVersionBean = new SequencePropertyBean (
          offeredSequenceId,Sandesha2Constants.SequenceProperties.ADDRESSING_NAMESPACE_VALUE,addressingNamespace);
      sequencePropMgr.insert(addressingVersionBean);
     
    }

    offerProcessTransaction.commit();
   
    Transaction updateAppMessagesTransaction = storageManager.getTransaction();
   
    SenderBean target = new SenderBean();
    target.setInternalSequenceID(internalSequenceId);
    target.setSend(false);
    target.setReSend(true);

    Iterator iterator = retransmitterMgr.find(target).iterator();
    while (iterator.hasNext()) {
      SenderBean tempBean = (SenderBean) iterator.next();

      //updating the application message
      String key = tempBean.getMessageContextRefKey();
      MessageContext applicationMsg = storageManager.retrieveMessageContext(key,configCtx);

      //TODO make following exception message more understandable to the user (probably some others exceptions messages as well)
      if (applicationMsg==null)
        throw new SandeshaException ("Unavailable application message");
     
      String rmVersion = SandeshaUtil.getRMVersion(internalSequenceId,configCtx);
      if (rmVersion==null)
        throw new SandeshaException ("Cant find the rmVersion of the given message");
     
      String assumedRMNamespace = SpecSpecificConstants.getRMNamespaceValue(rmVersion);
     
      RMMsgContext applicaionRMMsg = MsgInitializer
          .initializeMessage(applicationMsg);

      Sequence sequencePart = (Sequence) applicaionRMMsg
          .getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE);
      if (sequencePart == null) {
        String message = "Sequence part is null";
        log.debug(message);
        throw new SandeshaException(message);
      }
     
      Identifier identifier = new Identifier(factory,assumedRMNamespace);
      identifier.setIndentifer(newOutSequenceId);

      sequencePart.setIdentifier(identifier);

      AckRequested ackRequestedPart = (AckRequested) applicaionRMMsg
          .getMessagePart(Sandesha2Constants.MessageParts.ACK_REQUEST);
      if (ackRequestedPart != null) {
        Identifier id1 = new Identifier(factory,assumedRMNamespace);
        id1.setIndentifer(newOutSequenceId);
        ackRequestedPart.setIdentifier(id1);
      }

      try {
        applicaionRMMsg.addSOAPEnvelope();
      } catch (AxisFault e) {
        throw new SandeshaException(e.getMessage());
      }
     
      //asking to send the application msssage
      tempBean.setSend(true);
      retransmitterMgr.update(tempBean);
     
      //updating the message. this will correct the SOAP envelope string.
      storageManager.updateMessageContext(key,applicationMsg);
    }

    updateAppMessagesTransaction.commit();
   
    Transaction lastUpdatedTimeTransaction = storageManager.getTransaction();
    SequenceManager.updateLastActivatedTime(internalSequenceId,configCtx);
    lastUpdatedTimeTransaction.commit();
   
    createSeqResponseRMMsgCtx.getMessageContext().getOperationContext()
        .setProperty(org.apache.axis2.Constants.RESPONSE_WRITTEN,
            "false");
View Full Code Here

      ackRMMsgCtx.getMessageContext().setServerSide(true);
      return ackRMMsgCtx;
     
    } else {

      Transaction asyncAckTransaction = storageManager.getTransaction();

      SenderBeanMgr retransmitterBeanMgr = storageManager
          .getRetransmitterBeanMgr();

      String key = SandeshaUtil.getUUID();
     
      SenderBean ackBean = new SenderBean();
      ackBean.setMessageContextRefKey(key);
      ackBean.setMessageID(ackMsgCtx.getMessageID());
      ackBean.setReSend(false);
      ackBean.setSequenceID(sequenceID);
     
      //this will be set to true in the sender.
      ackBean.setSend(true);
     
      ackMsgCtx.setProperty(Sandesha2Constants.QUALIFIED_FOR_SENDING,
          Sandesha2Constants.VALUE_FALSE);
     
      ackBean.setMessageType(Sandesha2Constants.MessageTypes.ACK);
      long ackInterval = SandeshaUtil.getPropertyBean(referenceMsg.getAxisOperation()).getAcknowledgementInaterval();
     
      //Ack will be sent as stand alone, only after the retransmitter
      // interval.
      long timeToSend = System.currentTimeMillis() + ackInterval;

      //removing old acks.
      SenderBean findBean = new SenderBean();
      findBean.setMessageType(Sandesha2Constants.MessageTypes.ACK);
     
      //this will be set to true in the sandesha2TransportSender.
      findBean.setSend(true);
      findBean.setReSend(false);
      Collection coll = retransmitterBeanMgr.find(findBean);
      Iterator it = coll.iterator();

      if (it.hasNext()) {
        SenderBean oldAckBean = (SenderBean) it.next();
        timeToSend = oldAckBean.getTimeToSend();    //If there is an old ack. This ack will be sent in the old timeToSend.
        retransmitterBeanMgr.delete(oldAckBean.getMessageID());
      }
     
      ackBean.setTimeToSend(timeToSend);
      storageManager.storeMessageContext(key,ackMsgCtx);
     
      //inserting the new ack.
      retransmitterBeanMgr.insert(ackBean);
      asyncAckTransaction.commit();

      //passing the message through sandesha2sender
      ackMsgCtx.setProperty(Sandesha2Constants.ORIGINAL_TRANSPORT_OUT_DESC,ackMsgCtx.getTransportOut());
      ackMsgCtx.setProperty(Sandesha2Constants.SET_SEND_TO_TRUE,Sandesha2Constants.VALUE_TRUE);
      ackMsgCtx.setProperty(Sandesha2Constants.MESSAGE_STORE_KEY,key);
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.