Expanding our client application
It's time to show how you can leverage the WebSocket features in real life. In the previous chapter, Chapter 7, Adding Web Services to Your Applications, we created the ticket booking application based on the REST API and AngularJS framework. It was clearly missing one important feature: the application did not show information concerning ticket purchases of other users. This is a perfect use case for WebSockets!
Since we're just adding a feature to our previous app, we will only describe the changes we will introduce to it.
In this example, we would like to be able to inform all current users about other purchases. This means that we have to store information about active sessions. Let's start with the registry type object, which will serve this purpose. We can use a Singleton
session bean for this task, as shown in the following code:
@Singleton public class SessionRegistry { private final Set<Session> sessions = new HashSet<>(); @Lock...