37 |
|
|
38 |
package java.nio.channels; |
package java.nio.channels; |
39 |
|
|
40 |
import java.util.Set; |
import java.io.IOException; |
41 |
import java.nio.channels.spi.SelectorProvider; |
import java.nio.channels.spi.SelectorProvider; |
42 |
|
import java.util.Set; |
43 |
|
|
44 |
|
/** |
45 |
|
* @author Michael Koch |
46 |
|
* @since 1.4 |
47 |
|
*/ |
48 |
public abstract class Selector |
public abstract class Selector |
49 |
{ |
{ |
50 |
|
/** |
51 |
|
* Initializes the selector. |
52 |
|
*/ |
53 |
protected Selector() |
protected Selector() |
54 |
{ |
{ |
55 |
} |
} |
56 |
|
|
57 |
public static Selector open() |
/** |
58 |
|
* Opens a selector. |
59 |
|
* |
60 |
|
* @exception IOException If an error occurs |
61 |
|
*/ |
62 |
|
public static Selector open () |
63 |
{ |
{ |
64 |
return SelectorProvider.provider().openSelector(); |
return SelectorProvider.provider ().openSelector (); |
65 |
} |
} |
66 |
|
|
67 |
public abstract void close(); |
/** |
68 |
|
* Closes the selector. |
69 |
public abstract boolean isOpen(); |
* |
70 |
|
* @exception IOException If an error occurs |
71 |
public abstract Set keys(); |
*/ |
72 |
|
public abstract void close () throws IOException; |
73 |
public abstract SelectorProvider provider(); |
|
74 |
|
/** |
75 |
public abstract int select(); |
* Tells whether the selector is open or not. |
76 |
|
*/ |
77 |
public abstract int select(long timeout); |
public abstract boolean isOpen (); |
78 |
|
|
79 |
public abstract Set selectedKeys(); |
/** |
80 |
|
* Returns this selector's key set. |
81 |
public abstract int selectNow(); |
* |
82 |
|
* @exception ClosedSelectorException If this selector is closed. |
83 |
public abstract Selector wakeup(); |
*/ |
84 |
|
public abstract Set keys (); |
85 |
|
|
86 |
|
/** |
87 |
|
* Returns the SelectorProvider that created the selector. |
88 |
|
*/ |
89 |
|
public abstract SelectorProvider provider (); |
90 |
|
|
91 |
|
/** |
92 |
|
* Selects a set of keys whose corresponding channels are ready |
93 |
|
* for I/O operations. |
94 |
|
* |
95 |
|
* @exception ClosedSelectorException If this selector is closed. |
96 |
|
* @exception IOException If an error occurs |
97 |
|
*/ |
98 |
|
public abstract int select () throws IOException; |
99 |
|
|
100 |
|
/** |
101 |
|
* Selects a set of keys whose corresponding channels are ready |
102 |
|
* for I/O operations. |
103 |
|
* |
104 |
|
* @param timeout The timeout to use. |
105 |
|
* |
106 |
|
* @exception ClosedSelectorException If this selector is closed. |
107 |
|
* @exception IllegalArgumentException If the timeout value is negative. |
108 |
|
* @exception IOException If an error occurs |
109 |
|
*/ |
110 |
|
public abstract int select (long timeout) throws IOException; |
111 |
|
|
112 |
|
/** |
113 |
|
* Returns this selector's selected-key set. |
114 |
|
* |
115 |
|
* @exception ClosedSelectorException If this selector is closed. |
116 |
|
*/ |
117 |
|
public abstract Set selectedKeys (); |
118 |
|
|
119 |
|
/** |
120 |
|
* Selects a set of keys whose corresponding channels are ready |
121 |
|
* for I/O operations. |
122 |
|
* |
123 |
|
* @exception ClosedSelectorException If this selector is closed. |
124 |
|
* @exception IOException If an error occurs |
125 |
|
*/ |
126 |
|
public abstract int selectNow () throws IOException; |
127 |
|
|
128 |
|
/** |
129 |
|
* Causes the first selection operation that has not yet returned to |
130 |
|
* return immediately. |
131 |
|
*/ |
132 |
|
public abstract Selector wakeup (); |
133 |
} |
} |