Best code examples for Java 8 Selector class (java.nio.channels.Selector)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Selector class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Java 8 Selector examples from Open Source projects
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();
	} 
 
} 
Full Snippet Info
6
CodeRank
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
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;
        } 
    } 
} 
Full Snippet Info
6
CodeRank
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();
Full Snippet Info
6
CodeRank
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();
    } 
} 
Full Snippet Info
6
CodeRank
Related Java 8 Selector Questions & Answers:
See Code Examples for Java 8 Selector Methods: