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

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

Java 8 SelectionKey examples from Open Source projects
This code example shows how to use the following methods: attachment, interestOps, isValid, isWritable
46:	if (sk.isValid() && sk.isWritable()) { 
-
48:	sk.interestOps(sk.interestOps() & ~SelectionKey.OP_WRITE); 
49:	SelectionHandler handler = (SelectionHandler) sk.attachment(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: interestOps, isReadable, isValid, isWritable, readyOps
56:	assertTrue(key.isValid()); 
57:	assertFalse(key.isReadable()); 
58:	assertEquals(0,key.readyOps()); 
-
64:	assertTrue(key.isValid()); 
65:	assertFalse(key.isReadable()); 
66:	assertEquals(0,key.readyOps()); 
-
76:	assertTrue(key.isValid()); 
77:	assertTrue(key.isReadable()); 
78:	assertEquals(1,key.readyOps()); 
-
84:	assertTrue(key.isValid()); 
85:	assertTrue(key.isReadable()); 
86:	assertEquals(1,key.readyOps()); 
-
97:	assertTrue(key.isValid()); 
98:	assertTrue(key.isReadable()); 
99:	assertEquals(1,key.readyOps()); 
-
105:	assertTrue(key.isValid()); 
106:	assertTrue(key.isReadable()); 
107:	assertEquals(1,key.readyOps()); 
-
113:	assertTrue(key.isValid()); 
114:	assertTrue(key.isReadable()); 
115:	assertEquals(1,key.readyOps()); 
-
121:	assertTrue(key.isValid()); 
122:	assertTrue(key.isReadable()); 
123:	assertEquals(1,key.readyOps()); 
-
126:	key.interestOps(SelectionKey.OP_READ|SelectionKey.OP_WRITE); 
-
130:	assertTrue(key.isValid()); 
131:	assertTrue(key.isWritable()); 
132:	assertFalse(key.isReadable()); 
133:	assertEquals(SelectionKey.OP_WRITE,key.readyOps()); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: attach, attachment, cancel, channel, interestOps
132:	return (SocketChannel) key.channel(); 
-
136:	SocketChannel channel = (SocketChannel) key.channel(); 
-
142:	key.attach(null); 
143:	key.cancel(); 
-
163:	if (key.attachment() == null) { 
-
165:	key.attach(request); 
-
167:	request = (Receive) key.attachment(); 
-
183:	key.interestOps(SelectionKey.OP_READ); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: attachment, isReadable, isValid
46:	if (sk.isValid() && sk.isReadable()) { 
-
48:	SelectionHandler handler = (SelectionHandler) sk.attachment(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: interestOps, isConnectable, isReadable, isValid, isWritable
84:	int ops = key.readyOps(); 
85:	key.interestOps(key.interestOps() & ~ops); 
-
88:	if ( !key.isValid() ) throw new IOException("Key is not valid, it must have been cancelled."); 
89:	if ( key.isConnectable() ) { 
-
92:	if ( current != null ) key.interestOps(key.interestOps() | SelectionKey.OP_WRITE); 
-
96:	key.interestOps(key.interestOps() | SelectionKey.OP_CONNECT); 
-
99:	} else if ( key.isWritable() ) { 
-
105:	key.interestOps(key.interestOps() | SelectionKey.OP_READ); 
-
116:	key.interestOps(key.interestOps()|SelectionKey.OP_WRITE); 
-
118:	} else if ( key.isReadable() ) { 
-
124:	key.interestOps(key.interestOps() | SelectionKey.OP_READ); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: attach, cancel, interestOps, isConnectable, isValid
140:	key.interestOps(SelectionKey.OP_WRITE); 
-
155:	if (!key.isValid()) { 
156:	key.cancel(); 
-
186:	key.cancel(); 
187:	key.attach(null); 
-
251:	if (!key.isConnectable() || !transport.finishConnect()) { 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: cancel, interestOps, isValid, selector, SelectionKey.interestOps
500:	if (this.selectionKey.isValid()) { 
-
504:	this.selectionKey.cancel(); 
-
513:	.interestOps()) 
-
519:	this.selectionKey.interestOps(getInterestOperations()); 
-
525:	this.selectionKey = register(this.selectionKey.selector()); 
-
531:	this.selectionKey = register(this.selectionKey.selector()); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: cancel, interestOps, isConnectable, isReadable, isValid
200:	if (!key.isValid()) { 
-
202:	key.cancel(); 
-
207:	boolean connectable = key.isConnectable(); 
208:	boolean readable = key.isReadable(); 
209:	boolean writable = key.isWritable(); 
-
213:	key.cancel(); 
-
221:	key.interestOps(getInterestOps()); 
-
223:	key.cancel(); //XXX is this ok? 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: cancel, channel, isAcceptable, isConnectable, isReadable
173:	if (selKey.isValid() && selKey.isAcceptable()) { 
-
175:	ServerSocketChannel ssChannel = (ServerSocketChannel) selKey.channel(); 
-
194:	if (selKey.isValid() && selKey.isConnectable()) { 
-
196:	SocketChannel sChannel = (SocketChannel) selKey.channel(); 
-
199:	selKey.cancel(); 
-
207:	selKey.cancel(); 
-
212:	selKey.cancel(); 
-
218:	if (selKey.isValid() && selKey.isReadable()) { 
219:	SocketChannel sChannel = (SocketChannel) selKey.channel(); 
-
225:	selKey.cancel(); 
-
231:	if (selKey.isValid() && selKey.isWritable()) { 
232:	SocketChannel sChannel = (SocketChannel) selKey.channel(); 
-
238:	selKey.cancel(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: cancel, channel
58:	session.setKey(key); 
-
61:	SocketChannel channel = (SocketChannel) key.channel(); 
-
70:	key.cancel(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: cancel, channel
73:	if (((ReadableByteChannel)key.channel()).read(readBuffer) == -1) 
-
86:	closeAfterWrite = writePb(key); 
-
89:	key.channel().close(); 
90:	key.cancel(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: attachment, channel
501:	Connection connection = (Connection)key.attachment(); 
-
506:	int count = ((SocketChannel)key.channel()).read(buf); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: channel, isAcceptable, isReadable
82:	if (key.isAcceptable()) { 
83:	ServerSocketChannel server = (ServerSocketChannel) key.channel(); 
-
90:	} else if (key.isReadable()) { 
-
97:	SocketChannel sc = (SocketChannel)key.channel(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: interestOps, isReadable, isValid, isWritable, readyOps
23:	if (selectionKey.isValid()) { 
24:	if (selectionKey.isReadable() || selectionKey.isWritable()) { 
-
26:	.setInterestOps(selectionKey, (selectionKey 
27:	.interestOps() & (~selectionKey.readyOps()))); 
-
29:	attachment)); 
-
32:	attachment.cancelledKey(kuraokami, selectionKey); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: cancel, channel
71:	session.setKey(key); 
72:	SocketChannel channel = (SocketChannel) key.channel(); 
-
81:	key.cancel(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: interestOps, isValid, readyOps
305:	boolean valid = _key != null && _key.isValid(); 
306:	int keyInterests = valid ? _key.interestOps() : -1; 
307:	int keyReadiness = valid ? _key.readyOps() : -1; 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: attachment, channel
89:	SocketChannel channel = ((SocketChannel) key.channel()); 
-
91:	if (key.attachment() instanceof MappedByteBuffer) { 
-
93:	} else if (key.attachment() instanceof DynamicByteBuffer) { 
-
103:	MappedByteBuffer mbb = (MappedByteBuffer) key.attachment(); 
-
118:	DynamicByteBuffer dbb = (DynamicByteBuffer) key.attachment(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: channel, selector
57:	key.selector().close(); 
58:	key.channel().close(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: attachment, interestOps, isAcceptable, isConnectable, isReadable
269:	s = "Att: " + (sk.attachment() == null ? "no" : "yes"); 
270:	s += ", Read: " + sk.isReadable(); 
271:	s += ", Acpt: " + sk.isAcceptable(); 
272:	s += ", Cnct: " + sk.isConnectable(); 
273:	s += ", Wrt: " + sk.isWritable(); 
274:	s += ", Valid: " + sk.isValid(); 
275:	s += ", Ops: " + sk.interestOps(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: cancel
30:	writeSelectionKey.cancel(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: attach, attachment
37:	ChannelProcessor channelProcessor = (ChannelProcessor) key.attachment(); 
-
39:	((ClearableChannelProcessor) channelProcessor).clear(key); 
-
45:	key.attach(processor); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: interestOps
375:	sk.interestOps(iops); 
Full Snippet Info
5
CodeRank
This code example shows how to use the following methods: cancel
55:	sk.cancel(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: interestOps, isConnectable, isReadable, isValid, isWritable
85:	int ops = key.readyOps(); 
86:	key.interestOps(key.interestOps() & ~ops); 
-
89:	if ( !key.isValid() ) throw new IOException("Key is not valid, it must have been cancelled."); 
90:	if ( key.isConnectable() ) { 
-
93:	if ( current != null ) key.interestOps(key.interestOps() | SelectionKey.OP_WRITE); 
-
97:	key.interestOps(key.interestOps() | SelectionKey.OP_CONNECT); 
-
100:	} else if ( key.isWritable() ) { 
-
106:	key.interestOps(key.interestOps() | SelectionKey.OP_READ); 
-
117:	key.interestOps(key.interestOps()|SelectionKey.OP_WRITE); 
-
119:	} else if ( key.isReadable() ) { 
-
125:	key.interestOps(key.interestOps() | SelectionKey.OP_READ); 
Full Snippet Info
5
CodeRank
This code example shows how to use the following methods: attachment, isAcceptable, isReadable, isWritable
53:	if (key.isAcceptable()) { 
-
62:	Session client = (Session)key.attachment(); 
-
64:	if (key.isReadable()) { 
-
67:	if (key.isWritable()) { 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: cancel
52:	sk.cancel(); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: attach, interestOps, isValid
330:	} else if (key.isValid() == false) { 
-
333:	key.interestOps(key.interestOps() | opCode); 
-
335:	key.attach(Pipe.this); 
Full Snippet Info
5
CodeRank
This code example shows how to use the following methods: attach, attachment, cancel, channel
319:	key.attach(cancel); 
320:	key.cancel(); 
-
463:	Runnable task = (Runnable) key.attachment(); 
464:	Channel channel = key.channel(); 
-
467:	this.table.put(channel, key); 
Full Snippet Info
5
CodeRank
This code example shows how to use the following methods: hashCode, attachment, interestOps
495:	_dumps.add(String.format("SelectionKey@%x{i=%d}->%s", key.hashCode(), key.interestOps(), key.attachment())); 
Full Snippet Info
5
CodeRank
This code example shows how to use the following methods: channel, isAcceptable, isValid
55:	if (key.isValid() && key.isAcceptable()) 
-
57:	return (ServerSocketChannel) key.channel(); 
Full Snippet Info
5
CodeRank
This code example shows how to use the following methods: cancel
413:	selectionKey_.cancel(); 
Full Snippet Info
5
CodeRank
This code example shows how to use the following methods: attach, cancel
27:	clientKey.attach(new ClientHandler()); 
-
30:	clientKey.cancel(); 
Full Snippet Info
5
CodeRank
This code example shows how to use the following methods: attachment, channel
496:	Connection connection = (Connection)key.attachment(); 
-
501:	int count = ((SocketChannel)key.channel()).read(buf); 
Full Snippet Info
5
CodeRank
This code example shows how to use the following methods: channel, interestOps
37:	SocketChannel channel = (SocketChannel) key.channel(); 
-
39:	int read = Helper.read(key, getInBuffer()); 
-
42:	key.interestOps(OP_WRITE); 
43:	Helper.write(key, ByteBuffer.allocate(0)); 
-
47:	Helper.write(key, ByteBuffer.allocate(0)); 
Full Snippet Info
5
CodeRank
This code example shows how to use the following methods: channel, isAcceptable, isValid
307:	if ( key.isValid() && key.isAcceptable() ) { 
308:	return (ServerSocketChannel) key.channel(); 
Full Snippet Info
5
CodeRank
This code example shows how to use the following methods: interestOps
46:	sk.interestOps(SelectionKey.OP_WRITE | sk.interestOps()); 
Full Snippet Info
5
CodeRank
This code example shows how to use the following methods: attach, channel
45:	sourceKey.attach(sourceConduit); 
46:	sourceChannel = (Pipe.SourceChannel) sourceKey.channel(); 
Full Snippet Info
5
CodeRank
This code example shows how to use the following methods: channel, isValid
117:	assertTrue(acceptKey.isValid()); 
118:	assertSame(sc, acceptKey.channel()); 
Full Snippet Info
5
CodeRank
This code example shows how to use the following methods: channel
101:	ServerSocketChannel serverSocketChannel = (ServerSocketChannel) key.channel(); 
Full Snippet Info
5
CodeRank
This code example shows how to use the following methods: attach
156:	IOSession session = getSession(key); 
-
164:	key.attach(null); 
Full Snippet Info
5
CodeRank
This code example shows how to use the following methods: isConnectable
55:	selector.selectedKeys().remove(channelKey); 
-
58:	if (!channelKey.isConnectable()) { 
Full Snippet Info
5
CodeRank
Related Java 8 SelectionKey Questions & Answers:
See Code Examples for Java 8 SelectionKey Methods: