01 /*
02 * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
03 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04 *
05 * This code is free software; you can redistribute it and/or modify it
06 * under the terms of the GNU General Public License version 2 only, as
07 * published by the Free Software Foundation. Sun designates this
08 * particular file as subject to the "Classpath" exception as provided
09 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26 /*
27 * @(#)InterruptibleChannel.java 1.12 07/05/05
28 */
29
30 package java.nio.channels;
31
32 import java.io.IOException;
33
34 /**
35 * A channel that can be asynchronously closed and interrupted.
36 *
37 * <p> A channel that implements this interface is <i>asynchronously
38 * closeable:</i> If a thread is blocked in an I/O operation on an
39 * interruptible channel then another thread may invoke the channel's {@link
40 * #close close} method. This will cause the blocked thread to receive an
41 * {@link AsynchronousCloseException}.
42 *
43 * <p> A channel that implements this interface is also <i>interruptible:</i>
44 * If a thread is blocked in an I/O operation on an interruptible channel then
45 * another thread may invoke the blocked thread's {@link Thread#interrupt()
46 * interrupt} method. This will cause the channel to be closed, the blocked
47 * thread to receive a {@link ClosedByInterruptException}, and the blocked
48 * thread's interrupt status to be set.
49 *
50 * <p> If a thread's interrupt status is already set and it invokes a blocking
51 * I/O operation upon a channel then the channel will be closed and the thread
52 * will immediately receive a {@link ClosedByInterruptException}; its interrupt
53 * status will remain set.
54 *
55 * <p> A channel supports asynchronous closing and interruption if, and only
56 * if, it implements this interface. This can be tested at runtime, if
57 * necessary, via the <tt>instanceof</tt> operator.
58 *
59 *
60 * @author Mark Reinhold
61 * @author JSR-51 Expert Group
62 * @version 1.12, 07/05/05
63 * @since 1.4
64 */
65
66 public interface InterruptibleChannel extends Channel {
67
68 /**
69 * Closes this channel.
70 *
71 * <p> Any thread currently blocked in an I/O operation upon this channel
72 * will receive an {@link AsynchronousCloseException}.
73 *
74 * <p> This method otherwise behaves exactly as specified by the {@link
75 * Channel#close Channel} interface. </p>
76 *
77 * @throws IOException If an I/O error occurs
78 */
79 public void close() throws IOException;
80
81 }
|