Package org.codehaus.activemq.message

Examples of org.codehaus.activemq.message.ActiveMQMessage


    private void doPeek(QueueMessageContainer container, QueueList browsers) throws JMSException {
        if (browsers != null && browsers.size() > 0) {
            for (int i = 0; i < browsers.size(); i++) {
                SubscriptionImpl sub = (SubscriptionImpl) browsers.get(i);
                int count = 0;
                ActiveMQMessage msg = null;
                do {
                    msg = container.peekNext(sub.getLastMessageIdentity());
                    if (msg != null) {
                        if (sub.isTarget(msg)) {
                            sub.addMessage(container, msg);
                            dispatcher.wakeup(sub);
                        }
                        else {
                            sub.setLastMessageIdentifier(msg.getJMSMessageIdentity());
                        }
                    }
                }
                while (msg != null && !sub.isAtPrefetchLimit() && count++ < MAX_MESSAGES_DISPATCHED_FROM_POLL);
            }
View Full Code Here


        }
    }

    private void doPoll(QueueMessageContainer container, QueueList subList) throws JMSException {
        int count = 0;
        ActiveMQMessage msg = null;
        if (subList != null && subList.size() > 0) {
            do {
                boolean dispatched = false;
                msg = container.poll();
                if (msg != null) {
                    QueueListEntry entry = subList.getFirstEntry();
                    boolean targeted = false;
                    while (entry != null) {
                        SubscriptionImpl sub = (SubscriptionImpl) entry.getElement();
                        if (sub.isTarget(msg)) {
                            targeted = true;
                            if (!sub.isAtPrefetchLimit()) {
                                sub.addMessage(container, msg);
                                dispatched = true;
                                dispatcher.wakeup(sub);
                                subList.rotate(); //round-robin the list
                                break;
                            }
                        }
                        entry = subList.getNextEntry(entry);
                    }
                    if (!dispatched) {
                        if (targeted) { //ie. it can be selected by current active consumers - but they are at
                            // pre-fectch
                            // limit
                            container.returnMessage(msg.getJMSMessageIdentity());
                        }
                        break;
                    }
                }
            }
View Full Code Here

     * Receives the next message that arrives within the specified timeout interval.
     * @throws JMSException
     */
    public ActiveMQMessage receive(long timeout) throws JMSException {
        try {
            ActiveMQMessage message = (ActiveMQMessage) messageQueue.dequeue(timeout);
            return message;
        }
        catch (InterruptedException ioe) {
            return null;
        }
View Full Code Here

    private void fillBuffer(int requiredLength) throws IOException {
        int len = 0;
        try {
            do {
                if (!closed) {
                    ActiveMQMessage msg = null;
                    if (len == 0 && requiredLength > 0) {
                        msg = (ActiveMQMessage) consumer.receive(2000);
                    }
                    else {
                        msg = (ActiveMQMessage) consumer.receiveNoWait();
                    }
                    if (msg != null) {
                        ByteArray ba = msg.getBodyAsBytes();
                        if (ba != null) {
                            len += ba.getLength();
                            process(ba);
                        }
                    }
View Full Code Here

                if (brokerConnection) {
                    packet.addBrokerVisited(remoteBrokerName); //got from the remote broker
                    packet.addBrokerVisited(brokerName);
                }
                if (packet.isJMSMessage()) {
                    ActiveMQMessage message = (ActiveMQMessage) packet;
                   
                    if (!brokerConnection) {
                        message.setEntryBrokerName(brokerName);
                        message.setEntryClusterName(clusterName);
                    }
                    consumeActiveMQMessage(message);
                }
                else {
                    switch (packet.getPacketType()) {
View Full Code Here

                    for (Iterator i = sessions.iterator();i.hasNext();) {
                        SessionInfo si = (SessionInfo) i.next();
                        si.setClientId(info.getClientId());
                    }
                    for (int i = 0;i < dispatchQueue.size();i++) {
                        ActiveMQMessage msg = (ActiveMQMessage) dispatchQueue.get(i);
                        dispatch(msg);
                    }
                    dispatchQueue.clear();
                }
                if (started.get() && !info.isStarted()) {
View Full Code Here

    public Message receive() throws JMSException {
        checkClosed();
        session.setSessionConsumerDispatchState(ActiveMQSession.CONSUMER_DISPATCH_SYNC);
        try {
            this.accessThread = Thread.currentThread();
            ActiveMQMessage message = (ActiveMQMessage) messageQueue.dequeue();
            this.accessThread = null;
            if (message != null) {
                boolean expired = message.isExpired();
                messageDelivered(message, true, expired);
                if (!expired) {
                    message = message.shallowCopy();
                }
                else {
                    message = (ActiveMQMessage) receiveNoWait(); //this will remove any other expired messages held in the queue
                }
            }
View Full Code Here

        try {
            if (timeout == 0) {
                return this.receive();
            }
            this.accessThread = Thread.currentThread();
            ActiveMQMessage message = (ActiveMQMessage) messageQueue.dequeue(timeout);
            this.accessThread = null;
            if (message != null) {
                boolean expired = message.isExpired();
                messageDelivered(message, true, expired);
                if (!expired) {
                    message = message.shallowCopy();
                }
                else {
                    message = (ActiveMQMessage) receiveNoWait(); //this will remove any other expired messages held in the queue
                }
            }
View Full Code Here

     */
    public Message receiveNoWait() throws JMSException {
        checkClosed();
        session.setSessionConsumerDispatchState(ActiveMQSession.CONSUMER_DISPATCH_SYNC);
        try {
            ActiveMQMessage message = null;
            //iterate through an scrub delivered but expired messages
            while ((message = (ActiveMQMessage) messageQueue.dequeueNoWait()) != null) {
                boolean expired = message.isExpired();
                messageDelivered(message, true, expired);
                if (!expired) {
                    if( message!=null && log.isDebugEnabled() ) {
                        log.debug("Message received: "+message);
                    }           
                    return message.shallowCopy();
                }
            }
        }
        catch (InterruptedException ioe) {
            throw new JMSException("Queue is interrupted: " + ioe.getMessage());
View Full Code Here

     * @see org.codehaus.activemq.message.PacketListener#consume(org.codehaus.activemq.message.Packet)
     */
    public void consume(Packet packet) {
        if (!closed && packet != null) {
            if (packet.isJMSMessage()) {
                ActiveMQMessage message = (ActiveMQMessage) packet;
                message.setReadOnly(true);
                message.setConsumerIdentifer(clientID);

                // lets check for expired messages which is only relevant for multicast based stuff
                // as a pointcast based network should filter out this stuff
                if (transportChannel.isMulticast()) {
                    long expiration = message.getJMSExpiration();
                    if (expiration > 0) {
                        long timeStamp = System.currentTimeMillis();
                        if (timeStamp > expiration) {
                            if (log.isDebugEnabled()) {
                                log.debug("Discarding expired message: " + message);
                            }
                            return;
                        }
                    }
                }

                try {
                    int count = 0;
                    for (Iterator i = this.messageDispatchers.iterator(); i.hasNext();) {
                        ActiveMQMessageDispatcher dispatcher = (ActiveMQMessageDispatcher) i.next();
                        if (dispatcher.isTarget(message)) {
                            if (count > 0) {
                                //separate message for each Session etc.
                                message = message.deepCopy();
                            }
                            dispatcher.dispatch(message);
                            count++;
                        }
                    }
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.