Question

In my project I have all services designed as stateless session beans. During the workflow, new data is created and this should be reported back to the clients. I only want to send this messages when the transaction is successfully committed.

I have a ServletContextListener registered which dispatches my xmpp packets (smack library). When I receive a packet, I locate my dispatching stateful session bean and start the processing of the request.

public void processPacket(Packet packet) {
    try{
        if(packet instanceof RawRequest){
            DispatchIQService service = Core.lookup(DispatchIQService.class);
            service.process(connection, (RawRequest)packet);
            // sending of the messages should happen here, because transaction completed successful.
        }else{
            log.debug("Packet ignored: " + packet.toXML());
        } 
    }catch(Exception e){
        log.error(e, e);
    }
}
  1. How can I collect this generated messages during the workflow accross multiple beans? I would return this list from the dispatch bean and send the messages afterwards. My simple solution would be to route through a list where I add my messages, but is there a more elegant way?

  2. I have an XMPP resource (roster http://www.igniterealtime.org/builds/smack/docs/latest/javadoc/org/jivesoftware/smack/Roster.html) which I have to access from all beans. How can I accomplish that? Store it into a static variable and synchronize the access to it doesn't sound very good.

Was it helpful?

Solution

Markus, I'm not a guru of J2EE, but for your purposes I recommend taking a look at JMS. This will help you implement message-based approach. As for me, I used to go with RabbitMQ system. It was great experience, but additional software is required to run the system.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top