ServerSocket -> Grizzly Implementation ?

View: New views
3 Messages — Rating Filter:   Alert me  

ServerSocket -> Grizzly Implementation ?

by dentz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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.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
                           

Re: ServerSocket -> Grizzly Implementation ?

by Jeanfrancois Arcand-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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


>          
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: ServerSocket -> Grizzly Implementation ?

by Oleksiy Stashok :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

in Grizzly 2.0 you can implement Filter's onAccept method to get  
notified, when new connection gets accepted. Please take a look at  
lifecycle filter implementation from this sample [1].

WBR,
Alexey.

[1] https://grizzly.dev.java.net/source/browse/grizzly/branches/2dot0/code/samples/framework-samples/src/main/java/com/sun/grizzly/samples/lifecycle/

On Oct 2, 2009, at 22:08 , 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.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
>
>
> --
> View this message in context: http://www.nabble.com/ServerSocket--%3E-Grizzly-Implementation---tp25721796p25721796.html
> Sent from the Grizzly - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...