[jboss-user] [JBoss Messaging] - Re: XA datasource with JBM problem

perisb do-not-reply at jboss.com
Tue Aug 19 13:16:08 EDT 2008


I am on 4.0.2

Here is the Interceptor:

package test;

import org.jboss.invocation.Invocation;
import org.jboss.ejb.Interceptor;
import org.jboss.ejb.Container;
import org.jboss.ejb.EntityContainer;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.jms.*;
import javax.ejb.EJBObject;
import javax.transaction.TransactionManager;
import java.lang.reflect.Method;
import java.util.Arrays;

public
class	TestInterceptor implements Interceptor {

public
void	setNext(Interceptor next) {
	this.next =  next;
}

public
Interceptor getNext() {
	return next;
}

public
void	setContainer(Container container) {
	this.container =  (EntityContainer)container;
}

public
void	create() throws Exception {
	name =  container.getBeanMetaData().getEjbName();
	if (!name.equals("Foo")) // only operate on entity Foo
		return;
	Context ctx = new InitialContext();
	QueueConnectionFactory qcf = (QueueConnectionFactory)ctx.lookup("java:/JmsXA");
	conn =  qcf.createQueueConnection();
	queue =  (Queue)ctx.lookup("queue/DDSListenerQ");
	session =  conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
	conn.start();
}

public
Object	invokeHome(Invocation invocation) throws Exception {
	Object returnValue = getNext().invokeHome(invocation);
	return returnValue;
}

public
Object	invoke(Invocation invocation) throws Exception {
	Object returnValue = getNext().invoke(invocation);
	if (!name.equals("Foo"))
	return returnValue;
	Method method = invocation.getMethod();
	if (method != null) {
		String mname = method.getName();
		if (mname.startsWith("set")) {
			QueueSender sender = session.createSender(queue);
			TextMessage tm = session.createTextMessage(invocation.getId()+",mname.substring(3),"+invocation.getArguments()[0]);
			sender.send(tm);
			sender.close();
		}
	}
	return returnValue;
}

public
void	start() throws Exception {
}

public
void	stop() {
}

public
void	destroy() {
	//session.close();
	//conn.close();
}

private	Interceptor	next;
private EntityContainer	container;
private	String		name;
private	QueueConnection	conn;
private	QueueSession	session;
private	Queue		queue;

}


Here is the remote client test driver snippet: (there is an EJB wrapper framework in place; the Context object wraps UserTransaction, FooHomeRemote, etc.)

	Context ctx = ContextRemoteImpl.instance();
	ctx.begin();
	Foo foo = ctx.FooFactory().findByOID(333l);
	foo.setBar("Bat");
	ctx.rollback();

Finally, here is an MDB that listens to the Queue, and receives a message, even though the client rolls back:

package test;

import javax.ejb.MessageDrivenBean;
import javax.ejb.MessageDrivenContext;
import javax.ejb.EJBException;
import javax.jms.MessageListener;
import javax.jms.Message;

public
class	TestMDBImpl implements MessageDrivenBean, MessageListener {

public
void	ejbCreate() {	
}

public
void	setMessageDrivenContext(MessageDrivenContext mdc) {
}

public
void	onMessage(Message message) {
System.err.println("GOT MESSAGE:"+message);
}


public
void ejbRemove() throws EJBException {\
}

}


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4171330#4171330

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4171330



More information about the jboss-user mailing list