< prev index next >

src/java.base/share/classes/java/nio/channels/spi/AbstractInterruptibleChannel.java

Print this page




  28 
  29 package java.nio.channels.spi;
  30 
  31 import java.io.IOException;
  32 import java.nio.channels.*;
  33 import jdk.internal.misc.SharedSecrets;
  34 import sun.nio.ch.Interruptible;
  35 
  36 
  37 /**
  38  * Base implementation class for interruptible channels.
  39  *
  40  * <p> This class encapsulates the low-level machinery required to implement
  41  * the asynchronous closing and interruption of channels.  A concrete channel
  42  * class must invoke the {@link #begin begin} and {@link #end end} methods
  43  * before and after, respectively, invoking an I/O operation that might block
  44  * indefinitely.  In order to ensure that the {@link #end end} method is always
  45  * invoked, these methods should be used within a
  46  * {@code try}&nbsp;...&nbsp;{@code finally} block:
  47  *
  48  * <blockquote><pre>
  49  * boolean completed = false;
  50  * try {
  51  *     begin();
  52  *     completed = ...;    // Perform blocking I/O operation
  53  *     return ...;         // Return result
  54  * } finally {
  55  *     end(completed);
  56  * }</pre></blockquote>
  57  *
  58  * <p> The {@code completed} argument to the {@link #end end} method tells
  59  * whether or not the I/O operation actually completed, that is, whether it had
  60  * any effect that would be visible to the invoker.  In the case of an
  61  * operation that reads bytes, for example, this argument should be
  62  * {@code true} if, and only if, some bytes were actually transferred into the
  63  * invoker's target buffer.
  64  *
  65  * <p> A concrete channel class must also implement the {@link
  66  * #implCloseChannel implCloseChannel} method in such a way that if it is
  67  * invoked while another thread is blocked in a native I/O operation upon the
  68  * channel then that operation will immediately return, either by throwing an




  28 
  29 package java.nio.channels.spi;
  30 
  31 import java.io.IOException;
  32 import java.nio.channels.*;
  33 import jdk.internal.misc.SharedSecrets;
  34 import sun.nio.ch.Interruptible;
  35 
  36 
  37 /**
  38  * Base implementation class for interruptible channels.
  39  *
  40  * <p> This class encapsulates the low-level machinery required to implement
  41  * the asynchronous closing and interruption of channels.  A concrete channel
  42  * class must invoke the {@link #begin begin} and {@link #end end} methods
  43  * before and after, respectively, invoking an I/O operation that might block
  44  * indefinitely.  In order to ensure that the {@link #end end} method is always
  45  * invoked, these methods should be used within a
  46  * {@code try}&nbsp;...&nbsp;{@code finally} block:
  47  *
  48  * <blockquote><pre id="be">
  49  * boolean completed = false;
  50  * try {
  51  *     begin();
  52  *     completed = ...;    // Perform blocking I/O operation
  53  *     return ...;         // Return result
  54  * } finally {
  55  *     end(completed);
  56  * }</pre></blockquote>
  57  *
  58  * <p> The {@code completed} argument to the {@link #end end} method tells
  59  * whether or not the I/O operation actually completed, that is, whether it had
  60  * any effect that would be visible to the invoker.  In the case of an
  61  * operation that reads bytes, for example, this argument should be
  62  * {@code true} if, and only if, some bytes were actually transferred into the
  63  * invoker's target buffer.
  64  *
  65  * <p> A concrete channel class must also implement the {@link
  66  * #implCloseChannel implCloseChannel} method in such a way that if it is
  67  * invoked while another thread is blocked in a native I/O operation upon the
  68  * channel then that operation will immediately return, either by throwing an


< prev index next >