41 |
import java.nio.channels.Channel; |
import java.nio.channels.Channel; |
42 |
import java.nio.channels.InterruptibleChannel; |
import java.nio.channels.InterruptibleChannel; |
43 |
|
|
44 |
|
/** |
45 |
|
* @author Michael Koch |
46 |
|
* @since 1.4 |
47 |
|
*/ |
48 |
public abstract class AbstractInterruptibleChannel |
public abstract class AbstractInterruptibleChannel |
49 |
implements Channel, InterruptibleChannel |
implements Channel, InterruptibleChannel |
50 |
{ |
{ |
51 |
boolean opened = false; |
boolean opened = true; |
52 |
|
|
53 |
protected AbstractInterruptibleChannel() |
/** |
54 |
|
* Initializes the channel. |
55 |
|
*/ |
56 |
|
protected AbstractInterruptibleChannel () |
57 |
{ |
{ |
58 |
} |
} |
59 |
|
|
60 |
protected final void begin() |
/** |
61 |
|
* Marks the beginning of an I/O operation that might block indefinitely. |
62 |
|
*/ |
63 |
|
protected final void begin () |
64 |
{ |
{ |
|
// Marks the beginning of an I/O operation that might block indefinitely. |
|
65 |
} |
} |
66 |
|
|
67 |
public final void close() throws IOException |
/** |
68 |
|
* Closes the channel. |
69 |
|
* |
70 |
|
* @exception IOException If an error occurs |
71 |
|
*/ |
72 |
|
public final void close () throws IOException |
73 |
{ |
{ |
74 |
// Closes this channel. |
opened = false; |
75 |
implCloseChannel(); |
implCloseChannel (); |
76 |
} |
} |
77 |
|
|
78 |
protected final void end(boolean completed) |
/** |
79 |
|
* Marks the end of an I/O operation that might block indefinitely. |
80 |
|
* |
81 |
|
* @exception AsynchronousCloseException If the channel was asynchronously |
82 |
|
* closed. |
83 |
|
* @exception ClosedByInterruptException If the thread blocked in the |
84 |
|
* I/O operation was interrupted. |
85 |
|
*/ |
86 |
|
protected final void end (boolean completed) |
87 |
{ |
{ |
|
// Marks the end of an I/O operation that might block indefinitely. |
|
88 |
} |
} |
89 |
|
|
90 |
protected abstract void implCloseChannel() throws IOException; |
/** |
91 |
|
* Closes the channel. |
92 |
public final boolean isOpen() |
* |
93 |
|
* @exception IOException If an error occurs |
94 |
|
*/ |
95 |
|
protected abstract void implCloseChannel () throws IOException; |
96 |
|
|
97 |
|
/** |
98 |
|
* Tells whether or not this channel is open. |
99 |
|
*/ |
100 |
|
public final boolean isOpen () |
101 |
{ |
{ |
|
// Tells whether or not this channel is open. |
|
102 |
return opened; |
return opened; |
103 |
} |
} |
104 |
} |
} |
|
|
|