Java 8 Selector - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Selector class.

This code example shows how to use the following methods:close, isOpen, provider
 
public class SystemUtilsUniTest extends TestCase {
	public void testOpenSelector() throws IOException {
		Selector selector = SystemUtils.openSelector();
		assertNotNull(selector);
		assertTrue(selector.isOpen());
		if (SystemUtils.isLinuxPlatform()) { 
			final String pollClassName = selector.provider().getClass()
					.getCanonicalName();
			assertTrue(pollClassName.equals("sun.nio.ch.EPollSelectorProvider")
					|| pollClassName.equals("sun.nio.ch.PollSelectorProvider"));
		} 
		Selector selector2 = SystemUtils.openSelector();
		; 
		assertNotSame(selector, selector2);
		selector.close();
		selector2.close();
	} 
 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:select, selectedKeys
            } 
            else if (timeout < 0) {
                rc = selector.select(0);
            } 
            else { 
                rc = selector.select(timeout);
            } 
        } 
        catch (IOException e) {
            throw new ZError.IOException(e);
        } 
 
        if (rc == 0) {
            return false; 
        } 
 
        selector.selectedKeys().clear();
 
        return true; 
    } 

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close
    /* ------------------------------------------------------------------------------- */ 
    public void destroy() 
    { 
        if (_selector!=null)
        { 
            try{_selector.close();}
            catch(IOException e){ LogSupport.ignore(log,e);}
            _selector=null;
            _buffer=null;
            _flush=null;
            _channel=null;
        } 
    } 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close, isOpen, provider
public class SystemUtilsUniTest { 
    @Test
    public void testOpenSelector() throws IOException {
        Selector selector = SystemUtils.openSelector();
        assertNotNull(selector);
        assertTrue(selector.isOpen());
        if (SystemUtils.isLinuxPlatform()) { 
            assertEquals(selector.provider().getClass().getCanonicalName(), "sun.nio.ch.EPollSelectorProvider");
        } 
        Selector selector2 = SystemUtils.openSelector();
        assertNotSame(selector, selector2);
        selector.close();
        selector2.close();
    } 
 
 
    @Test
    public void testSystemThreadCount() { 
        int cpus = Runtime.getRuntime().availableProcessors();
        int n = SystemUtils.getSystemThreadCount();
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:sleep, close, wakeup
        // start thread to block in Selector 
        Thread t = new Thread(r);
        t.start();
 
        // give thread time to start 
        Thread.sleep(1000);
 
        // interrupt, close, and wakeup is the magic sequence to provoke the NPE 
        t.interrupt();
        sel.close();
        sel.wakeup();
    } 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:select, selectNow, selectedKeys
This code example shows how to use the following methods:close
        ch.close();
    } 
 
    private static void closeSelector(String selectorName, Selector selector) {
        try { 
            selector.close();
        } catch (IOException e) {
            logger.warn("Failed to close a " + selectorName + " selector.", e);
        } 
    } 
 
    @Override 
    public ChannelFuture bindAddress(InetAddress localAddress) {
        return bindAddress(localAddress, newPromise());
    } 
 
    @Override 
    public ChannelFuture bindAddress(final InetAddress localAddress, final ChannelPromise promise) {
        if (eventLoop().inEventLoop()) { 
            try { 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close, isOpen
 
        return bb.remaining();
    } 
 
    public void close() throws IOException {
        if (rs.isOpen()) {
            rs.close();
 
            if (sc.isOpen()) {
                sc.socket().shutdownInput();
                sc.socket().close();
            } 
 
            bb = null;
            sc = null;
        } 
    } 
 
    public int read() throws IOException {
        if (!rs.isOpen())
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:isOpen
		} 
	} 
 
	@Override 
	protected final IoSession bind0(Set<SocketAddress> localAddresses) {
		if (serverSocketChannel.isOpen() && selector.isOpen()) {
			try { 
				serverSocketChannel.bind(localAddresses.iterator().next());
				if (serverSocketChannel.isOpen() && selector.isOpen()) {
					serverSocketChannel.configureBlocking(false);
					serverSocketChannel.register(selector,
							SelectionKey.OP_ACCEPT);
				} 
				// 
				init(); 
			} catch (IOException e) {
				e.printStackTrace();
			} catch (Exception e) {
				e.printStackTrace();
			} 

5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:isOpen, wakeup
        } 
    } 
     
    public synchronized void stopPumping() { 
        _alive = false;
        if (_selector != null && _selector.isOpen())
            _selector.wakeup();
    } 
     
    /** 
     *  Selector can take quite a while to close after calling stopPumping() 
     */ 
    public boolean isAlive() { 
        return _alive || (_selector != null && _selector.isOpen());
    } 
 
    /** 
     *  Register the acceptor. 
     *  This is only called from NTCPTransport.bindAddress(), so it isn't clear 
     *  why this needs a queue.  
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Java 8 Selector Questions & Answers:

See Code Examples for Java 8 Selector Methods: