users@grizzly.java.net

Re: ServerSocket -> Grizzly Implementation ?

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Fri, 02 Oct 2009 16:28:22 -0400

Salut,

dentz wrote:
> Hi,
>
> I have a Server implementation like this:
>
> ServerSocket s = new ServerSocket(this.port);
> while (true)
> {
> logger.info("Waiting....!");
> Socket conexao = s.accept();
> logger.info("Connected!");
> /* do Something...*/
> }
>
> I need to know when a new connection have been established.
> I tried using a custom Filter but with no success.
>
> Is threre a way to do that with Grizzly (1.9.18a or 2.0.0 M3)?
>
> That's my Grizzly implementation so far:
>
> //--------------
> TCPSelectorHandler selectorHandler = new TCPSelectorHandler();


selectorHandler = new TCPSelectorHandler(){

     public boolean onAcceptInterest(SelectionKey key,
             Context ctx) throws IOException{
        boolean b = super(key,ctx);
         logger.info("Connected!");
         return b;
     }
}



> selectorHandler.setPort(PORT);
> selectorHandler.setInet(InetAddress.getByName(HOST));
>
> controller.setSelectorHandler(selectorHandler);
>
> DefaultThreadPool threadPool = new
> DefaultThreadPool("ThreadPool",5,10,100,TimeUnit.DAYS);
> controller.setThreadPool(threadPool);
>
> //Protocol Chain
> controller.setProtocolChainInstanceHandler(new
> DefaultProtocolChainInstanceHandler(){
> @Override
> public ProtocolChain poll() {
> ProtocolChain protocolChain = protocolChains.poll();
> if (protocolChain == null){
> protocolChain = new DefaultProtocolChain();
> protocolChain.addFilter(myFilter);
> }
> return protocolChain;
> }
> });
>
> controller.start();
> //--------------
>
>
> Thanks! []'s
>
> ps. Sorry for my english! :P

Hope that help.

Thanks

--Jeanfrancois


>
>