users@grizzly.java.net

UDP problem after restartarting Controller

From: LittleBear <petrinic_at_iskratel.si>
Date: Mon, 21 Jul 2008 06:28:06 -0700 (PDT)

Hi,

I am implementing an UDP server (listening on a fixed port) with Grizzly.
One of use cases is to start and stop the UDP server without restarting the
JVM. So I implemented the start() and stop() methods:

public void start() {
                controller = new Controller();

                udpSelector = new UDPSelectorHandler();
                udpSelector.setPort(5555);
                controller.addSelectorHandler(udpSelector);
                
                mySharedPipeline = new DefaultPipeline();
                controller.setPipeline(mySharedPipeline);

                pciHandler = new StackInstanceHandler();
                controller.setProtocolChainInstanceHandler(pciHandler);

                th = new Thread(controller);
                th.start();
        }

        public void stop() {
                controller.stop();
        }


The server works fine until I restart it (call stop() then start()). Then I
get a strange behaviour in the Filter that parses the messages...
The full scenario is:

1. start the server
2. send some (e.g. 5 different) messages from the client, they get parsed,
answers are sent, all is Ok
3. restart the server
4. send a new message from the client
5. my Filter.execute() is called, but the buffer is not as expected. It
contains bytes from the last message sent in step 2. I get the buffer this
way:

WorkerThread workerThread = ((WorkerThread) Thread.currentThread());
ByteBuffer buffer = workerThread.getByteBuffer();


It looks like the bytes from the last message in step 2 remain somewhere in
the buffer/socket/controller and are sent to my Filter when a totally new
message is received on the socket.

I tried also:
  mySharedPipeline.stopPipeline();
  udpSelector.shutdown();
in the stop() method, but the results were the same.


Any idea what could be wrong?

-- 
View this message in context: http://www.nabble.com/UDP-problem-after-restartarting-Controller-tp18568653p18568653.html
Sent from the Grizzly - Users mailing list archive at Nabble.com.