I'm writing an application in Java that reads sensor data and I want to show this data in real-time to a number of clients (in their browser). In order to accomplish this I already have an servlet using the atmosphere framework to communicate using web-socket if possible (and fall back to long-polling if not). On the other hand I have a java class that constantly read's in and interprets the sensor data.
However this question is not about web socket but how can I merge these two programs? I have little experience with servlets. As far as I can tell every time a client connect a new instance of the servlet is dispatched but I don't want a new instance of my data gathering program; I want this data gathering program to communicate to all the clients (and their servlets). Is this possible?
edit: The data gathering program is actually reading from a serial port and decoding it's data (data over serial port is encryped using special protocol).