On Nov 20, 2009, at 7:30 AM, thabach wrote:

We are implementing a JCA resource adapter

Ooh, sounds like a fun project. You can do unbelievably cool and *portable* things with RAs.

If you're doing anything REST based or generic, could be a great contribution. There are like a million connectors I'd love to write.

and are experiencing a strange
problem regarding dispatching incoming messages to the MDB pool. We have implemented the standard mechanism for dispatching to the endpoint as shown
in this snippet (according to the J2EE Connector Architecture Spec -
November 2003, section 12.5.1) :


OurMessageListener endpoint =
(OurMessageListener)_messageEndpointFactory.createEndpoint(null);

endpoint.onMessage(message);


We have exactly one acceptor thread receiving incoming messages which will then hit the above code. The problem we are experiencing is that after ten
messages we receive the following:


javax.resource.spi.UnavailableException: Only 10 instances can be created


And indeed we notice it uses each MDB instance exactly once until it runs
out. It seems as if MDB's are not being released back into the pool.

The missing part of the puzzle is the MessageEndpoint interface. Cast your instance of OurMessageListener to MessageEndpoint and call the release() method. Also there is no pool, the createEndpoint will physically create an instance of the MDB (injection, @PostConstruct, and such) and the release method will destroy it (@PreDestroy). It's the RA that does the pooling and the InstanceLimit property of the MDB container is basically there to prevent mistakes like this from going into production.

You'll probably immediately notice the beforeDelivery and afterDelivery methods which the RA should call before invoking the "onMessage" method.

Check out this test case. It has just about everything you need to know to write your own RA. It should save you a ton of time.

  
http://svn.apache.org/repos/asf/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/CustomMdbContainerTest.java

-David

Reply via email to