Package org.apache.sandesha2.storage.beanmanagers

Examples of org.apache.sandesha2.storage.beanmanagers.SenderBeanMgr


       
        // Get the sequence id for this sequence.
        String sequenceId = SandeshaClient.getSequenceID(serviceClient);
       
        // Get the SenderBeanManager
        SenderBeanMgr senderManager = storageManager.getSenderBeanMgr();
           
        // Check that there are no sender beans inside the SenderBeanMgr.
        SenderBean senderBean = new SenderBean();
        senderBean.setSequenceID(sequenceId);
        senderBean.setSend(true);
        senderBean.setReSend(false);
       
        // Find any sender beans for the to address.
        List<SenderBean> beans = senderManager.find(senderBean);
        assertTrue("SenderBeans found when the list should be empty", beans.isEmpty());
       
        SequenceReport sequenceReport = SandeshaClient.getOutgoingSequenceReport(serviceClient);
       
        assertNotNull(sequenceReport.getSequenceID());
View Full Code Here


      // ack messages at this point, as if someone is sending duplicates then they may have
      // missed earlier acks. We also have special processing for sync 2-way when no make connection is
      // in use
      if(replyTo==null || replyTo.isWSAddressingAnonymous()) {

        SenderBeanMgr senderBeanMgr = storageManager.getSenderBeanMgr();
        SenderBean findSenderBean = new SenderBean ();
       
        if (rmMsgCtx.getMessageType()==Sandesha2Constants.MessageTypes.LAST_MESSAGE)
          findSenderBean.setMessageType(Sandesha2Constants.MessageTypes.LAST_MESSAGE);
        else
          findSenderBean.setMessageType(Sandesha2Constants.MessageTypes.APPLICATION);
       
        findSenderBean.setInboundSequenceId(sequence.getIdentifier().getIdentifier());
        findSenderBean.setInboundMessageNumber(sequence.getMessageNumber());
        findSenderBean.setSend(true);
   
        SenderBean replyMessageBean = senderBeanMgr.findUnique(findSenderBean);
         
        // this is effectively a poll for the replyMessage, so re-use the logic in the MakeConnection
        // processor. This will use this thread to re-send the reply, writing it into the transport.
        // As the reply is now written we do not want to continue processing, or suspend, so we abort.
        if(replyMessageBean != null) {
View Full Code Here

      String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.relatesToNotAvailable);
      log.error(message);
      throw new SandeshaException(message);
    }

    SenderBeanMgr retransmitterMgr = storageManager.getSenderBeanMgr();
    RMSBeanMgr rmsBeanMgr = storageManager.getRMSBeanMgr();

    RMSBean rmsBean = rmsBeanMgr.retrieve(createSeqMsgId);
    if (rmsBean == null) {
      if (log.isDebugEnabled())
        log.debug("Exit: FaultManager::processCreateSequenceRefusedFault Unable to find RMSBean");
      return;
    }
    if(rmsBean.getSequenceID()!=null){
      //we got a cseqRefused but the sequence is already setup - this implies a timing condition whereby several resends of the cSeqReq have been sent out.
      //The best thing to do here is to ignore it.
      if (log.isDebugEnabled())
        log.debug("Exit: FaultManager::processCreateSequenceRefusedFault Sequence already established - no requirement to cleanup");
      return;     
    }
   
    // Indicate that there was an error when sending the Create Sequence.
    rmsBean.setLastSendError(fault);
    // Mark the sequence as terminated
    rmsBean.setTerminated(true);
     
    // Update the RMSBean
    rmsBeanMgr.update(rmsBean);

    SenderBean createSequenceSenderBean = retransmitterMgr.retrieve(createSeqMsgId);
    if (createSequenceSenderBean == null)
      throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.createSeqEntryNotFound));

    // deleting the create sequence entry.
    retransmitterMgr.delete(createSeqMsgId);
     
    // Notify the clients of a failure
    notifyClientsOfFault(rmsBean.getInternalSequenceID(), storageManager, configCtx, fault);
   
    rmMsgCtx.pause();
View Full Code Here

    Transaction transaction = null;
   
    try {
      StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configurationContext, configurationContext.getAxisConfiguration());
      SenderBeanMgr senderBeanMgr = storageManager.getSenderBeanMgr();
     
      transaction = storageManager.getTransaction();

      String key = senderBean.getMessageContextRefKey();
      MessageContext msgCtx = null;
      RMMsgContext   rmMsgCtx = null;
      if(messageToSend != null) {
        msgCtx = messageToSend.getMessageContext();
        rmMsgCtx = messageToSend;
      } else {
        msgCtx = storageManager.retrieveMessageContext(key, configurationContext);
     
        if (msgCtx == null) {
          // This sender bean has already been processed
         
          if(transaction != null && transaction.isActive()) transaction.commit();
          transaction = null;

          return;
        }
     
        rmMsgCtx = MsgInitializer.initializeMessage(msgCtx);
      }

      // sender will not send the message if following property is
      // set and not true.
      // But it will set if it is not set (null)

      // This is used to make sure that the mesage get passed the
      // Sandesha2TransportSender.

      String qualifiedForSending = (String) msgCtx.getProperty(Sandesha2Constants.QUALIFIED_FOR_SENDING);
      if (qualifiedForSending != null && !qualifiedForSending.equals(Sandesha2Constants.VALUE_TRUE)) {
        if (log.isDebugEnabled())
          log.debug("Exit: SenderWorker::run, !qualified for sending");
       
        if(transaction != null && transaction.isActive()) {
          transaction.commit();
          transaction = null;
        }
       
        return;
      }

      if (msgCtx == null) {
        if (log.isDebugEnabled())
          log.debug(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.sendHasUnavailableMsgEntry));
       
        if(transaction != null && transaction.isActive()) {
          transaction.commit();
          transaction = null;
        }
       
        return;     
      }

      // operation is the lowest level Sandesha2 should be attached
      ArrayList<Integer> msgsNotToSend = SandeshaUtil.getPropertyBean(msgCtx.getAxisOperation()).getMsgTypesToDrop();

      if (msgsNotToSend != null && msgsNotToSend.contains(new Integer(rmMsgCtx.getMessageType()))) {
        if (log.isDebugEnabled())
          log.debug("Exit: SenderWorker::run, message type to be dropped " + rmMsgCtx.getMessageType());
       
        if(transaction != null && transaction.isActive()) {
          transaction.commit();
          transaction = null;
        }
       
        return
      }

      // If we are sending to the anonymous URI then we _must_ have a transport waiting,
      // or the message can't go anywhere. If there is nothing here then we leave the
      // message in the sender queue, and a MakeConnection (or a retransmitted request)
      // will hopefully pick it up soon.
      Boolean makeConnection = (Boolean) msgCtx.getProperty(Sandesha2Constants.MAKE_CONNECTION_RESPONSE);
      EndpointReference toEPR = msgCtx.getTo();

      MessageContext inMsg = null;
      OperationContext op = msgCtx.getOperationContext();
     
      RequestResponseTransport t = (RequestResponseTransport) msgCtx.getProperty(RequestResponseTransport.TRANSPORT_CONTROL);
     
      if (t==null) {
        if (op != null)
          inMsg = op.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
        if (inMsg != null)
          t = (RequestResponseTransport) inMsg.getProperty(RequestResponseTransport.TRANSPORT_CONTROL);
      }

      // If we are anonymous, and this is not a makeConnection, then we must have a transport waiting
      if((toEPR==null || toEPR.hasAnonymousAddress()) &&
         (makeConnection == null || !makeConnection.booleanValue()) &&
         (t == null || !t.getStatus().equals(RequestResponseTransportStatus.WAITING))) {
       
        // Mark this sender bean so that we know that the transport is unavailable, if the
        // bean is still stored.
        SenderBean bean = senderBeanMgr.retrieve(senderBean.getMessageID());
        if(bean != null && bean.isTransportAvailable()) {
          bean.setTransportAvailable(false);
          senderBeanMgr.update(bean);
        }
       
        // Commit the update
        if(transaction != null && transaction.isActive()) transaction.commit();
        transaction = null;
       
        if (log.isDebugEnabled())
          log.debug("Exit: SenderWorker::run, no response transport for anonymous message");
        return;
      }
     
      int messageType = senderBean.getMessageType();
     
      if (isAckPiggybackableMsgType(messageType)) {
        // Commit the update
        if(transaction != null && transaction.isActive()) transaction.commit();
        transaction = storageManager.getTransaction();

        // Piggyback ack messages based on the 'To' address of the message
        AcknowledgementManager.piggybackAcksIfPresent(rmMsgCtx, storageManager);
      }
      if (transaction != null && transaction.isActive())
        transaction.commit();     
     
      transaction = storageManager.getTransaction();

      /*Removing the sending of AckRequested msgs as has performance impact.
        It could be rewritten to send AckRequested headers infrequantly and
        hence be less of a performance impact.  Functionally it
        may be required to interop with other implementations but until
        the problem occurs it's best not to do it at all and keep performance
        as optimal as possible
      //If this is an application msg we need to add an ackRequest to the header   
      if(messageType == Sandesha2Constants.MessageTypes.APPLICATION){       
        //Add an ackRequest       
        RMSBean rmsBean = SandeshaUtil.getRMSBeanFromSequenceId(storageManager, senderBean.getSequenceID());       
        RMMsgCreator.addAckRequest(rmMsgCtx, senderBean.getSequenceID(), rmsBean);               
        if (transaction != null && transaction.isActive())          
          transaction.commit();
       
        transaction = storageManager.getTransaction();     
      } */
     
      //if this is a sync RM exchange protocol we always have to add an ack
      boolean ackPresent = false;
      Iterator it = rmMsgCtx.getSequenceAcknowledgements();
      if (it.hasNext())
        ackPresent = true;
     
      if (!ackPresent && toEPR.hasAnonymousAddress()
          && rmMsgCtx.getMessageContext().isServerSide()
          &&
        (messageType==Sandesha2Constants.MessageTypes.APPLICATION ||
           messageType==Sandesha2Constants.MessageTypes.UNKNOWN ||
           messageType==Sandesha2Constants.MessageTypes.LAST_MESSAGE)) {
       
        String inboundSequenceId = senderBean.getInboundSequenceId();
        if (inboundSequenceId==null)
          throw new SandeshaException ("InboundSequenceID is not set for the sequence:" + senderBean.getSequenceID());
       
        RMDBean incomingSequenceBean = SandeshaUtil.getRMDBeanFromSequenceId(storageManager, inboundSequenceId);

        if (incomingSequenceBean!=null)
          RMMsgCreator.addAckMessage(rmMsgCtx, inboundSequenceId, incomingSequenceBean, false, true);
      }

      if (transaction != null && transaction.isActive())
        transaction.commit();     
     
      transaction = storageManager.getTransaction();
     
      senderBean = updateMessage(rmMsgCtx,senderBean,storageManager);

      if (senderBean == null) {
        if (log.isDebugEnabled())
          log.debug("Exit: SenderWorker::run, !continueSending");
       
        if(transaction != null && transaction.isActive()) {
          transaction.rollback();
          transaction = null;
        }
       
        return;
      }

      // Although not actually sent yet, update the send count to indicate an attempt
      if (senderBean.isReSend()) {
        senderBeanMgr.update(senderBean);
      }

      // sending the message
      boolean successfullySent = false;
     
      // No need to redecorate application messages ... only for rm protocol messages
      if(Sandesha2Constants.MessageTypes.APPLICATION!=senderBean.getMessageType()){
        //try to redecorate the EPR if necessary
        if (log.isDebugEnabled())
          log.debug("Redecorate EPR : " + msgCtx.getEnvelope().getHeader());
        EndpointReference replyToEPR = msgCtx.getReplyTo();
        if(replyToEPR!=null){
          replyToEPR = SandeshaUtil.getEPRDecorator(msgCtx.getConfigurationContext()).decorateEndpointReference(replyToEPR);
          msgCtx.setReplyTo(replyToEPR);
        }
      }
      // have to commit the transaction before sending. This may
      // get changed when WS-AT is available.
      if(transaction != null) {
        transaction.commit();
        transaction = null;
      }

      boolean processResponseForFaults = false;
      try {
        InvocationResponse response = InvocationResponse.CONTINUE;
       
        if(storageManager.requiresMessageSerialization()) {
          if(msgCtx.isPaused()) {
            if (log.isDebugEnabled())
              log.debug("Resuming a send for message : " + msgCtx.getEnvelope().getHeader());
            msgCtx.setPaused(false);
            msgCtx.setProperty(MessageContext.CLIENT_API_NON_BLOCKING, Boolean.FALSE);
            response = AxisEngine.resumeSend(msgCtx);
          } else {
            if (log.isDebugEnabled())
              log.debug("Sending a message : " + msgCtx.getEnvelope().getHeader());
            msgCtx.setProperty(MessageContext.CLIENT_API_NON_BLOCKING, Boolean.FALSE);
            AxisEngine.send(msgCtx)// TODO check if this should return an invocation response
          }
        } else {
 
          ArrayList<Handler> retransmittablePhases = (ArrayList<Handler>) msgCtx.getProperty(Sandesha2Constants.RETRANSMITTABLE_PHASES);
          if (retransmittablePhases!=null) {
            msgCtx.setExecutionChain(retransmittablePhases);
          } else {
            ArrayList<Handler> emptyExecutionChain = new ArrayList<Handler>();
            msgCtx.setExecutionChain(emptyExecutionChain);
          }
         
          msgCtx.setCurrentHandlerIndex(0);
          msgCtx.setCurrentPhaseIndex(0);
          msgCtx.setPaused(false);
       
          if (log.isDebugEnabled())
            log.debug("Resuming a send for message : " + msgCtx.getEnvelope().getHeader());
              msgCtx.setProperty(MessageContext.CLIENT_API_NON_BLOCKING, Boolean.FALSE);
          response = AxisEngine.resumeSend(msgCtx);
        }
        if(log.isDebugEnabled()) log.debug("Engine resume returned " + response);
        if(response != InvocationResponse.SUSPEND) {
          if(t != null) {
            if(log.isDebugEnabled()) log.debug("Signalling transport in " + t);
            t.signalResponseReady();
          }
        }
       
        successfullySent = true;
       
      } catch (AxisFault e) {
        //this is a possible SOAP 1.2 Fault. So letting it proceed.
       
        processResponseForFaults = true;
       
        recordError(e, rmMsgCtx, storageManager);
       
      } catch (Exception e) {
        String message = SandeshaMessageHelper.getMessage(
            SandeshaMessageKeys.sendMsgError, e.toString());
       
        if (log.isDebugEnabled())
          log.debug(message, e);
       
        recordError(e, rmMsgCtx, storageManager);
       
      }
      // Establish the transaction for post-send processing
      transaction = storageManager.getTransaction();

      // update or delete only if the object is still present.
      SenderBean bean1 = senderBeanMgr
          .retrieve(senderBean.getMessageID());
      if (bean1 != null) {
        if (senderBean.isReSend()) {
          bean1.setTimeToSend(senderBean.getTimeToSend());
          senderBeanMgr.update(bean1);
        } else {
          senderBeanMgr.delete(bean1.getMessageID());

          // removing the message from the storage.
          String messageStoredKey = bean1.getMessageContextRefKey();
          storageManager.removeMessageContext(messageStoredKey);
        }
View Full Code Here

    if (log.isDebugEnabled())
      log.debug("Enter: ApplicationMsgProcessor::processResponseMessage, " + internalSequenceId + ", " + outSequenceID);

    MessageContext msg = rmMsg.getMessageContext();

    SenderBeanMgr retransmitterMgr = storageManager.getSenderBeanMgr();

    // setting last message
    boolean lastMessage = false;
    if (msg.isServerSide()) {
      Boolean inboundLast = (Boolean) msg.getProperty(Sandesha2Constants.MessageContextProperties.INBOUND_LAST_MESSAGE);
      if (inboundLast != null && inboundLast.booleanValue()) {
        lastMessage = true;
      }

    } else {
      // client side
      Object obj = msg.getProperty(SandeshaClientConstants.LAST_MESSAGE);
      if (obj != null && "true".equals(obj)) {
        lastMessage = true;
      }
    }

    boolean sendingNow = false;
    if(outSequenceID != null && !hasUserTransaction) {
      sendingNow = true;
    }
   
    // Now that we have decided which sequence to use for the message, make sure that we secure
    // it with the correct token.
    RMMsgCreator.secureOutboundMessage(rmsBean, msg);

    // Retransmitter bean entry for the application message
    SenderBean appMsgEntry = new SenderBean();

    appMsgEntry.setMessageContextRefKey(storageKey);

    appMsgEntry.setTimeToSend(System.currentTimeMillis());
    appMsgEntry.setMessageID(rmMsg.getMessageId());
    appMsgEntry.setMessageNumber(messageNumber);
    appMsgEntry.setLastMessage(lastMessage);
   
    SOAPEnvelope envelope = rmMsg.getSOAPEnvelope();
    if (lastMessage && envelope!=null && envelope.getBody().getFirstOMChild()==null)
      appMsgEntry.setMessageType(Sandesha2Constants.MessageTypes.LAST_MESSAGE);
    else
      appMsgEntry.setMessageType(Sandesha2Constants.MessageTypes.APPLICATION);
   
    appMsgEntry.setInboundSequenceId(inboundSequence);
    appMsgEntry.setInboundMessageNumber(inboundMessageNumber);
    if (outSequenceID == null) {
      appMsgEntry.setSend(false);
    } else {
      appMsgEntry.setSend(true);
      // Send will be set to true at the sender.
      msg.setProperty(Sandesha2Constants.SET_SEND_TO_TRUE, Sandesha2Constants.VALUE_TRUE);
      appMsgEntry.setSequenceID(outSequenceID);
    }
   
    EndpointReference to = rmMsg.getTo();
    if (to!=null)
      appMsgEntry.setToAddress(to.getAddress());
   
    appMsgEntry.setInternalSequenceID(internalSequenceId);

    msg.setProperty(Sandesha2Constants.QUALIFIED_FOR_SENDING, Sandesha2Constants.VALUE_FALSE);

    // increasing the current handler index, so that the message will not be
    // going throught the SandeshaOutHandler again.
    msg.setCurrentHandlerIndex(msg.getCurrentHandlerIndex() + 1);

    SandeshaUtil.executeAndStore(rmMsg, storageKey, storageManager);
   
    // Insert the SenderBean
    retransmitterMgr.insert(appMsgEntry);

    // Lock the sender bean before we insert it, if we are planning to send it ourselves
    SenderWorker worker = null;
    if(sendingNow) {
      String workId = appMsgEntry.getMessageID() + appMsgEntry.getTimeToSend();
View Full Code Here

      makeConnectionSenderBean.setSequenceID(rmBean.getSequenceID());
      EndpointReference to = makeConnectionRMMessage.getTo();
      if (to!=null)
        makeConnectionSenderBean.setToAddress(to.getAddress());

      SenderBeanMgr senderBeanMgr = storageManager.getSenderBeanMgr();
     
      //this message should not be sent until it is qualified. I.e. till it is sent through the Sandesha2TransportSender.
      makeConnectionRMMessage.setProperty(Sandesha2Constants.QUALIFIED_FOR_SENDING, Sandesha2Constants.VALUE_FALSE);
     
          SandeshaUtil.executeAndStore(makeConnectionRMMessage, makeConnectionMsgStoreKey, storageManager);
     
      senderBeanMgr.insert(makeConnectionSenderBean);     
    }
   
    if(log.isDebugEnabled()) log.debug("Exit: PollingManager::pollForSequence");
  }
View Full Code Here

    //removing any un-sent ack messages.
    SenderBean findAckBean = new SenderBean ();
    findAckBean.setSequenceID(sequenceId);
    findAckBean.setMessageType(Sandesha2Constants.MessageTypes.ACK);
   
    SenderBeanMgr senderBeanMgr = storageManager.getSenderBeanMgr();
    Iterator<SenderBean> ackBeans = senderBeanMgr.find(findAckBean).iterator();
    while (ackBeans.hasNext()) {
      SenderBean ackBean = (SenderBean) ackBeans.next();
      senderBeanMgr.delete(ackBean.getMessageID());
     
      storageManager.removeMessageContext(ackBean.getMessageContextRefKey());
    }
   
    // Currently in-order invocation is done for default values.
View Full Code Here

    if(LoggingControl.isAnyTracingEnabled() && log.isDebugEnabled())
      log.debug("Enter: TerminateManager::cleanSendingSideData " + internalSequenceId + ", " + reallocateIfPossible);
   
    boolean reallocatedOK = false;
    SenderBeanMgr retransmitterBeanMgr = storageManager.getSenderBeanMgr();

    // removing retransmitterMgr entries and corresponding message contexts.
    Collection<SenderBean> collection = retransmitterBeanMgr.find(internalSequenceId);
    Iterator<SenderBean> iterator = collection.iterator();
    List<MessageContext> msgsToReallocate = null;
    if(reallocateIfPossible){
      msgsToReallocate = new LinkedList<MessageContext>();
    }
    Range[] ranges = rmsBean.getClientCompletedMessages().getRanges();
    long lastAckedMsg = -1;
   
    if(ranges.length==1){
      //the sequence is a single contiguous acked range
      lastAckedMsg = ranges[0].upperValue;
    } else{
      if(reallocateIfPossible){
        //cannot reallocate as there are gaps
        rmsBean.setReallocated(Sandesha2Constants.WSRM_COMMON.REALLOCATION_FAILED);
        storageManager.getRMSBeanMgr().update(rmsBean);
        reallocateIfPossible=false;
        if(LoggingControl.isAnyTracingEnabled() && log.isDebugEnabled())
          log.debug("cannot reallocate sequence as there are gaps");
      }
    }
   
    while (iterator.hasNext()) {
      SenderBean retransmitterBean = (SenderBean) iterator.next();
      if(retransmitterBean.getMessageType()!=Sandesha2Constants.MessageTypes.TERMINATE_SEQ || rmsBean.isTerminated()){
        //remove all but terminate sequence messages
        String messageStoreKey = retransmitterBean.getMessageContextRefKey();
        //if we have been asked to reallocate we need to send all unacked messages to a new sequence.
        //We must ensure that we rerieve these messages in the correct order
        if(reallocateIfPossible
          && retransmitterBean.getMessageType()==Sandesha2Constants.MessageTypes.APPLICATION
          && retransmitterBean.getMessageNumber()==lastAckedMsg+1){
         
          if(LoggingControl.isAnyTracingEnabled() && log.isDebugEnabled())
            log.debug("adding message for reallocate: " + retransmitterBean.getMessageNumber());
         
          //try to reallocate application msgs that are next in the outgoing list to
          msgsToReallocate.add(storageManager.retrieveMessageContext(messageStoreKey, storageManager.getContext()));
          retransmitterBeanMgr.delete(retransmitterBean.getMessageID());
          storageManager.removeMessageContext(messageStoreKey)
          lastAckedMsg++;
        }
        else if(reallocateIfPossible){
          //we are reallocating but this message does not fit the criteria. We should not delete it
          if(LoggingControl.isAnyTracingEnabled() && log.isDebugEnabled())
            log.debug("cannot reallocate: " + retransmitterBean.getMessageNumber());
          if(msgsToReallocate.size()==0){
            try{
              //however we might need this message if there are no messages to reallocate but we still
              //need a new sequence - we use a dummy message
              MessageContext dummy = SandeshaUtil.cloneMessageContext(
                  storageManager.retrieveMessageContext(messageStoreKey, storageManager.getContext()));
              dummy.getOptions().setProperty(SandeshaClientConstants.DUMMY_MESSAGE, Sandesha2Constants.VALUE_TRUE)
              msgsToReallocate.add(dummy);             
            }
            catch(Exception e){
              if(LoggingControl.isAnyTracingEnabled() && log.isDebugEnabled())
                log.debug("Exit: TerminateManager::cleanSendingSideData " + e);
              throw new SandeshaStorageException(e);
            }
          }
        }
        else{
          //we are not reallocating so just delete the messages
          retransmitterBeanMgr.delete(retransmitterBean.getMessageID());
          storageManager.removeMessageContext(messageStoreKey);           
        }
      }
    }
   
View Full Code Here

//    terminateRMMessage.setProperty(Sandesha2Constants.MessageContextProperties.SEQUENCE_PROPERTY_KEY, sequencePropertyKey);
   
    // / addTerminateSeqTransaction.commit();
      SandeshaUtil.executeAndStore(terminateRMMessage, key, storageManager);
   
    SenderBeanMgr retramsmitterMgr = storageManager.getSenderBeanMgr();
   
   
    retramsmitterMgr.insert(terminateBean);

    if(LoggingControl.isAnyTracingEnabled() && log.isDebugEnabled())
      log.debug("Exit: TerminateManager::addTerminateSequenceMessage");
  }
View Full Code Here

      String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.relatesToNotAvailable);
      log.error(message);
      throw new SandeshaException(message);
    }

    SenderBeanMgr retransmitterMgr = storageManager.getSenderBeanMgr();
    RMSBeanMgr rmsBeanMgr = storageManager.getRMSBeanMgr();

    RMSBean rmsBean = rmsBeanMgr.retrieve(createSeqMsgId);
    if (rmsBean == null) {
      String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.createSeqEntryNotFound);
      log.debug(message);
      throw new SandeshaException(message);
    }
   
    //Need to see if the seqID is a dupe of one that already exists
    //If it is we can't accept the CSR, so will do nothing so that a new CreateSeq msg is sent
    RMSBean finderBean = new RMSBean ();
    finderBean.setSequenceID(newOutSequenceId);
    RMSBean rmsBeanWithDuplicateSeqID = storageManager.getRMSBeanMgr().findUnique(finderBean);
    if(rmsBeanWithDuplicateSeqID != null){
      if (log.isDebugEnabled())
        log.debug("Duplicate SeqID: " + newOutSequenceId + " so we can't accept the CSR, will terminate this seq and reallocate to a new seq");
      return false;
    }

    // Check that the create sequence response message proves possession of the correct token
    MessageContext msgCtx = createSeqResponseRMMsgCtx.getMessageContext();
    SandeshaUtil.assertProofOfPossession(rmsBean, msgCtx, msgCtx.getEnvelope().getBody());

    String internalSequenceId = rmsBean.getInternalSequenceID();
    if (internalSequenceId == null || "".equals(internalSequenceId)) {
      String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.tempSeqIdNotSet);
      log.debug(message);
      throw new SandeshaException(message);
    }
    createSeqResponseRMMsgCtx.setProperty(Sandesha2Constants.MessageContextProperties.INTERNAL_SEQUENCE_ID,internalSequenceId);
   
    // Check to see if we have already received a sequence id. If we have then this response is redundant,
    // and we can forget about it.
    // TODO: Should we terminate or close the extra sequence? We can only do that if the new sequence
    // id is different from the one we got back the first time. For now it should be enough to just
    // ignore it, and let it time out.
    if(rmsBean.getSequenceID() != null) {
      if(log.isDebugEnabled())
        log.debug("Exit: CreateSeqResponseMsgProcessor::processInMessage, sequence id is already set. " +
            "Existing id:" + rmsBean.getSequenceID() + ", new id:" + newOutSequenceId);
      return false;
    }
     
    // Store the new sequence id
    rmsBean.setSequenceID(newOutSequenceId);

    // We should poll for any reply-to that uses the anonymous URI, when MakeConnection
    // is enabled.
    if (Sandesha2Constants.SPEC_VERSIONS.v1_1.equals(createSeqResponseRMMsgCtx.getRMSpecVersion())) {
      SandeshaPolicyBean policy = SandeshaUtil.getPropertyBean(configCtx.getAxisConfiguration());
      if(policy.isEnableMakeConnection()) {
        EndpointReference reference = rmsBean.getAcksToEndpointReference();
        if(reference == null || reference.hasAnonymousAddress()) {
          rmsBean.setPollingMode(true);
        }
      }
    }
     
    rmsBean.setLastActivatedTime(System.currentTimeMillis());
   
    if(!rmsBeanMgr.update(rmsBean)){     
      //Im not setting the createSeqBean sender bean to resend true as the reallocation of msgs will do this
      try{
        TerminateManager.terminateSendingSide(rmsBean, storageManager, true, transaction);
      } catch(Exception e){
        if (log.isDebugEnabled())
          log.debug(e);         
      }
    } else {
      // processing for accept (offer has been sent)
      Accept accept = createSeqResponsePart.getAccept();
      if (accept != null) {

        // TODO this should be detected in the Fault manager.
        if (rmsBean.getOfferedSequence() == null) {
          String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.accptButNoSequenceOffered);
          log.debug(message);
          throw new SandeshaException(message);
        }

        RMDBean rMDBean = new RMDBean();
       
        EndpointReference acksToEPR = accept.getAcksTo().getEPR();
        rMDBean.setAcksToEndpointReference(acksToEPR);
        rMDBean.setSequenceID(rmsBean.getOfferedSequence());
        rMDBean.setNextMsgNoToProcess(1);
        rMDBean.setOutboundInternalSequence(rmsBean.getInternalSequenceID());

        rMDBean.setServiceName(createSeqResponseRMMsgCtx.getMessageContext().getAxisService().getName());
       
        //Storing the referenceMessage of the sending side sequence as the reference message
        //of the receiving side as well.
        //This can be used when creating new outgoing messages.
       
        String referenceMsgStoreKey = rmsBean.getReferenceMessageStoreKey();
        MessageContext referenceMsg = storageManager.retrieveMessageContext(referenceMsgStoreKey, configCtx);
       
        String newMessageStoreKey = SandeshaUtil.getUUID();
        storageManager.storeMessageContext(newMessageStoreKey,referenceMsg);
       
        rMDBean.setReferenceMessageKey(newMessageStoreKey);

        // If this is an offered sequence that needs polling then we need to setup the
        // rmdBean for polling too, so that it still gets serviced after the outbound
        // sequence terminates.
        if (Sandesha2Constants.SPEC_VERSIONS.v1_1.equals(createSeqResponseRMMsgCtx.getRMSpecVersion())) {
          if(rmsBean.isPollingMode()) {
            rMDBean.setPollingMode(true);
            rMDBean.setReplyToEndpointReference(rmsBean.getReplyToEndpointReference());
          }
        }
       
        String rmSpecVersion = createSeqResponseRMMsgCtx.getRMSpecVersion();
        rMDBean.setRMVersion(rmSpecVersion);
       
        EndpointReference toEPR = createSeqResponseRMMsgCtx.getTo();
        if (toEPR==null) {
          //Most probably this is a sync response message, using the replyTo of the request message
          OperationContext operationContext = createSeqResponseRMMsgCtx.getMessageContext().getOperationContext();
          if (operationContext!=null) {
            MessageContext createSequnceMessage = operationContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
            if (createSequnceMessage!=null)
              toEPR = createSequnceMessage.getReplyTo();
          }
        }
       
        if (toEPR!=null)
          rMDBean.setToAddress(toEPR.getAddress());
       
        rMDBean.setServerCompletedMessages(new RangeString());
        RMDBeanMgr rmdBeanMgr = storageManager.getRMDBeanMgr();

        // Store the security token for the offered sequence
        rMDBean.setSecurityTokenData(rmsBean.getSecurityTokenData());
       
        rMDBean.setLastActivatedTime(System.currentTimeMillis());
       
        rmdBeanMgr.insert(rMDBean);
        SandeshaUtil.startWorkersForSequence(configCtx, rMDBean);
      }
     
      // Get the CreateSeqBean based on the message id to take a lock on the bean
        SenderBean createSeqBean = retransmitterMgr.retrieve(createSeqMsgId);
       
      // deleting the create sequence sender bean entry.
      retransmitterMgr.delete(createSeqBean.getMessageID());
       
      // Remove the create sequence message
      storageManager.removeMessageContext(rmsBean.getCreateSequenceMsgStoreKey());
      SandeshaUtil.startWorkersForSequence(configCtx, rmsBean);
 
      // Locate and update all of the messages for this sequence, now that we know
      // the sequence id.
      SenderBean target = new SenderBean();
      target.setInternalSequenceID(internalSequenceId);
      target.setSend(false);
     
      Iterator<SenderBean> iterator = retransmitterMgr.find(target).iterator();
      while (iterator.hasNext()) {
        SenderBean tempBean = (SenderBean) iterator.next();
 
        // asking to send the application msssage
        tempBean.setSend(true);
        tempBean.setSequenceID(newOutSequenceId);
        retransmitterMgr.update(tempBean);
      }
 
      // TODO - does this do anything?
      createSeqResponseRMMsgCtx.pause();
    }
View Full Code Here

TOP

Related Classes of org.apache.sandesha2.storage.beanmanagers.SenderBeanMgr

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.