Package org.apache.synapse.message.store

Examples of org.apache.synapse.message.store.MessageStore


        return executor;
    }

    public static MessageStore defineMessageStore(SynapseConfiguration config ,
                                                  OMElement elem, Properties properties) {
        MessageStore messageStore = MessageStoreFactory.createMessageStore(elem, properties);
        config.addMessageStore(messageStore.getName(), messageStore);
        return messageStore;
    }
View Full Code Here


        JobDataMap jdm = jobExecutionContext.getMergedJobDataMap();

        /**
         * Get the Globle Objects from DataMap
         */
        MessageStore messageStore = (MessageStore) jdm.get(
                MessageProcessorConsents.MESSAGE_STORE);
        Map<String, Object> parameters = (Map<String, Object>) jdm.get(
                MessageProcessorConsents.PARAMETERS);
        BlockingMessageSender sender =
                (BlockingMessageSender) jdm.get(ScheduledMessageForwardingProcessor.BLOCKING_SENDER);

        ScheduledMessageForwardingProcessor processor =
                (ScheduledMessageForwardingProcessor) jdm.get(ScheduledMessageForwardingProcessor.PROCESSOR_INSTANCE);


        int maxDeliverAttempts = -1;
        String mdaParam = (String) parameters.get(MessageProcessorConsents.MAX_DELIVER_ATTEMPTS);


        if (mdaParam != null) {
            maxDeliverAttempts = Integer.parseInt(mdaParam);

            // Here we look for the edge case
            if(maxDeliverAttempts == 0) {
                processor.deactivate();
            }
        }

        // WE do not try to process if the processor is inactive or
        // there is no message store attached.
        if(!processor.isActive() || messageStore == null) {
            return;
        }

        boolean errorStop = false;
        while (!errorStop) {

            MessageContext messageContext = messageStore.peek();
            if (messageContext != null) {


                //If The Message not belongs to this server we ignore it.
                String serverName = (String)
                        messageContext.getProperty(SynapseConstants.Axis2Param.SYNAPSE_SERVER_NAME);

                if(serverName != null && messageContext instanceof Axis2MessageContext) {

                    AxisConfiguration configuration = ((Axis2MessageContext)messageContext).
                            getAxis2MessageContext().
                            getConfigurationContext().getAxisConfiguration();

                    String myServerName = getAxis2ParameterValue(configuration,
                            SynapseConstants.Axis2Param.SYNAPSE_SERVER_NAME);

                    if(!serverName.equals(myServerName)) {
                        return;
                    }

                }

                Set proSet = messageContext.getPropertyKeySet();

                if (proSet != null) {
                    if (proSet.contains(ForwardingProcessorConstants.BLOCKING_SENDER_ERROR)) {
                        proSet.remove(ForwardingProcessorConstants.BLOCKING_SENDER_ERROR);
                    }
                }

                String targetEp =
                        (String) messageContext.getProperty(ForwardingProcessorConstants.TARGET_ENDPOINT);

                if (targetEp != null) {
                    Endpoint ep = messageContext.getEndpoint(targetEp);

                    if (ep instanceof AddressEndpoint) {
                        AddressEndpoint addEp = (AddressEndpoint) ep;
                        String addressUrl = addEp.getDefinition().getAddress();

                        try {
                            MessageContext outCtx = sender.send(messageContext, addressUrl);

                            if (outCtx != null && "true".equals(outCtx.
                                    getProperty(ForwardingProcessorConstants.BLOCKING_SENDER_ERROR))) {
                                // This Means an Error has occurred

                                if (maxDeliverAttempts > 0) {
                                    processor.incrementSendAttemptCount();
                                }

                                if (parameters != null &&
                                        parameters.get(
                                                ForwardingProcessorConstants.FAULT_SEQUENCE) != null) {

                                    String seq = (String) parameters.get(
                                            ForwardingProcessorConstants.FAULT_SEQUENCE);
                                    Mediator mediator = outCtx.getSequence(seq);
                                    if (mediator != null) {
                                        mediator.mediate(outCtx);
                                    } else {
                                        log.warn("Can't Send the fault Message , Sequence " + seq +
                                                " Does not Exist");
                                    }

                                }

                                if (maxDeliverAttempts > 0) {
                                    if(processor.getSendAttemptCount() >= maxDeliverAttempts) {
                                        processor.deactivate();
                                    }
                                }
                                errorStop = true;
                                continue;

                            } else if(outCtx == null) {
                                // This Means we have invoked an out only operation
                                // remove the message and reset the count
                                messageStore.poll();
                                processor.resetSentAttemptCount();
                                continue;
                            }

                            // If there is a sequence defined to send success replies,
                            // we must send the message to it
                            if (parameters != null &&
                                    parameters.get(
                                            ForwardingProcessorConstants.REPLY_SEQUENCE) != null) {
                                if (outCtx != null) {
                                    String seq = (String) parameters.get(
                                            ForwardingProcessorConstants.REPLY_SEQUENCE);
                                    Mediator mediator = outCtx.getSequence(seq);
                                    if (mediator != null) {
                                        mediator.mediate(outCtx);
                                    } else {
                                        log.warn("Can't Send the Out Message , Sequence " + seq +
                                                " Does not Exist");
                                    }
                                }
                            }

                            // If no Exception Occurred We remove the Message
                            // and reset the delivery attempt count
                            processor.resetSentAttemptCount();
                            messageStore.poll();
                        } catch (Exception e) {

                            if (maxDeliverAttempts > 0) {
                                processor.incrementSendAttemptCount();
                                if (processor.getSendAttemptCount() >= maxDeliverAttempts) {
                                    processor.deactivate();
                                }
                            }
                            errorStop = true;
                            log.error("Error Forwarding Message ", e);
                            continue;
                        }
                    } else {
                        // Currently only Address Endpoint delivery is supported
                        log.warn("Address Endpoint Named " + targetEp + " not found.Hence removing " +
                                "the message form store");
                        messageStore.poll();
                    }


                } else {
                    //No Target Endpoint defined for the Message
                    //So we do not have a place to deliver.
                    //Here we log a warning and remove the message
                    //todo: we can improve this by implementing a target inferring mechanism

                    log.warn("Property " + ForwardingProcessorConstants.TARGET_ENDPOINT +
                            " not found in the message context , Hence removing the message ");
                    messageStore.poll();

                }

            } else {
                errorStop = true;
View Full Code Here

            Iterator messageStores = FileUtils.iterateFiles(messageStoresDir, extensions, false);
            while (messageStores.hasNext()) {
                File file = (File) messageStores.next();
                OMElement document = getOMElement(file);
                MessageStore messageStore = SynapseXMLConfigurationFactory.defineMessageStore(
                        synapseConfig, document, properties);
                if (messageStore != null) {
                    messageStore.setFileName(file.getName());
                    synapseConfig.getArtifactDeploymentStore().addArtifact(file.getAbsolutePath(),
                            messageStore.getName());
                }
            }
        }
    }
View Full Code Here

                "<syn:backoffMutiplier>2</syn:backoffMutiplier>" +
                "</syn:redelivery>" +
                "</syn:messageStore>";

        OMElement messageStoreElement = createOMElement(messageStoreConfiguration);
        MessageStore messageStore = MessageStoreFactory.createMessageStore(messageStoreElement,
                new Properties());
        OMElement serializedElement = MessageStoreSerializer.serializeMessageStore(null,
                messageStore);

        try {
View Full Code Here

            File[] messageStores = messageStoresDir.listFiles(filter);
            for (File file : messageStores) {
                try {
                    OMElement document = parseFile(file);
                    MessageStore messageStore = SynapseXMLConfigurationFactory.defineMessageStore(
                            synapseConfig, document, properties);
                    messageStore.setFileName(file.getName());
                    synapseConfig.getArtifactDeploymentStore().addArtifact(file.getAbsolutePath(),
                            messageStore.getName());
                } catch (FileNotFoundException ignored ) { }
            }
        }
    }
View Full Code Here

        return executor;
    }

    public static MessageStore defineMessageStore(SynapseConfiguration config ,
                                                  OMElement elem, Properties properties) {
        MessageStore messageStore = MessageStoreFactory.createMessageStore(elem, properties);
        config.addMessageStore(messageStore.getName(), messageStore);
        return messageStore;
    }
View Full Code Here

    @SuppressWarnings({"UnusedDeclaration"})
    public static MessageStore createMessageStore(OMElement elem, Properties properties) {

        OMAttribute clss = elem.getAttribute(CLASS_Q);
        MessageStore messageStore;
        if (clss != null) {
            try {
                Class cls = Class.forName(clss.getAttributeValue());
                messageStore = (MessageStore) cls.newInstance();
            } catch (Exception e) {
                handleException("Error while instantiating the message store", e);
                return null;
            }
        } else {
            messageStore = new InMemoryMessageStore();
        }

        OMAttribute nameAtt = elem.getAttribute(NAME_Q);
        if (nameAtt != null) {
            messageStore.setName(nameAtt.getAttributeValue());
        } else {
            handleException("Message Store name not specified");
        }

        OMAttribute sequenceAtt = elem.getAttribute(SEQUENCE_Q);
        if(sequenceAtt != null) {
            messageStore.setSequence(sequenceAtt.getAttributeValue());
        }

        OMElement redeliveryElem = elem.getFirstChildWithName(REDELIVERY_Q);

        if (redeliveryElem != null) {
            RedeliveryProcessor redeliveryProcessor = populateRedeliveryProcessor(redeliveryElem,
                    messageStore);
            messageStore.setRedeliveryProcessor(redeliveryProcessor);
        }

        OMElement descriptionElem = elem.getFirstChildWithName(DESCRIPTION_Q);
        if (descriptionElem != null) {
            messageStore.setDescription(descriptionElem.getText());
        }

        messageStore.setParameters(getParameters(elem));
        return messageStore;
    }
View Full Code Here

    private static Log log = LogFactory.getLog(SamplingJob.class);

    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        JobDataMap jdm = jobExecutionContext.getMergedJobDataMap();

        final MessageStore messageStore = (MessageStore) jdm.get(
                MessageProcessorConsents.MESSAGE_STORE);

        Map<String, Object> parameters = (Map<String, Object>) jdm.get(
                MessageProcessorConsents.PARAMETERS);
        SamplingProcessor processor = (SamplingProcessor)
                jdm.get(ScheduledMessageProcessor.PROCESSOR_INSTANCE);

        final Object concurrency = jdm.get(SamplingProcessor.CONCURRENCY);
        final String sequence = (String) parameters.get(SamplingProcessor.SEQUENCE);

        // if processor is not active we do not proceed with the processing
        if(!processor.isActive()) {
            return;
        }

        int conc = 1;
        if (concurrency instanceof Integer) {
            conc = (Integer) concurrency;
        }

        for (int i = 0; i < conc; i++) {
            //lock.lock();
            synchronized (messageStore) {
                final MessageContext messageContext = messageStore.peek();

                if (messageContext != null) {
                    messageStore.poll();
                    final ExecutorService executor = messageContext.getEnvironment().
                            getExecutorService();
                    executor.submit(new Runnable() {
                        public void run() {
                            try {
View Full Code Here

        JobDataMap jdm = jobExecutionContext.getMergedJobDataMap();

        /**
         * Get the Globle Objects from DataMap
         */
        MessageStore messageStore = (MessageStore) jdm.get(
                MessageProcessorConsents.MESSAGE_STORE);
        Map<String, Object> parameters = (Map<String, Object>) jdm.get(
                MessageProcessorConsents.PARAMETERS);
        BlockingMessageSender sender =
                (BlockingMessageSender) jdm.get(ScheduledMessageForwardingProcessor.BLOCKING_SENDER);

        ScheduledMessageForwardingProcessor processor =
                (ScheduledMessageForwardingProcessor) jdm.get(ScheduledMessageForwardingProcessor.PROCESSOR_INSTANCE);


        int maxDeliverAttempts = -1;
        String mdaParam = (String) parameters.get(MessageProcessorConsents.MAX_DELIVER_ATTEMPTS);


        if (mdaParam != null) {
            maxDeliverAttempts = Integer.parseInt(mdaParam);

            // Here we look for the edge case
            if(maxDeliverAttempts == 0) {
                processor.deactivate();
            }
        }

        // WE do not try to process if the processor is inactive or
        // there is no message store attached.
        if(!processor.isActive() || messageStore == null) {
            return;
        }

        boolean errorStop = false;
        while (!errorStop) {

            MessageContext messageContext = messageStore.peek();
            if (messageContext != null) {


                //If The Message not belongs to this server we ignore it.
                String serverName = (String)
                        messageContext.getProperty(SynapseConstants.Axis2Param.SYNAPSE_SERVER_NAME);

                if(serverName != null && messageContext instanceof Axis2MessageContext) {

                    AxisConfiguration configuration = ((Axis2MessageContext)messageContext).
                            getAxis2MessageContext().
                            getConfigurationContext().getAxisConfiguration();

                    String myServerName = getAxis2ParameterValue(configuration,
                            SynapseConstants.Axis2Param.SYNAPSE_SERVER_NAME);

                    if(!serverName.equals(myServerName)) {
                        return;
                    }

                }

                Set proSet = messageContext.getPropertyKeySet();

                if (proSet != null) {
                    if (proSet.contains(ForwardingProcessorConstants.BLOCKING_SENDER_ERROR)) {
                        proSet.remove(ForwardingProcessorConstants.BLOCKING_SENDER_ERROR);
                    }
                }

                String targetEp =
                        (String) messageContext.getProperty(ForwardingProcessorConstants.TARGET_ENDPOINT);

                if (targetEp != null) {
                    Endpoint ep = messageContext.getEndpoint(targetEp);

                    // stop processing if endpoint is not ready to send
                    if(!ep.getContext().readyToSend()) {
                        return;
                    }

                    if (ep instanceof AddressEndpoint) {

                        try {
                            MessageContext outCtx = sender.send(
                                    ((AddressEndpoint) ep).getDefinition(), messageContext);

                            if (outCtx != null && "true".equals(outCtx.
                                    getProperty(ForwardingProcessorConstants.BLOCKING_SENDER_ERROR))) {
                                // This Means an Error has occurred

                                if (maxDeliverAttempts > 0) {
                                    processor.incrementSendAttemptCount();
                                }

                                if (parameters != null &&
                                        parameters.get(
                                                ForwardingProcessorConstants.FAULT_SEQUENCE) != null) {

                                    String seq = (String) parameters.get(
                                            ForwardingProcessorConstants.FAULT_SEQUENCE);
                                    Mediator mediator = outCtx.getSequence(seq);
                                    if (mediator != null) {
                                        mediator.mediate(outCtx);
                                    } else {
                                        log.warn("Can't Send the fault Message , Sequence " + seq +
                                                " Does not Exist");
                                    }

                                }

                                if (maxDeliverAttempts > 0) {
                                    if(processor.getSendAttemptCount() >= maxDeliverAttempts) {
                                        processor.deactivate();
                                    }
                                }
                                errorStop = true;
                                continue;

                            } else if(outCtx == null) {
                                // This Means we have invoked an out only operation
                                // remove the message and reset the count
                                messageStore.poll();
                                processor.resetSentAttemptCount();
                                continue;
                            }

                            // If there is a sequence defined to send success replies,
                            // we must send the message to it
                            if (parameters != null &&
                                    parameters.get(
                                            ForwardingProcessorConstants.REPLY_SEQUENCE) != null) {
                                if (outCtx != null) {
                                    String seq = (String) parameters.get(
                                            ForwardingProcessorConstants.REPLY_SEQUENCE);
                                    Mediator mediator = outCtx.getSequence(seq);
                                    if (mediator != null) {
                                        mediator.mediate(outCtx);
                                    } else {
                                        log.warn("Can't Send the Out Message , Sequence " + seq +
                                                " Does not Exist");
                                    }
                                }
                            }

                            // If no Exception Occurred We remove the Message
                            // and reset the delivery attempt count
                            processor.resetSentAttemptCount();
                            messageStore.poll();
                        } catch (Exception e) {

                            if (maxDeliverAttempts > 0) {
                                processor.incrementSendAttemptCount();
                                if (processor.getSendAttemptCount() >= maxDeliverAttempts) {
                                    processor.deactivate();
                                }
                            }
                            errorStop = true;
                            log.error("Error Forwarding Message ", e);
                            continue;
                        }
                    } else {
                        // Currently only Address Endpoint delivery is supported
                        log.warn("Address Endpoint Named " + targetEp + " not found.Hence removing " +
                                "the message form store");
                        messageStore.poll();
                    }


                } else {
                    //No Target Endpoint defined for the Message
                    //So we do not have a place to deliver.
                    //Here we log a warning and remove the message
                    //todo: we can improve this by implementing a target inferring mechanism

                    log.warn("Property " + ForwardingProcessorConstants.TARGET_ENDPOINT +
                            " not found in the message context , Hence removing the message ");
                    messageStore.poll();

                }

            } else {
                errorStop = true;
View Full Code Here

    private String  onStoreSequence;


    public boolean mediate(MessageContext synCtx) {
        if(synCtx != null) {
            MessageStore messageStore = synCtx.getConfiguration().getMessageStore(messageStoreName);
            if(messageStore != null) {
                if(onStoreSequence != null) {
                    Mediator sequence = synCtx.getSequence(onStoreSequence);
                    if(sequence != null) {
                        sequence.mediate(synCtx);
                    }
                }

                if(log.isDebugEnabled()) {
                    log.debug("Message Store mediator storing the message : \n " + synCtx.getEnvelope());
                }

                // Here we set the server name in the message context before storing the message.
                //This can be used by the Processors in a clustering setup.
                if(synCtx instanceof Axis2MessageContext) {

                    String serverName =
                                        getAxis2ParameterValue(((Axis2MessageContext)synCtx).
                                        getAxis2MessageContext().
                                        getConfigurationContext().getAxisConfiguration(),
                                        SynapseConstants.Axis2Param.SYNAPSE_SERVER_NAME);
                    if(serverName != null) {
                        synCtx.setProperty(SynapseConstants.Axis2Param.SYNAPSE_SERVER_NAME,
                                serverName);
                    }

                }

                messageStore.offer(synCtx);

                // with the nio transport, this causes the listener not to write a 202
                // Accepted response, as this implies that Synapse does not yet know if
                // a 202 or 200 response would be written back.
                ((Axis2MessageContext) synCtx).getAxis2MessageContext().getOperationContext().setProperty(
View Full Code Here

TOP

Related Classes of org.apache.synapse.message.store.MessageStore

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.