users@grizzly.java.net

Re: Thread name is always...GrizzlyWorkerThread-8080 ?

From: Neil Avery <neil.avery_at_gmail.com>
Date: Mon, 26 May 2008 12:14:59 +0100

ServerCode for its creation follows.......
Cheers Neil.


public class GrizzlyReceiver implements Receiver {

    static final Logger LOGGER = Logger.getLogger(GrizzlyReceiver.class);


    private final URI startPoint;
    final ProtocolFilter read = new ReadFilter();
    final LogFilter log = new LogFilter();
    final TCPSelectorHandler tcpHandler = new TCPSelectorHandler();
    final Controller controller = new Controller();
    ProtocolFilter protocolFilter;

    public GrizzlyReceiver(URI address, Receiver receiver) {
        this.startPoint = address;
        this.receiver = receiver;
    }

    public void start() {
        if (state == LifeCycle.State.STARTED) return;
        state = LifeCycle.State.STARTED;
        LOGGER.info("GrizzlyReceiver starting on[" + startPoint + "]");
        tcpHandler.setPort(startPoint.getPort());
        controller.setSelectorHandler(tcpHandler);

        final ProtocolFilter myFilter = new LLProtocolFilter();
        controller.setProtocolChainInstanceHandler(new
DefaultProtocolChainInstanceHandler() {
            public ProtocolChain poll() {
                ProtocolChain protocolChain = protocolChains.poll();
                if (protocolChain == null) {
                    protocolChain = new DefaultProtocolChain();
                    protocolChain.addFilter(read);
                    protocolChain.addFilter(log);
                    protocolChain.addFilter(new MyProtocolFilter());
                }
                return protocolChain;
            }

        });
        new Thread(controller).start();
    }
    public class MyProtocolFilter implements ProtocolFilter {

        public boolean postExecute(Context ctx) throws IOException {
            return true;
        }

        public boolean execute(Context ctx) throws IOException {

                final WorkerThread workerThread = ((WorkerThread)
Thread.currentThread());
                ByteBuffer buffer = workerThread.getByteBuffer();
                buffer.flip();
                System.out.println("Thread is:" +
Thread.currentThread().getName());
                // handler code <snipped>
               return false;
            }
    public boolean postExecute(Context ctx) throws IOException {
        return true;
      }

}
}





Date: Mon, 26 May 2008 11:23:20 +0200
From: Oleksiy Stashok <Oleksiy.Stashok_at_Sun.COM>
Content-type: text/plain; delsp=yes; format=flowed; charset=US-ASCII
Subject: Thread name is always...GrizzlyWorkerThread-8080 ?

Hello Neil,
can you pls. share the code, how you instantiate the server?

Thanks.

WBR,
Alexey.

On May 25, 2008, at 20:26 , Neil Avery wrote:

> Hi,
> Ive started using Grizzly and in the testcases Im writing I will
> fire of multiple Servers - however as each instance receives its
> payload, the WorkerThread always has a name of
> "GrizzlyWorkerThread-8080-" regardless of the address and port being
> used.
>
> Is it possible to have the WorkerThread pool use the correct name
> and port ?
>
> Regards Neil.