Package org.apache.sandesha

Examples of org.apache.sandesha.RMMessageContext


    }

    //Only for client.
    public RMMessageContext checkForResponseMessage(String requestId, String seqId) {
        SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
        RMMessageContext msg = sq.checkForResponseMessage(requestId, seqId);
        return msg;
    }
View Full Code Here


    public RMMessageContext getNextMessageToProcess(Object seq) {

        if (seq == null)
            return null;

        RMMessageContext nextMsg = accessor.getNextMsgContextToProcess(seq);
        return nextMsg;
    }
View Full Code Here

    /**
     * This is used to get a random message from the out queue Basically server
     * sender will use this.
     */
    public synchronized RMMessageContext getNextMessageToSend() {
        RMMessageContext msg;
        msg = accessor.getNextPriorityMessageContextToSend();
        if (msg == null)
            msg = accessor.getNextOutgoingMsgContextToSend();
        if (msg == null)
            msg = accessor.getNextLowPriorityMessageContextToSend();

        if (msg != null && !msg.isLocked()) {
            msg.setLocked(true);
            return msg;
        } else {
            return null;
        }

View Full Code Here

            rpcProvider.invoke(msgContext);
        } else {
            IStorageManager storageManager = SandeshaContext.init(client);
            storageManager.init();

            RMMessageContext rmMessageContext = new RMMessageContext();
            rmMessageContext.setMsgContext(msgContext);
            try {
                MessageValidator.validate(rmMessageContext, client);
            } catch (AxisFault af) {
                FaultProcessor faultProcessor = new FaultProcessor(storageManager, af);
                if (!faultProcessor.sendFault(rmMessageContext)) {
                    msgContext.setPastPivot(true);
                    msgContext.setResponseMessage(null);
                    return;
                }
                return;
            }
            RMHeaders rmHeaders = rmMessageContext.getRMHeaders();
            AddressingHeaders addrHeaders = rmMessageContext.getAddressingHeaders();

            if (null != rmHeaders.getSequence()) {
                rmMessageContext.setSequenceID(rmHeaders.getSequence().getIdentifier().toString());
                if (null != rmHeaders.getSequence().getLastMessage()) {
                    rmMessageContext.setLastMessage(true);
                }
            }

            if (addrHeaders.getMessageID() == null) {
                rmMessageContext.setMessageID((new Long(System.currentTimeMillis())).toString());
            } else {
                rmMessageContext.setMessageID(addrHeaders.getMessageID().toString());
            }

            IRMMessageProcessor rmMessageProcessor = RMMessageProcessorIdentifier.getMessageProcessor(rmMessageContext, storageManager);

            if (callback != null) {
View Full Code Here

            long startTime = System.currentTimeMillis();
            boolean hasMessages = true;
            //Take a messge from the storage and check whether we can send it.
            do {

                RMMessageContext rmMessageContext = storageManager.getNextMessageToSend();
                if (rmMessageContext == null) {
                    hasMessages = false;
                } else {
                    long inactivityTimeout = PolicyLoader.getInstance().getInactivityTimeout();
                    long retransmissionInterval = PolicyLoader.getInstance()
                            .getBaseRetransmissionInterval();

                    if (rmMessageContext.getFristProcessedTime() == 0)
                        rmMessageContext.setFristProcessedTime(System.currentTimeMillis());

                    if ((System.currentTimeMillis() - rmMessageContext.getFristProcessedTime()) >
                            inactivityTimeout) {
                        log.error("Inactivity Time Out Reached for the message with <wsa:MessageID> " +
                                rmMessageContext.getMessageID());
                        //Need to clear the storage only for this sequece.
                        // storageManager.clearStorage();

                    } else if (rmMessageContext.getRetransmissionTime() <
                            (System.currentTimeMillis() - rmMessageContext.getLastPrecessedTime())) {
                        try {

                            rmMessageContext.setLastPrecessedTime(System.currentTimeMillis());

                            if (PolicyLoader.getInstance().getExponentialBackoff() != null) {
                                long newRtTime = ((long) Math.pow(retransmissionInterval / 1000,
                                        rmMessageContext.getReTransmissionCount())) * 1000;
                                rmMessageContext.setRetransmissionTime(newRtTime);

                            } else {
                                //Let's do Binary Back Off
                                long rtTime = rmMessageContext.getRetransmissionTime();
                                rmMessageContext.setRetransmissionTime(2 * rtTime);

                            }
                            sendMessage(rmMessageContext);
                            rmMessageContext.setReTransmissionCount(rmMessageContext.getReTransmissionCount() + 1);

                            rmMessageContext.setLocked(false);

                        } catch (AxisFault e) {
                            rmMessageContext.setLocked(false);
                            log.error(e);
                        } catch (SOAPException e) {
                            rmMessageContext.setLocked(false);
                            log.error(e);
                        } catch (Exception e) {
                            rmMessageContext.setLocked(false);
                            log.error(e);
                        }
                    }
                    rmMessageContext.setLocked(false);

                }
            } while (hasMessages);

            long timeGap = System.currentTimeMillis() - startTime;
View Full Code Here

    public void executeInvoke() throws Exception {

        Object seq = getStorageManager().getNextSeqToProcess();
        if (seq != null) {
            synchronized (seq) {
                RMMessageContext rmMessageContext = getStorageManager().getNextMessageToProcess(seq);
                doWork(rmMessageContext);
            }
        }
    }
View Full Code Here

                rmMessageContext.getAddressingHeaders().setAction(oldAction + Constants.RESPONSE);
                if (rmMessageContext.isLastMessage()) {
                    //Insert Terminate Sequnce.
                    if (addrHeaders.getReplyTo() != null) {
                        String replyTo = addrHeaders.getReplyTo().getAddress().toString();
                        RMMessageContext terminateMsg = RMMessageCreator.createTerminateSeqMsg(rmMessageContext, Constants.SERVER);
                        terminateMsg.setOutGoingAddress(replyTo);
                        getStorageManager().insertTerminateSeqMessage(terminateMsg);
                    } else {
                        RMInvokerWork.log.error(Constants.ErrorMessages.CANNOT_SEND_THE_TERMINATE_SEQ);
                    }
                }
                //Store the message in the response queue. If there is an application
                // response then that response is always sent using a new HTTP connection
                // and the <replyTo> header is used in this case. This is done by the
                // RMSender.
                rmMessageContext.setMessageType(Constants.MSG_TYPE_SERVICE_RESPONSE);

                boolean hasResponseSeq = getStorageManager().isResponseSequenceExist(rmMessageContext.getSequenceID());
                boolean firstMsgOfResponseSeq = false;
                if (!(hasResponseSeq && rmMessageContext.getRMHeaders().getSequence()
                        .getMessageNumber().getMessageNumber() == 1)) {
                    firstMsgOfResponseSeq = !hasResponseSeq;
                }

                rmMessageContext.setMsgNumber(getStorageManager().getNextMessageNumber(rmMessageContext.getSequenceID()));
                getStorageManager().insertOutgoingMessage(rmMessageContext);


                if (firstMsgOfResponseSeq) {
                    String msgIdStr = Constants.UUID + RMInvokerWork.uuidGen.nextUUID();

                    RMMessageContext csRMMsgCtx = RMMessageCreator.createCreateSeqMsg(rmMessageContext, Constants.SERVER, msgIdStr, null);
                    csRMMsgCtx.setOutGoingAddress(rmMessageContext.getAddressingHeaders()
                            .getReplyTo().getAddress().toString());

                    csRMMsgCtx.addToMsgIdList(msgIdStr);
                    csRMMsgCtx.setMessageID(msgIdStr);

                    getStorageManager().setTemporaryOutSequence(csRMMsgCtx.getSequenceID(),
                            msgIdStr);
                    getStorageManager().addCreateSequenceRequest(csRMMsgCtx);
                }
            }
        }
View Full Code Here

    public void invoke(MessageContext msgContext) throws AxisFault {

        storageManager = new ClientStorageManager();

        try {
            RMMessageContext reqMsgCtx = null;
            String tempSeqID = null;

            reqMsgCtx = getRMMessageContext(msgContext);

            tempSeqID = reqMsgCtx.getSequenceID();

            reqMsgCtx = processRequestMessage(reqMsgCtx, reqMsgCtx.getSync());

            if (reqMsgCtx.isHasResponse()) {
                RMMessageContext responseMessageContext = null;
                long startingTime = System.currentTimeMillis();
                long inactivityTimeOut = PolicyLoader.getInstance().getInactivityTimeout();

                while (responseMessageContext == null) {
                    synchronized (lock) {
                        responseMessageContext =
                                checkTheQueueForResponse(tempSeqID, reqMsgCtx.getMessageID());
                        if ((System.currentTimeMillis() - startingTime) >= inactivityTimeOut) {
                            reqMsgCtx.getCtx().stopClientByForce();
                        }
                        Thread.sleep(Constants.CLIENT_RESPONSE_CHECKING_INTERVAL);
                    }
                }

                //setting RMReport;
                if (responseMessageContext != null) {
                    String oldSeqId = reqMsgCtx.getOldSequenceID();
                    if (oldSeqId != null) {
                        Call call = (Call) reqMsgCtx.getCtx().getCallMap().get(reqMsgCtx.getOldSequenceID());

                        if (call != null) {
                            RMReport report = (RMReport) call.getProperty(Constants.ClientProperties.REPORT);
                            report.incrementReturnedMsgCount();
                        }
                    }
                }

                //We need these steps to filter all addressing and rm related headers.
                Message resMsg = responseMessageContext.getMsgContext().getRequestMessage();
                RMHeaders.removeHeaders(resMsg.getSOAPEnvelope());
                AddressingHeaders addHeaders = new AddressingHeaders(resMsg.getSOAPEnvelope(),
                        null, true, false, false, null);

                msgContext.setResponseMessage(resMsg);
View Full Code Here

                    offerID = Constants.UUID + uuidGen.nextUUID();
                    storageManager.addRequestedSequence(offerID);
                    storageManager.addOffer(msgID, offerID);
                }

                RMMessageContext createSeqRMMsgContext = RMMessageCreator.createCreateSeqMsg(reqRMMsgContext, Constants.CLIENT, msgID, offerID);
                storageManager.addOutgoingSequence(reqRMMsgContext.getSequenceID());
                storageManager.setTemporaryOutSequence(reqRMMsgContext.getSequenceID(),
                        createSeqRMMsgContext.getMessageID());

                createSeqRMMsgContext.setSync(sync);
                storageManager.addCreateSequenceRequest(createSeqRMMsgContext);
                processMessage(reqRMMsgContext);

            } else {
                processMessage(reqRMMsgContext);
View Full Code Here

    private RMMessageContext processMessage(RMMessageContext reqRMMsgContext)
            throws Exception {
        if (reqRMMsgContext.isLastMessage()) {
            storageManager.insertTerminateSeqMessage(RMMessageCreator.createTerminateSeqMsg(reqRMMsgContext, Constants.CLIENT));
        }
        RMMessageContext serviceRequestMsg = RMMessageCreator.createServiceRequestMessage(reqRMMsgContext);
        storageManager.insertOutgoingMessage(serviceRequestMsg);
        return reqRMMsgContext;
    }
View Full Code Here

TOP

Related Classes of org.apache.sandesha.RMMessageContext

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.