Examples of ListeningIOReactor


Examples of org.apache.http.nio.reactor.ListeningIOReactor

       
        final IOEventDispatch eventDispatch = new DefaultServerIOEventDispatch(
                serviceHandler,
                params);
       
        final ListeningIOReactor ioreactor = new DefaultListeningIOReactor(1, params);
       
        Thread t = new Thread(new Runnable() {
           
            public void run() {
                try {
                    ioreactor.execute(eventDispatch);
                } catch (IOException ex) {
                }
            }
           
        });
       
        t.start();
       
        Set<ListenerEndpoint> endpoints = ioreactor.getEndpoints();
        assertNotNull(endpoints);
        assertEquals(0, endpoints.size());
       
        ListenerEndpoint port9998 = ioreactor.listen(new InetSocketAddress(9998));
        port9998.waitFor();

        ListenerEndpoint port9999 = ioreactor.listen(new InetSocketAddress(9999));
        port9999.waitFor();

        endpoints = ioreactor.getEndpoints();
        assertNotNull(endpoints);
        assertEquals(2, endpoints.size());
       
        port9998.close();

        endpoints = ioreactor.getEndpoints();
        assertNotNull(endpoints);
        assertEquals(1, endpoints.size());
       
        ListenerEndpoint endpoint = endpoints.iterator().next();
       
        assertEquals(9999, ((InetSocketAddress) endpoint.getAddress()).getPort());
       
        ioreactor.shutdown(1000);
        t.join(1000);
       
        assertEquals(IOReactorStatus.SHUT_DOWN, ioreactor.getStatus());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.