java - Web socket chat and EJB services -


I'm new Java / EJB developer. I want to create chat service for my web application. The main functionality of the chat feature is to make the user Depending on some events to send ordinary messages. Here is the code:

Chat endpoint

  @ServerEndpoint (value = "/ chat") Public class ChatEndpoint {@OnOpen Public Zero Open ( Last Session Session, Last EndpointConfig Config) {} @OnMessage Public Zero Message (Last String msg) {} @OnError Public Zero onError (Throwable T) {} @OnClose Public Zero OnClose {Last Session Session} {} Public Zero SendMessage @ Observe chat event event) {System.out.println ("Try sending new message:" + event.getMessage ()); }}  

Event class

  Public class ChatEvent {Private last string message; Public chat event (last string message) {this.message = message; } Public string getMessage () {return message; }}  

Timer class (to send some random messages)

  @Stateless Public Square ChatTimer {@Inject of event & Lt; ChatEvent & gt; Arrangement; @Schedule (second = "*", minutes = "*", hours = "*") Public Zero sendSomeRandomeMessage () {println ("Send Event"); Events.fire (new ChatEvent ("From Bean" + System.currentTimeMillis ()); }}  

Now my question is:

  1. There is any problem in making @ServerEndpoint @Stateless as (without @Stateless) Observes method is not working)
  2. How can I track all open sessions (users) to broadcast a message? (My current strategy is to save them to a stable area that does not look right!)


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -