2

I'm trying to transfer data (from a thread started in a ServletContextListener which is continuously adding data to the queue) to a ServletContextAttributeListener.

The data from the queue needs to be passed on to the connected clients which are notified on "attributeReplaced".

The data is contained in a BlockingQueue.

However I'm kind of confused; if I'm placing the BlockingQueue in the context by calling

private BlockingQueue<String> queue = new LinkedBlockingQueue<String>();
//..
event.getServletContext().setAttribute("serialPortData", queue);
//..

Question: Does the context then contain a copy of this Queue or a pointer?

Because if it only copies the queue then it would not make sense to add a Queue to the context right? Or would you solve this problem in another way?

Thomas.

Thomas
  • 1,678
  • 4
  • 24
  • 47
  • Have you checked if you need the data inside the queue to be Serializable in order to be transferred to the context? – Alberto Segura Mar 05 '13 at 14:02
  • The data doesn't implement java.io.Serializable if that is what you mean. Data is just decoded frames read from a serial port which contains information from different sensors (GPS,Gyro,Alti,Speed) that need to be sent to the clients regularly. – Thomas Mar 05 '13 at 14:06
  • 1
    The `Context` is simply a `Map` - it holds pointers. I would wrap your `Queue` in an `Object` of some sort - to make the code clearer. – Boris the Spider Mar 05 '13 at 14:08
  • Then I only need to add the Queue to the context once. context.getServletContext().setAttribute("serialPortData", queue); Then simply adding data using queue.add will also change the queue inside the context. And the attributeAdded will be called inside the event listener where I read the queue and block if empty. Correct? – Thomas Mar 05 '13 at 14:21

0 Answers0