01: /* Licensed to the Apache Software Foundation (ASF) under one or more
02: * contributor license agreements. See the NOTICE file distributed with
03: * this work for additional information regarding copyright ownership.
04: * The ASF licenses this file to You under the Apache License, Version 2.0
05: * (the "License"); you may not use this file except in compliance with
06: * the License. You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package java.nio.channels;
18:
19: import java.io.Closeable;
20: import java.io.IOException;
21:
22: /**
23: * A channel is a conduit to IO services covering such items as files, sockets,
24: * hardware devices, IO ports, or some software component.
25: * <p>
26: * Channels are open upon creation, and can be explicitly closed. Once a channel
27: * is closed it cannot be re-opened, and attempts to perform IO operations on
28: * the closed channel result in a <code>ClosedChannelException
29: * </code>.
30: * </p>
31: * <p>
32: * Particular implementations or sub-interfaces of Channel dictate whether they
33: * are thread-safe or not.
34: * </p>
35: */
36: public interface Channel extends Closeable {
37:
38: /**
39: * Answers whether this channel is open or not.
40: *
41: * @return true if the channel is open, otherwise answers false.
42: */
43: public boolean isOpen();
44:
45: /**
46: * Closes an open channel.
47: *
48: * If the channel is already closed this method has no effect. If there is a
49: * problem with closing the channel then the method throws an IOException
50: * and the exception contains reasons for the failure.
51: * <p>
52: * If an attempt is made to perform an operation on a closed channel then a
53: * <code>ClosedChannelException</code> will be thrown on that attempt.
54: * </p>
55: * <p>
56: * If multiple threads attempts to simultaneously close a channel, then only
57: * one thread will run the closure code, and others will be blocked until
58: * the first returns.
59: * </p>
60: *
61: * @throws IOException
62: * if a problem occurs closing the channel.
63: */
64: public void close() throws IOException;
65: }
|