< prev index next >

src/java.base/share/classes/sun/nio/ch/SelChImpl.java

Print this page




  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 package sun.nio.ch;
  27 
  28 import java.nio.channels.Channel;
  29 import java.io.FileDescriptor;
  30 import java.io.IOException;
  31 
  32 import static java.util.concurrent.TimeUnit.NANOSECONDS;
  33 


  34 /**
  35  * An interface that allows translation (and more!).
  36  *
  37  * @since 1.4
  38  */
  39 
  40 public interface SelChImpl extends Channel {
  41 
  42     FileDescriptor getFD();
  43 
  44     int getFDVal();
  45 
  46     /**
  47      * Adds the specified ops if present in interestOps. The specified
  48      * ops are turned on without affecting the other ops.
  49      *
  50      * @return  true iff the new value of sk.readyOps() set by this method
  51      *          contains at least one bit that the previous value did not
  52      *          contain
  53      */
  54     boolean translateAndUpdateReadyOps(int ops, SelectionKeyImpl ski);
  55 
  56     /**
  57      * Sets the specified ops if present in interestOps. The specified
  58      * ops are turned on, and all other ops are turned off.
  59      *
  60      * @return  true iff the new value of sk.readyOps() set by this method
  61      *          contains at least one bit that the previous value did not
  62      *          contain
  63      */
  64     boolean translateAndSetReadyOps(int ops, SelectionKeyImpl ski);
  65 
  66     /**
  67      * Translates an interest operation set into a native event set
  68      */
  69     int translateInterestOps(int ops);
  70 
  71     void kill() throws IOException;
  72 
  73     /**
  74      * Disables the current thread for scheduling purposes until this
  75      * channel is ready for I/O, or asynchronously closed, for up to the
  76      * specified waiting time.
  77      *
  78      * <p> This method does <em>not</em> report which of these caused the
  79      * method to return. Callers should re-check the conditions which caused
  80      * the thread to park.
  81      *
  82      * @param event the event to poll
  83      * @param nanos the timeout to wait; {@code <= 0} to wait indefinitely
  84      */
  85     default void park(int event, long nanos) throws IOException {
  86         long millis;
  87         if (nanos <= 0) {
  88             millis = -1;











  89         } else {
  90             millis = NANOSECONDS.toMillis(nanos);






  91         }
  92         Net.poll(getFD(), event, millis);
  93     }
  94 
  95     /**
  96      * Disables the current thread for scheduling purposes until this
  97      * channel is ready for I/O, or asynchronously closed.
  98      *
  99      * <p> This method does <em>not</em> report which of these caused the
 100      * method to return. Callers should re-check the conditions which caused
 101      * the thread to park.
 102      *
 103      * @param event the event to poll
 104      */
 105     default void park(int event) throws IOException {
 106         park(event, 0L);
 107     }
 108 
 109 }


  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 package sun.nio.ch;
  27 
  28 import java.nio.channels.Channel;
  29 import java.io.FileDescriptor;
  30 import java.io.IOException;
  31 
  32 import static java.util.concurrent.TimeUnit.NANOSECONDS;
  33 
  34 import jdk.internal.misc.Strands;
  35 
  36 /**
  37  * An interface that allows translation (and more!).
  38  *
  39  * @since 1.4
  40  */
  41 
  42 public interface SelChImpl extends Channel {
  43 
  44     FileDescriptor getFD();
  45 
  46     int getFDVal();
  47 
  48     /**
  49      * Adds the specified ops if present in interestOps. The specified
  50      * ops are turned on without affecting the other ops.
  51      *
  52      * @return  true iff the new value of sk.readyOps() set by this method
  53      *          contains at least one bit that the previous value did not
  54      *          contain
  55      */
  56     boolean translateAndUpdateReadyOps(int ops, SelectionKeyImpl ski);
  57 
  58     /**
  59      * Sets the specified ops if present in interestOps. The specified
  60      * ops are turned on, and all other ops are turned off.
  61      *
  62      * @return  true iff the new value of sk.readyOps() set by this method
  63      *          contains at least one bit that the previous value did not
  64      *          contain
  65      */
  66     boolean translateAndSetReadyOps(int ops, SelectionKeyImpl ski);
  67 
  68     /**
  69      * Translates an interest operation set into a native event set
  70      */
  71     int translateInterestOps(int ops);
  72 
  73     void kill() throws IOException;
  74 
  75     /**
  76      * Disables the current thread or fiber for scheduling purposes until this
  77      * channel is ready for I/O, or asynchronously closed, for up to the
  78      * specified waiting time.
  79      *
  80      * <p> This method does <em>not</em> report which of these caused the
  81      * method to return. Callers should re-check the conditions which caused
  82      * the thread to park.
  83      *
  84      * @param event the event to poll
  85      * @param nanos the timeout to wait; {@code <= 0} to wait indefinitely
  86      */
  87     default void park(int event, long nanos) throws IOException {
  88         Object strand = Strands.currentStrand();
  89         if (PollerProvider.available() && (strand instanceof Fiber)) {
  90             Poller.register(strand, getFDVal(), event);
  91             if (isOpen()) {
  92                 try {
  93                     if (nanos == 0) {
  94                         Strands.parkFiber();
  95                     } else {
  96                         Strands.parkFiber(nanos);
  97                     }
  98                 } finally {
  99                     Poller.deregister(strand, getFDVal(), event);
 100                 }
 101             }
 102         } else {
 103             long millis;
 104             if (nanos == 0) {
 105                 millis = -1;
 106             } else {
 107                 millis = NANOSECONDS.toMillis(nanos);
 108             }
 109             Net.poll(getFD(), event, millis);
 110         }

 111     }
 112 
 113     /**
 114      * Disables the current thread or fiber for scheduling purposes until this
 115      * channel is ready for I/O, or asynchronously closed.
 116      *
 117      * <p> This method does <em>not</em> report which of these caused the
 118      * method to return. Callers should re-check the conditions which caused
 119      * the thread to park.
 120      *
 121      * @param event the event to poll
 122      */
 123     default void park(int event) throws IOException {
 124         park(event, 0L);
 125     }

 126 }
< prev index next >