35 |
obligated to do so. If you do not wish to do so, delete this |
obligated to do so. If you do not wish to do so, delete this |
36 |
exception statement from your version. */ |
exception statement from your version. */ |
37 |
|
|
|
|
|
38 |
package java.nio.channels.spi; |
package java.nio.channels.spi; |
39 |
|
|
40 |
import java.io.*; |
import java.io.IOException; |
41 |
import java.util.*; |
import java.nio.channels.SelectableChannel; |
42 |
import java.nio.channels.*; |
import java.nio.channels.ClosedChannelException; |
43 |
|
import java.util.List; |
44 |
|
|
45 |
public abstract class AbstractSelectableChannel extends SelectableChannel |
public abstract class AbstractSelectableChannel extends SelectableChannel |
46 |
{ |
{ |
47 |
int registered; |
int registered; |
48 |
boolean blocking = true; |
boolean blocking = true; |
49 |
Object LOCK = new Object(); |
Object LOCK = new Object(); |
50 |
SelectorProvider sprovider; |
SelectorProvider sprovider; |
54 |
protected abstract void implCloseSelectableChannel(); |
protected abstract void implCloseSelectableChannel(); |
55 |
protected abstract void implConfigureBlocking(boolean block); |
protected abstract void implConfigureBlocking(boolean block); |
56 |
|
|
57 |
|
public final Object blockingLock() |
|
public Object blockingLock() |
|
58 |
{ |
{ |
59 |
return LOCK; |
return LOCK; |
60 |
//Retrieves the object upon which the configureBlocking and register methods synchronize. |
//Retrieves the object upon which the configureBlocking and register methods synchronize. |
61 |
} |
} |
62 |
|
|
63 |
public SelectableChannel configureBlocking(boolean block) |
public final SelectableChannel configureBlocking(boolean block) |
64 |
{ |
{ |
65 |
synchronized(LOCK) |
synchronized(LOCK) |
66 |
{ |
{ |
71 |
return this; |
return this; |
72 |
} |
} |
73 |
|
|
74 |
protected void implCloseChannel() |
protected final void implCloseChannel() |
75 |
{ |
{ |
76 |
// Closes this channel. |
// Closes this channel. |
77 |
implCloseSelectableChannel(); |
implCloseSelectableChannel(); |
78 |
} |
} |
79 |
|
|
80 |
|
|
81 |
public boolean isBlocking() |
public final boolean isBlocking() |
82 |
{ |
{ |
83 |
return blocking; |
return blocking; |
84 |
//Tells whether or not every I/O operation on this channel will block until it completes. |
//Tells whether or not every I/O operation on this channel will block until it completes. |
85 |
} |
} |
86 |
|
|
87 |
|
|
88 |
public boolean isRegistered() |
public final boolean isRegistered() |
89 |
{ |
{ |
90 |
//Tells whether or not this channel is currently registered with any selectors. |
//Tells whether or not this channel is currently registered with any selectors. |
91 |
return registered > 0; |
return registered > 0; |
101 |
} |
} |
102 |
} |
} |
103 |
|
|
104 |
public SelectorProvider provider() |
public final SelectorProvider provider() |
105 |
{ |
{ |
106 |
// Returns the provider that created this channel. |
// Returns the provider that created this channel. |
107 |
return sprovider; |
return sprovider; |
132 |
keys.add(k); |
keys.add(k); |
133 |
} |
} |
134 |
|
|
135 |
public SelectionKey register(Selector selin, |
public final SelectionKey register(Selector selin, int ops, Object att) throws ClosedChannelException |
|
int ops, |
|
|
Object att) throws java.nio.channels.ClosedChannelException |
|
|
|
|
|
|
|
136 |
{ |
{ |
137 |
if (!isOpen()) |
if (!isOpen()) |
138 |
{ |
{ |