void sendSubscriptionEvent ( String topic , int nb ) { Collection < Session > sessions = getSessionsForTopic ( topic ) ; if ( ! sessions . isEmpty ( ) ) { MessageToClient messageToClient = new MessageToClient ( ) ; messageToClient . setId ( topic ) ; messageToClient . setType ( MessageType . MESSAGE ) ; messageToClient . setResponse ( nb ) ; // Collection<Session> sessionsClosed = new ArrayList<>(); // throws java.lang.StackOverflowError for ( Session session : sessions ) { if ( session . isOpen ( ) ) { session . getAsyncRemote ( ) . sendObject ( messageToClient ) ; // } else { // sessionsClosed.add(session); } } // removeSessionsToTopic(sessionsClosed); } }
Send subscription event to all client