Package org.codehaus.activemq.message

Examples of org.codehaus.activemq.message.ActiveMQMessage


        //iterate through the message table and populate the subscriber
        Map map = new HashMap(messageTable);
        boolean alreadyAcked = true;
        MessageIdentity lastAcked = (MessageIdentity)ackDatabase.get(subscription.getPersistentKey());
        for (Iterator i = map.values().iterator(); i.hasNext(); ){
            ActiveMQMessage msg = (ActiveMQMessage)i.next();
            if (lastAcked == null || !alreadyAcked){
                subscription.addMessage(container, msg);
            }
            if (lastAcked != null){
                if (lastAcked.getMessageID().equals(msg.getJMSMessageID())){
                    alreadyAcked = false;
                }
            }
        }
    }
View Full Code Here


    /**
     * implementation of Runnable
     */
    public void run() {
        while (!closed && !dispatchedBySessionPool) {
            ActiveMQMessage message = null;
            try {
                message = (ActiveMQMessage) messageQueue.dequeue(100);
            }
            catch (InterruptedException ie) {
            }
View Full Code Here

     * @return an ActiveMQMessage
     * @throws JMSException if the JMS provider fails to create this message due to some internal error.
     */
    public Message createMessage() throws JMSException {
        checkClosed();
        return new ActiveMQMessage();
    }
View Full Code Here

     * Optional operation, intended to be used only by Application Servers, not by ordinary JMS clients.
     *
     * @see javax.jms.ServerSession
     */
    public void run() {
        ActiveMQMessage message;
        while ((message = messageExecutor.dequeueNoWait()) != null) {
            this.beforeMessageDelivered(message);
            preDeliveryHook(messageListener, message);
            deliver(message);
            postDeliveryHook(messageListener, message);
View Full Code Here

        /**
         * Find the caller and ensure it is marked as consumed
         * This is to ensure acknowledge called by a
         * MessageListener works correctly
         */
        ActiveMQMessage msg = (ActiveMQMessage)deliveredMessages.get(caller);
        if (msg != null){
            msg.setMessageConsumed(true);
        }
      
        doAcknowledge(false);
    }
View Full Code Here

    }

    protected void doAcknowledge(boolean isClosing) throws JMSException {
        if (!closed) {
            if (this.acknowledgeMode == Session.CLIENT_ACKNOWLEDGE) {
                ActiveMQMessage msg = null;
                while((msg = (ActiveMQMessage)deliveredMessages.removeFirst())!=null){
                    boolean messageConsumed = isClosing ? false : msg.isMessageConsumed();
                    if (!msg.isTransientConsumed()){
                        sendMessageAck(msg, messageConsumed, false);
                    }else {
                        if (!messageConsumed){
                            connection.addToTransientConsumedRedeliverCache(msg);
                        }
View Full Code Here

       
        if ((id == null || id.length() == 0) || !producer.getDisableMessageID() && !reuseMessageId) {
            message.setJMSMessageID(producerKey + sequenceNumber);
        }
        //transform to our own message format here
        ActiveMQMessage msg = ActiveMQMessageTransformation.transformMessage(message);
        if (connection.isCopyMessageOnSend()){
            msg = msg.shallowCopy();
        }
        //clear identity - incase forwared on
        msg.setJMSMessageIdentity(null);
        connection.validateDestination(msg.getJMSActiveMQDestination());
       
        msg.setExternalMessageId(id != null);
        msg.setSequenceNumber(sequenceNumber);
        msg.setProducerKey(producerKey);
        msg.setTransactionId(currentTransactionId);
        msg.setJMSClientID(this.connection.clientID);
        msg.setMesssageHandle(producer.getProducerId());
        //reset state as could be forwarded on
        msg.setJMSRedelivered(false);
        if (!connection.isInternalConnection()){
            msg.clearBrokersVisited();
        }
       
        if (this.connection.isPrepareMessageBodyOnSend()){
            msg.prepareMessageBody();
        }
        //do message payload compression
        if (connection.isDoMessageCompression()){
            try {
                msg.getBodyAsBytes(compression);
            }
            catch (IOException e) {
                JMSException jmsEx = new JMSException("Failed to compress message payload");
                jmsEx.setLinkedException(e);
                throw jmsEx;
            }
        }
        boolean fragmentedMessage = connection.isDoMessageFragmentation();
        if (fragmentedMessage && !msg.isMessagePart()){
            try {
                if ((fragmentedMessage = fragmentation.doFragmentation(msg.getBodyAsBytes()))){
                    ByteArray[] array = fragmentation.fragment(msg.getBodyAsBytes());
                    String parentMessageId = msg.getJMSMessageID();
                    for (int i = 0; i < array.length; i++){
                        ActiveMQMessage fragment = msg.shallowCopy();
                        fragment.setJMSMessageID(null);
                        fragment.setMessagePart(true);
                        fragment.setParentMessageID(parentMessageId);
                        fragment.setNumberOfParts((short)array.length);
                        fragment.setPartNumber((short)i);
                        if (i != 0){
                            fragment.setSequenceNumber(producer.getIdGenerator().getNextSequence());
                        }
                        fragment.setBodyAsBytes(array[i]);
                        if (this.connection.isUseAsyncSend()) {
                            this.connection.asyncSendPacket(fragment);
                        }
                        else {
                            this.connection.syncSendPacket(fragment);
View Full Code Here

        }
       
        deliveredMessages.clear();
        if (!replay.isEmpty()) {
            for (ListIterator i = replay.listIterator(replay.size());i.hasPrevious();) {
                ActiveMQMessage msg = (ActiveMQMessage) i.previous();
                if (!onlyDeliverTransientConsumed || msg.isTransientConsumed()) {
                    msg.setJMSRedelivered(true);
                    msg.incrementDeliveryCount();
                    messageExecutor.executeFirst(msg);
                }
            }
        }
        replay.clear();
View Full Code Here

     * @param msg consumed message from remote broker
     */
    public void onMessage(Message msg) {
        try {
            if (!stopped) {
                ActiveMQMessage message = (ActiveMQMessage) msg;
                if (message != null) {
                    message = message.shallowCopy();
                    message.addBrokerVisited(localBrokerName);
                    Destination destination = message.getJMSDestination();
                    int deliveryMode = message.getJMSDeliveryMode();
                    int priority = message.getJMSPriority();
                    long timeToLive = message.getJMSExpiration() - msg.getJMSTimestamp();
                    localProducer.send(destination, message, deliveryMode, priority, timeToLive);
                    //acknowledge the original
                    msg.acknowledge();
                }
            }
View Full Code Here

    protected boolean isClientAcknowledge() {
        return this.acknowledgeMode == Session.CLIENT_ACKNOWLEDGE;
    }
   
    private final ActiveMQMessage assembleMessage(ActiveMQMessage message) {
        ActiveMQMessage result = message;
        if (message != null && !connection.isInternalConnection() && message.isMessagePart()) {
            if (message.getNumberOfParts() == 1) {
                //passed though from another session - i.e.
                //a network or remote connection and now assembled
                message.resetMessagePart();
                result = message;
            }
            else {
                result = null;
                String parentId = message.getParentMessageID();
                ActiveMQMessage[] array = (ActiveMQMessage[]) assemblies.get(parentId);
                if (array == null) {
                    array = new ActiveMQMessage[message.getNumberOfParts()];
                    assemblies.put(parentId, array);
                }
                array[message.getPartNumber()] = message;
                boolean complete = true;
                for (int i = 0;i < array.length;i++) {
                    complete &= array[i] != null;
                }
                if (complete) {
                    result = array[0];
                    ByteArray[] bas = new ByteArray[array.length];
                    try {
                        for (int i = 0;i < bas.length;i++) {
                            bas[i] = array[i].getBodyAsBytes();
                            if (i >= 1){
                                array[i].clearBody();
                            }
                        }
                        ByteArray ba = fragmentation.assemble(bas);
                        result.setBodyAsBytes(ba);
                    }
                    catch (IOException ioe) {
                        JMSException jmsEx = new JMSException("Failed to assemble fragment message: " + parentId);
                        jmsEx.setLinkedException(ioe);
                        this.connection.onException(jmsEx);
View Full Code Here

TOP

Related Classes of org.codehaus.activemq.message.ActiveMQMessage

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.