I have implemented a JCA 1.5 resource adapter for XMPP based on the smack api but have run into a problem which will require modification to the way XMPPConnection creates and manages Threads through the PacketReader and PacketWriter classes. The purpouse of this post is to solicit comments on a possible solution to this problem.
By way of motivation let me breafly mention what a JCA resource adaptor is for those not in the know. The J2EE spec from 1.3 and later allows for a general interface to external enterprise information systems (EIS) - things like SAP, MQ or for that matter an XMPP server. The JCA framework include things like transaction management, connection pooling etc. By creating a resource adaptor for XMPP it is possible to use XMPP-based services from J2EE components (like for instance EJB session or message-driven beans). It is instructive to view a resource adaptor as a generalization of the JDBC database connection concept.
While doing this I have implemented most of publish-subscribe too but that is not why I need your help now.
The problem is that inside an EJB server components cannot create Threads. Instead the JCA framework provides an interface into the EJB thread management subsystem. This means that in order for my RA to work I need a way to supply alternative implementations of the PacketReader and PacketWriter classes that don’'t call new Thread directly.
I can see a couple of alternatives:
- Turn PacketWriter and PacketReader into interfaces. Also create the corresponding
Packet{Reader,Writer}Factory interface. Instances of these interfaces are associated
with the XMPPConnection which allows custom implementations to be set (perhaps
in the constructor).
- Modify PacketReader and PacketWriter to provide overridable methods and fields
to allow readerThread and writerThread to be substituted for objects which play the
same roles as theads inside an EJB container.
Personally I much prefer option 1. It is clean and will not affect deployed code. I am
perfectly willing (of course) to provide an implementation of these ideas if there is a
chance they will be acceptable to the community.
Cheers Leif