A Java EE application is still a Java application. The difference between a normal Java application and a Java EE is only he fact that ONLY SOME of the instances of some classes (
ejb annotated classes) benefits from the services provided by the EJB container.
Why I said that? Because you miss a simple and trivial solution. What we do in a normal applications? One probable solution is to use a Singleton. The same in Java EE.
I think you can create a class MessageManager which implements Singleton pattern. That instance would have a property like Map<
String, Map><String, List><String>>>. The first String could be the target user name, second String would be sender user name, and the third one would be a message in queue. If a user sends a message to somebody, it should insert an entry here. As a sample if a send message x to b we would have messageQueue.get(b).get(a).add(x). Every user will read his messages periodically.
You could have also a Map<String, Date> like user time stamps. Every user when connects, will insert/update an entry in this map. Also, every connected user will update time stamp periodically. If the timestamp is older you can consider user away. If the time stamp is older enough you can remove the client from the map and consider it offline. Of course, you can give to a user the possibility to remove itself from timestamp map at sign out action.
Of course,
you should synchronize access to these maps. Users comes from different threads.
I don't have the possibility to try this at home but I will give a shot maybe tomorrow and see.
A scratch would be:
Hope it helps