1/*
2 * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26/*
27 */
28
29package java.nio.channels;
30
31import java.io.IOException;
32
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 {@code instanceof} operator.
58 *
59 *
60 * @author Mark Reinhold
61 * @author JSR-51 Expert Group
62 * @since 1.4
63 */
64
65public interface InterruptibleChannel
66    extends Channel
67{
68
69    /**
70     * Closes this channel.
71     *
72     * <p> Any thread currently blocked in an I/O operation upon this channel
73     * will receive an {@link AsynchronousCloseException}.
74     *
75     * <p> This method otherwise behaves exactly as specified by the {@link
76     * Channel#close Channel} interface.  </p>
77     *
78     * @throws  IOException  If an I/O error occurs
79     */
80    public void close() throws IOException;
81
82}
83