Package org.apache.sandesha2.storage.beans

Examples of org.apache.sandesha2.storage.beans.SenderBean


    }
   
    // From here on, we must be dealing with a real address. Piggyback all sequences that have an
    // acksTo that matches the To address, and that have an ackMessage queued up for sending.
    Set acked = new HashSet();
    SenderBean findBean = new SenderBean();
    findBean.setMessageType(Sandesha2Constants.MessageTypes.ACK);
    findBean.setSend(true);
    findBean.setToAddress(target.getAddress());

    Collection collection = retransmitterBeanMgr.find(findBean);
   
    if (transaction != null && transaction.isActive())
      transaction.commit();
   
    transaction = storageManager.getTransaction();
   
    Iterator it = collection.iterator();
    while (it.hasNext()) {
      SenderBean ackBean = (SenderBean) it.next();

      // Piggybacking will happen only if the end of ack interval (timeToSend) is not reached.
      long timeNow = System.currentTimeMillis();
      if (ackBean.getTimeToSend() > timeNow) {
        // Delete the beans that would have sent the ack
        retransmitterBeanMgr.delete(ackBean.getMessageID());
        storageManager.removeMessageContext(ackBean.getMessageContextRefKey());

        String sequenceId = ackBean.getSequenceID();
        if (log.isDebugEnabled()) log.debug("Piggybacking ack for sequence: " + sequenceId);

        RMDBean rmdBean = SandeshaUtil.getRMDBeanFromSequenceId(storageManager, sequenceId);
        if(rmdBean != null && !rmdBean.isTerminated()) {
          RMMsgCreator.addAckMessage(rmMessageContext, sequenceId, rmdBean);
View Full Code Here


    SenderBeanMgr retransmitterBeanMgr = storageManager.getSenderBeanMgr();

    String key = SandeshaUtil.getUUID();

    SenderBean ackBean = new SenderBean();
    ackBean.setMessageContextRefKey(key);
    ackBean.setMessageID(ackMsgContext.getMessageID());
    ackBean.setReSend(false);
    ackBean.setSequenceID(sequenceId);
    EndpointReference to = ackMsgContext.getTo();
    if (to!=null)
      ackBean.setToAddress(to.getAddress());

    ackBean.setSend(true);
    ackMsgContext.setProperty(Sandesha2Constants.QUALIFIED_FOR_SENDING, Sandesha2Constants.VALUE_FALSE);

    ackBean.setMessageType(Sandesha2Constants.MessageTypes.ACK);

    // removing old acks.
    SenderBean findBean = new SenderBean();
    findBean.setMessageType(Sandesha2Constants.MessageTypes.ACK);
    findBean.setSend(true);
    findBean.setReSend(false);
    findBean.setSequenceID(sequenceId);
    Collection coll = retransmitterBeanMgr.find(findBean);
    Iterator it = coll.iterator();

    while(it.hasNext()) {
      SenderBean oldAckBean = (SenderBean) it.next();
      if(oldAckBean.getTimeToSend() < timeToSend)
        timeToSend = oldAckBean.getTimeToSend();

      // removing the retransmitted entry for the oldAck
      retransmitterBeanMgr.delete(oldAckBean.getMessageID());

      // removing the message store entry for the old ack
      storageManager.removeMessageContext(oldAckBean.getMessageContextRefKey());
    }

    ackBean.setTimeToSend(timeToSend);

    ackMsgContext.setProperty(Sandesha2Constants.QUALIFIED_FOR_SENDING, Sandesha2Constants.VALUE_FALSE);
View Full Code Here

        SenderBeanMgr senderManager = storageManager.getSenderBeanMgr();
           
        Transaction transaction = storageManager.getTransaction();
       
        // 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 beans = senderManager.find(senderBean);
       
        //only the ackRequested bean will be present.
View Full Code Here

      rmsBean.setSecurityTokenData(secManager.getTokenRecoveryData(token));
    }
   
    storageManager.getRMSBeanMgr().insert(rmsBean);

    SenderBean createSeqEntry = new SenderBean();
    createSeqEntry.setMessageContextRefKey(createSequenceMessageStoreKey);
    createSeqEntry.setTimeToSend(System.currentTimeMillis());
    createSeqEntry.setMessageID(createSeqRMMessage.getMessageId());
    createSeqEntry.setInternalSequenceID(rmsBean.getInternalSequenceID());
    // this will be set to true in the sender
    createSeqEntry.setSend(true);
    // Indicate that this message is a create sequence
    createSeqEntry.setMessageType(Sandesha2Constants.MessageTypes.CREATE_SEQ);
    EndpointReference to = createSeqRMMessage.getTo();
    if (to!=null)
      createSeqEntry.setToAddress(to.getAddress());
    // If this message is targetted at an anonymous address then we must not have a transport
    // ready for it, as the create sequence is not a reply.
    if(to == null || to.hasAnonymousAddress())
      createSeqEntry.setTransportAvailable(false);

    createSeqMsg.setProperty(Sandesha2Constants.QUALIFIED_FOR_SENDING, Sandesha2Constants.VALUE_FALSE);
   
    SandeshaUtil.executeAndStore(createSeqRMMessage, createSequenceMessageStoreKey);
View Full Code Here

         (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;
      }
     
      boolean continueSending = updateMessage(rmMsgCtx,senderBean,storageManager);

      if (!continueSending) {
        if (log.isDebugEnabled())
          log.debug("Exit: SenderWorker::run, !continueSending");
        return;
      }

      int messageType = senderBean.getMessageType();
     
      if (isAckPiggybackableMsgType(messageType)) {
        // Piggyback ack messages based on the 'To' address of the message
        AcknowledgementManager.piggybackAcksIfPresent(rmMsgCtx, storageManager);
      }

      // sending the message
      boolean successfullySent = false;

      // Although not actually sent yet, update the send count to indicate an attempt
      if (senderBean.isReSend()) {
        SenderBean bean2 = senderBeanMgr.retrieve(senderBean.getMessageID());
        if (bean2 != null) {
          bean2.setSentCount(senderBean.getSentCount());
          senderBeanMgr.update(bean2);
        }
      }
     
      // have to commit the transaction before sending. This may
      // get changed when WS-AT is available.
      if(transaction != null) {
        transaction.commit();
        transaction = null;
      }

      msgCtx.getOptions().setTimeOutInMilliSeconds(1000000);
     
      try {
        AxisEngine engine = new AxisEngine (msgCtx.getConfigurationContext());
        InvocationResponse response = InvocationResponse.CONTINUE;
       
        SandeshaPolicyBean policy = SandeshaUtil.getPropertyBean(msgCtx.getAxisOperation());
        if(policy.isUseMessageSerialization()) {
          if(msgCtx.isPaused()) {
            if (log.isDebugEnabled())
              log.debug("Resuming a send for message : " + msgCtx.getEnvelope().getHeader());
            msgCtx.setPaused(false);
            msgCtx.setProperty(MessageContext.TRANSPORT_NON_BLOCKING, Boolean.FALSE);
            response = engine.resumeSend(msgCtx);
          } else {
            if (log.isDebugEnabled())
              log.debug("Sending a message : " + msgCtx.getEnvelope().getHeader());
            msgCtx.setProperty(MessageContext.TRANSPORT_NON_BLOCKING, Boolean.FALSE);
            engine.send(msgCtx)// TODO check if this should return an invocation response
          }
        } else {
          // had to fully build the SOAP envelope to support
          // retransmissions.
          // Otherwise a 'parserAlreadyAccessed' exception could
          // get thrown in retransmissions.
          // But this has a performance reduction.
          msgCtx.getEnvelope().build();
 
          ArrayList retransmittablePhases = (ArrayList) msgCtx.getProperty(Sandesha2Constants.RETRANSMITTABLE_PHASES);
          if (retransmittablePhases!=null) {
            msgCtx.setExecutionChain(retransmittablePhases);
          } else {
            ArrayList emptyExecutionChain = new ArrayList ();
            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());
          response = engine.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 (Exception e) {
        String message = SandeshaMessageHelper.getMessage(
            SandeshaMessageKeys.sendMsgError, e.toString());
       
        if (log.isErrorEnabled())
          log.error(message, e);
        // Store the Exception as a sequence property to enable the client to lookup the last
        // exception time and timestamp.
       
        try
        {
          // Create a new Transaction
          transaction = storageManager.getTransaction();
         
          // Get the internal sequence id from the context
          String internalSequenceId = (String)rmMsgCtx.getProperty(Sandesha2Constants.MessageContextProperties.INTERNAL_SEQUENCE_ID);
         
          RMSBean bean = SandeshaUtil.getRMSBeanFromInternalSequenceId(storageManager, internalSequenceId);
         
          if (bean != null) {           
            bean.setLastSendError(e);
            bean.setLastSendErrorTimestamp(System.currentTimeMillis());
          }
         
          // Update the RMSBean
          storageManager.getRMSBeanMgr().update(bean);
         
          // Commit the properties
          if(transaction != null) {
            transaction.commit();
            transaction = null;
          }
        }
        catch (Exception e1)
        {
          if (log.isErrorEnabled())
            log.error(e1);
        } finally {
          if (transaction != null) {
            transaction.rollback();
            transaction = null;
          }
        }
       
      }
      // 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);
        }
      }

      // Commit the transaction to release the SenderBean
View Full Code Here

    // 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.
View Full Code Here

      if (log.isDebugEnabled())
        log.debug("Exit: FaultManager::processCreateSequenceRefusedFault Allowing another CreateSequence attempt");
      return;
    }
*/
    SenderBean createSequenceSenderBean = retransmitterMgr.retrieve(createSeqMsgId);
    if (createSequenceSenderBean == null)
      throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.createSeqEntryNotFound));

    // deleting the create sequence entry.
    retransmitterMgr.delete(createSeqMsgId);
View Full Code Here

  static void notifyClientsOfFault(String internalSequenceId,
      StorageManager storageManager, ConfigurationContext configCtx, AxisFault fault) throws SandeshaStorageException {
    // Locate and update all of the messages for this sequence, now that we know
    // the sequence id.
    SenderBean target = new SenderBean();
    target.setInternalSequenceID(internalSequenceId);
   
    Iterator iterator = storageManager.getSenderBeanMgr().find(target).iterator();
    while (iterator.hasNext()) {
      SenderBean tempBean = (SenderBean) iterator.next();

      String messageStoreKey = tempBean.getMessageContextRefKey();
     
      // Retrieve the message context.
      MessageContext context = storageManager.retrieveMessageContext(messageStoreKey, configCtx);
     
      AxisOperation axisOperation = context.getAxisOperation();
View Full Code Here

      // missed earlier acks. We also have special processing for sync 2-way with RM 1.0
      if((replyTo==null || replyTo.hasAnonymousAddress()) &&
         (specVersion!=null && specVersion.equals(Sandesha2Constants.SPEC_VERSIONS.v1_0))) {

        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().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) {
          if(log.isDebugEnabled()) log.debug("Found matching reply for replayed message");
           MakeConnectionProcessor.replyToPoll(rmMsgCtx, replyMessageBean, storageManager, false, null, transaction);
          result = InvocationResponse.ABORT;
          if (log.isDebugEnabled())
            log.debug("Exit: SequenceProcessor::processReliableMessage, replayed message: " + result);
          return result;
        }
      }
     
      EndpointReference acksTo = new EndpointReference (bean.getAcksToEPR());
     
      // Send an Ack if needed.
      //We are not sending acks for duplicate messages in the RM 1.0 anon InOut case.
      //If a standalone ack get sent before the actualy message (I.e. before the original msg get
      //replied), the client may take this as a InOnly message and may avoid looking for the application
      //response.
      if (!(Sandesha2Constants.SPEC_VERSIONS.v1_0.equals(rmMsgCtx.getRMSpecVersion()) &&
          rmMsgCtx.getReplyTo().hasAnonymousAddress())) {
        sendAckIfNeeded(bean, sequenceId, rmMsgCtx, storageManager, true, acksTo.hasAnonymousAddress())
      }
     
      result = InvocationResponse.ABORT;
      if (log.isDebugEnabled())
        log.debug("Exit: SequenceProcessor::processReliableMessage, dropping duplicate: " + result);
      return result;
    }
   
    // If the message is a reply to an outbound message then we can update the RMSBean that
    // matches.
    EndpointReference toEPR = msgCtx.getTo();
    if(toEPR == null || toEPR.hasAnonymousAddress()) {
      RMSBean outBean = null;

      // Look for the correct outbound sequence by checking the anon uuid (if there is one)
      String toAddress = (toEPR == null) ? null : toEPR.getAddress();
      if(SandeshaUtil.isWSRMAnonymous(toAddress)) {
        RMSBean finderBean = new RMSBean();
        finderBean.setAnonymousUUID(toAddress);
        outBean = storageManager.getRMSBeanMgr().findUnique(finderBean);
      }
     
      // Fall back to the sequence that may have been offered at sequence creation time
      if(outBean == null) {
        String outboundSequence = bean.getOutboundInternalSequence();
        if(outboundSequence != null) {
          outBean = SandeshaUtil.getRMSBeanFromInternalSequenceId(storageManager, outboundSequence);
        }
      }
     
      // Update the reply count
      if(outBean != null && outBean.getExpectedReplies() > 0 ) {
        outBean.setExpectedReplies(outBean.getExpectedReplies() - 1);
        RMSBeanMgr outMgr = storageManager.getRMSBeanMgr();
        outMgr.update(outBean);
      }
    }
   
    // Set the last activated time
    bean.setLastActivatedTime(System.currentTimeMillis());
   
    // Update the RMD bean
    mgr.update(bean);
   
    // If we are doing sync 2-way over WSRM 1.0, then we may just have received one of
    // the reply messages that we were looking for. If so we can remove the matching sender bean.
    int mep = msgCtx.getAxisOperation().getAxisSpecifMEPConstant();
    if(specVersion!=null && specVersion.equals(Sandesha2Constants.SPEC_VERSIONS.v1_0) &&
        mep == WSDLConstants.MEP_CONSTANT_OUT_IN) {
      RelatesTo relatesTo = msgCtx.getRelatesTo();
      if(relatesTo != null) {
        String messageId = relatesTo.getValue();
        SenderBean matcher = new SenderBean();
        matcher.setMessageID(messageId);
        SenderBean sender = storageManager.getSenderBeanMgr().findUnique(matcher);
        if(sender != null) {
          if(log.isDebugEnabled()) log.debug("Deleting sender for sync-2-way message");
         
          storageManager.removeMessageContext(sender.getMessageContextRefKey());
         
          //this causes the request to be deleted even without an ack.
          storageManager.getSenderBeanMgr().delete(messageId);
         
          // Try and terminate the corresponding outbound sequence
          RMSBean rmsBean = SandeshaUtil.getRMSBeanFromSequenceId(storageManager, sender.getSequenceID());
          TerminateManager.checkAndTerminate(rmMsgCtx.getConfigurationContext(), storageManager, rmsBean);
        }
      }
    }
View Full Code Here

      makeConnectionRMMessage.setProperty(MessageContext.TRANSPORT_IN,null);
      //storing the MakeConnection message.
      String makeConnectionMsgStoreKey = SandeshaUtil.getUUID();
     
      //add an entry for the MakeConnection message to the sender (with ,send=true, resend=false)
      SenderBean makeConnectionSenderBean = new SenderBean ();
      makeConnectionSenderBean.setInternalSequenceID(internalSeqId);
      makeConnectionSenderBean.setMessageContextRefKey(makeConnectionMsgStoreKey);
      makeConnectionSenderBean.setMessageID(makeConnectionRMMessage.getMessageId());
      makeConnectionSenderBean.setMessageType(Sandesha2Constants.MessageTypes.MAKE_CONNECTION_MSG);
      makeConnectionSenderBean.setReSend(false);
      makeConnectionSenderBean.setSend(true);
      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);
View Full Code Here

TOP

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

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.