< prev index next >

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

Print this page




  28 import java.io.IOException;
  29 import java.nio.channels.SelectionKey;
  30 import java.nio.channels.Selector;
  31 import java.util.HashSet;
  32 import java.util.Set;
  33 import sun.nio.ch.Interruptible;
  34 import java.util.concurrent.atomic.AtomicBoolean;
  35 
  36 
  37 /**
  38  * Base implementation class for selectors.
  39  *
  40  * <p> This class encapsulates the low-level machinery required to implement
  41  * the interruption of selection operations.  A concrete selector class must
  42  * invoke the {@link #begin begin} and {@link #end end} methods before and
  43  * 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  * try {
  50  *     begin();
  51  *     // Perform blocking I/O operation here
  52  *     ...
  53  * } finally {
  54  *     end();
  55  * }</pre></blockquote>
  56  *
  57  * <p> This class also defines methods for maintaining a selector's
  58  * cancelled-key set and for removing a key from its channel's key set, and
  59  * declares the abstract {@link #register register} method that is invoked by a
  60  * selectable channel's {@link AbstractSelectableChannel#register register}
  61  * method in order to perform the actual work of registering a channel.  </p>
  62  *
  63  *
  64  * @author Mark Reinhold
  65  * @author JSR-51 Expert Group
  66  * @since 1.4
  67  */
  68 




  28 import java.io.IOException;
  29 import java.nio.channels.SelectionKey;
  30 import java.nio.channels.Selector;
  31 import java.util.HashSet;
  32 import java.util.Set;
  33 import sun.nio.ch.Interruptible;
  34 import java.util.concurrent.atomic.AtomicBoolean;
  35 
  36 
  37 /**
  38  * Base implementation class for selectors.
  39  *
  40  * <p> This class encapsulates the low-level machinery required to implement
  41  * the interruption of selection operations.  A concrete selector class must
  42  * invoke the {@link #begin begin} and {@link #end end} methods before and
  43  * 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  * try {
  50  *     begin();
  51  *     // Perform blocking I/O operation here
  52  *     ...
  53  * } finally {
  54  *     end();
  55  * }</pre></blockquote>
  56  *
  57  * <p> This class also defines methods for maintaining a selector's
  58  * cancelled-key set and for removing a key from its channel's key set, and
  59  * declares the abstract {@link #register register} method that is invoked by a
  60  * selectable channel's {@link AbstractSelectableChannel#register register}
  61  * method in order to perform the actual work of registering a channel.  </p>
  62  *
  63  *
  64  * @author Mark Reinhold
  65  * @author JSR-51 Expert Group
  66  * @since 1.4
  67  */
  68 


< prev index next >