AbstractSelectableChannel keyFor - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for AbstractSelectableChannel keyFor method.

This code example shows how to use the following methods:write, close, keyFor
	} 
 
	private void closeSocketChannel() throws IOException { 
		if (socketChannel == null) return;
		try { 
			socketChannel.close();
		} finally { 
			socketChannel = null;
		} 
	} 
 
	private void closeSelector() throws IOException { 
		if (selector == null) return;
		try { 
			selector.close();
		} finally { 
			selector = null;
		} 
	} 
 

5
CodeRank
This code example shows how to use the following methods:keyFor
        socketChannel.close();
    } 
 
    @Override 
    public SelectionKey keyFor(Selector selector) {
        return socketChannel.keyFor(selector);
    } 
 
    @Override 
    public SelectionKey register(Selector selector, int ops, Object attachment) throws ClosedChannelException {
        return socketChannel.register(selector, ops, attachment);
    } 
 
    @Override 
    public String toString() {
        final StringBuilder sb = new StringBuilder("DefaultSocketChannelWrapper{");
        sb.append("socketChannel=").append(socketChannel);
        sb.append('}');
        return sb.toString();
    } 
5
CodeRank
This code example shows how to use the following methods:disconnect, close, keyFor
        key.interestOps(newInterestOps);
    } 
 
    @Override 
    protected void close(DatagramChannel handle) throws Exception {
        SelectionKey key = handle.keyFor(selector);
 
        if (key != null) {
            key.cancel();
        } 
         
        handle.disconnect();
        handle.close();
    } 
 
    @Override 
    protected void wakeup() { 
        selector.wakeup();
    } 
     
4
CodeRank
This code example shows how to use the following methods:disconnect, close, keyFor
        key.interestOps(newInterestOps);
    } 
 
    @Override 
    protected void close(DatagramChannel handle) throws Exception {
        SelectionKey key = handle.keyFor(selector);
 
        if (key != null) {
            key.cancel();
        } 
 
        handle.disconnect();
        handle.close();
    } 
 
    @Override 
    protected void wakeup() { 
        selector.wakeup();
    } 
} 
5
CodeRank
This code example shows how to use the following methods:keyFor
    public boolean isOpen() { 
            return channel.isOpen();
    } 
 
    public SelectionKey keyFor(Selector sel) {
            return channel.keyFor(sel);
    } 
 
    public int read(ByteBuffer dst) throws IOException, NotYetConnectedException {
            return channel.read(dst);
    } 
 
    public SelectionKey register(Selector sel, int ops, Object att)
                    throws ClosedChannelException {
            return channel.register(sel, ops, att);
    } 
 
    public Socket socket() {
            return channel.socket();
    } 
3
CodeRank
This code example shows how to use the following methods:close, keyFor
    /** 
     * {@inheritDoc} 
     */ 
    @Override 
    protected void close(SocketChannel handle) throws Exception {
        SelectionKey key = handle.keyFor(selector);
 
        if (key != null) {
            key.cancel();
        } 
 
        handle.close();
    } 
 
    /** 
     * {@inheritDoc} 
     */ 
    @Override 
    protected boolean finishConnect(SocketChannel handle) throws Exception {
        if (handle.finishConnect()) {
4
CodeRank
This code example shows how to use the following methods:close, keyFor
    /** 
     * {@inheritDoc} 
     */ 
    @Override 
    protected void close(ServerSocketChannel handle) throws Exception {
        SelectionKey key = handle.keyFor(selector);
 
        if (key != null) {
            key.cancel();
        } 
 
        handle.close();
    } 
 
    /** 
     * {@inheritDoc} 
     */ 
    @Override 
    protected void wakeup() { 
        selector.wakeup();
4
CodeRank
This code example shows how to use the following methods:keyFor
    public boolean isOpen() { 
            return channel.isOpen();
    } 
 
    public SelectionKey keyFor(Selector sel) {
            return channel.keyFor(sel);
    } 
 
    public int read(ByteBuffer dst) throws IOException {
            return channel.read(dst);
    } 
 
    public SelectionKey register(Selector sel, int ops, Object att)
                    throws ClosedChannelException { 
            return channel.register(sel, ops, att);
    } 
 
    public Socket socket() {
            return channel.socket();
    } 
4
CodeRank
This code example shows how to use the following methods:keyFor
    } 
 
    @Override 
    public void registerConnect(SocketChannel channel, Handler handler) {
        // Should not be registered 
        assert channel.keyFor(selector) == null;
        register(channel, SelectionKey.OP_CONNECT, handler);
    } 
 
    @Override 
    public void registerWrite(SelectableChannel channel, Handler handler) {
        addInterest(channel, SelectionKey.OP_WRITE, handler);
    } 
 
    @Override 
    public void registerTimer(int timerMilliseconds, Handler handler) {
        assert timerMilliseconds >= 0;
        assert handler != null; 
        long expirationMs = System.currentTimeMillis() + timerMilliseconds;
        timers.add(new Timer(expirationMs, handler));
3
CodeRank
keyFor Method Overview
Retrieves the key representing the channel's registration with the given selector.
See Code Examples for other Java 8 AbstractSelectableChannel Methods: