In my application based on JBoss (version 5) I need to listen for UDP packets. The easies way (and probably the only one ) is to open DatagramSocket on certain port (using JBoss @Service singleton bean) and call receive(...) method. The first part is pretty easy - I've tested it and works as expected. Second part - receiving packets is more complicated. I am wondering about design of such a code. As it is stated in DatagramSocket javadoc, receive is a blocking operation - it blocks until packet is retrieved. How to code it to make sure that it is fast, scalable and thread-safe?
I thought about writing stateless beans that holds a reference to singleton with opened connection, and those beans are calling receive method - but I am not very sure how JBoss would manage those beans. Is there any pattern to use?
Thanks in advance,
Reading your question my first idea was to implement a Netty-Listener:
I can't remember exactly but there you've got several individual possibilities to serve requests on any protocoll.
From the Netty-Listener you can can use a remote access to your ejb. But I think the whole suggestion is a very sophisticated solution.