Package org.mom4j.messaging

Source Code of org.mom4j.messaging.P2PFilter

package org.mom4j.messaging;

import org.mom4j.messaging.select.Element;

import java.io.IOException;

import javax.jms.JMSException;
import javax.jms.Message;


public class P2PFilter implements Filter {

    private Console console;

   
    public P2PFilter(Console c) {
        this.console = c;
    }


    public void send(String  sessionId,
                     String  destination,
                     Message msg,
                     boolean transacted)
        throws IOException, JMSException
    {
        this.console.sendInternal(sessionId, destination, msg);
        if(!transacted) {
            //This is for non-transacted sessions
            this.console.commit(sessionId);
        }
    }
   

    public Message receive(String  sessionId,
                           String  destination,
                           String  consumerId,
                           boolean transacted)
        throws IOException, JMSException
    {
        Element e = this.console.getMessageSelector(destination, consumerId);

        Message ret = null;

        if(e != null) {
            PeekMessage pmsg = null;
            while((pmsg = this.console.peek(sessionId, destination)) != null) {
                if(e.match(pmsg.getMessage())) {
                    break;
                }
            }
            if(pmsg != null) {
                this.console.acknowledge(sessionId, pmsg);
                ret = pmsg.getMessage();
            }
        } else {
            ret = this.console.receiveInternal(sessionId, destination);
        }

        if(!transacted) {
            //This is for non-transacted sessions
            this.console.commit(sessionId);
        }
        return ret;
    }

}
TOP

Related Classes of org.mom4j.messaging.P2PFilter

TOP
Copyright © 2018 www.massapi.com. 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.