40 |
import java.nio.channels.spi.AbstractInterruptibleChannel; |
import java.nio.channels.spi.AbstractInterruptibleChannel; |
41 |
import java.nio.channels.spi.SelectorProvider; |
import java.nio.channels.spi.SelectorProvider; |
42 |
|
|
43 |
|
/** |
44 |
|
* @author Michael Koch |
45 |
|
* @since 1.4 |
46 |
|
*/ |
47 |
public abstract class SelectableChannel |
public abstract class SelectableChannel |
48 |
extends AbstractInterruptibleChannel |
extends AbstractInterruptibleChannel |
49 |
{ |
{ |
50 |
protected SelectableChannel() |
/** |
51 |
|
* Initializes the channel. |
52 |
|
*/ |
53 |
|
protected SelectableChannel () |
54 |
{ |
{ |
55 |
} |
} |
56 |
|
|
57 |
public abstract Object blockingLock(); |
/** |
58 |
|
* Returns the lock of this channel. |
59 |
|
*/ |
60 |
|
public abstract Object blockingLock (); |
61 |
|
|
62 |
public abstract SelectableChannel configureBlocking(boolean block); |
/** |
63 |
|
* Adjusts this channel's blocking mode. |
64 |
public abstract boolean isBlocking(); |
* |
65 |
|
* @exception ClosedChannelException If this channel is closed. |
66 |
public abstract boolean isRegistered(); |
* @exception IllegalBlockingModeException If block is true and this channel |
67 |
|
* is registered with one or more selectors. |
68 |
public abstract SelectionKey keyFor(Selector sel); |
* @exception IOException If an error occurs. |
69 |
|
*/ |
70 |
public abstract SelectorProvider provider(); |
public abstract SelectableChannel configureBlocking (boolean block); |
71 |
|
|
72 |
public final SelectionKey register(Selector sel, int ops) |
/** |
73 |
|
* Tells whether this channel is blocking or not. |
74 |
|
*/ |
75 |
|
public abstract boolean isBlocking (); |
76 |
|
|
77 |
|
/** |
78 |
|
* Tells whether or not this channel is currently registered with |
79 |
|
* any selectors. |
80 |
|
*/ |
81 |
|
public abstract boolean isRegistered (); |
82 |
|
|
83 |
|
/** |
84 |
|
* Retrieves the key representing the channel's registration with |
85 |
|
* the given selector. |
86 |
|
*/ |
87 |
|
public abstract SelectionKey keyFor (Selector sel); |
88 |
|
|
89 |
|
/** |
90 |
|
* Returns the provider that created this channel. |
91 |
|
*/ |
92 |
|
public abstract SelectorProvider provider (); |
93 |
|
|
94 |
|
/** |
95 |
|
* Registers this channel with the given selector, |
96 |
|
* returning a selection key. |
97 |
|
* |
98 |
|
* @exception CancelledKeyException If this channel is currently registered |
99 |
|
* with the given selector but the corresponding key has already been cancelled |
100 |
|
* @exception ClosedChannelException If this channel is closed. |
101 |
|
* @exception IllegalArgumentException If a bit in ops does not correspond |
102 |
|
* to an operation that is supported by this channel, that is, if |
103 |
|
* set & ~validOps() != 0. |
104 |
|
* @exception IllegalBlockingModeException If block is true and this channel |
105 |
|
* is registered with one or more selectors. |
106 |
|
* @exception IllegalSelectorException If this channel was not created by |
107 |
|
* the same provider as the given selector. |
108 |
|
*/ |
109 |
|
public final SelectionKey register (Selector sel, int ops) |
110 |
throws ClosedChannelException |
throws ClosedChannelException |
111 |
{ |
{ |
112 |
return register(sel, ops, null); |
return register (sel, ops, null); |
113 |
} |
} |
114 |
|
|
115 |
public abstract SelectionKey register(Selector sel, int ops, Object att) |
/** |
116 |
|
* Registers this channel with the given selector, |
117 |
|
* returning a selection key. |
118 |
|
* |
119 |
|
* @exception CancelledKeyException If this channel is currently registered |
120 |
|
* with the given selector but the corresponding key has already been |
121 |
|
* cancelled. |
122 |
|
* @exception ClosedChannelException If this channel is closed. |
123 |
|
* @exception IllegalArgumentException If a bit in ops does not correspond |
124 |
|
* to an operation that is supported by this channel, that is, if |
125 |
|
* set & ~validOps() != 0. |
126 |
|
* @exception IllegalBlockingModeException If block is true and this channel |
127 |
|
* is registered with one or more selectors. |
128 |
|
* @exception IllegalSelectorException If this channel was not created by |
129 |
|
* the same provider as the given selector. |
130 |
|
*/ |
131 |
|
public abstract SelectionKey register (Selector sel, int ops, Object att) |
132 |
throws ClosedChannelException; |
throws ClosedChannelException; |
133 |
|
|
134 |
public abstract int validOps(); |
/** |
135 |
|
* Returns a set of valid operations on this channel. |
136 |
|
*/ |
137 |
|
public abstract int validOps(); |
138 |
} |
} |