commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1130008 - in /commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net: SelectionKey.java SelectionKeyImpl.java
Date Wed, 01 Jun 2011 05:41:20 GMT
Author: mturk
Date: Wed Jun  1 05:41:19 2011
New Revision: 1130008

URL: http://svn.apache.org/viewvc?rev=1130008&view=rev
Log:
Add key's signaled api

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionKey.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionKeyImpl.java

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionKey.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionKey.java?rev=1130008&r1=1130007&r2=1130008&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionKey.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionKey.java
Wed Jun  1 05:41:19 2011
@@ -76,6 +76,111 @@ public abstract class SelectionKey
     public abstract SelectionKey events(int set);
 
     /**
+     * Indicates whether this key's endpoint is interested in the given
+     * operation and is ready to execute it without blocking.
+     *
+     * @param op operation to check.
+     * @return {@code true} if the endpoint is interested in the
+     *         in the given operation and is ready, {@code false} otherwise.
+     */
+    public abstract boolean isSignaled(int op);
+
+    /**
+     * Indicates whether this key's endpoint has timed out.
+     * When set, this flag indicates that no operation was signaled during
+     * this key's timeout period.
+     *
+     * @return {@code true} if the endpoint timed out, {@code false} otherwise.
+     */
+    public abstract boolean isTimedout();
+
+    /**
+     * Indicates whether the error condition was signaled during select
+     * operation for this key's endpoint.
+     *
+     * @return {@code true} if the error was signaled, {@code false} otherwise.
+     */
+    public abstract boolean isFailed();
+
+    /**
+     * Indicates whether this key's endpoint was hangup during the select
+     * operation.
+     *
+     * @return {@code true} if the endpoint is hangup, {@code false} otherwise.
+     */
+    public abstract boolean isHangup();
+    
+    /**
+     * Indicates whether this key's endpoint is ready to execute any of
+     * its interest operations without blocking.
+     *
+     * @return {@code true} if the endpoint is ready to execute any
+     *         of the registered interest operations, {@code false} otherwise.
+     */
+    public final boolean isSignaled()
+    {
+        return isSignaled(0x000f);
+    }
+
+    /**
+     * Indicates whether this key's endpoint is interested in the read operation
+     * and is ready to read. A call to this method is equal to executing
+     * {@code (events() & OP_READ) == OP_READ} or by executing
+     * {@code (isSignaled(OP_READ).
+     *
+     * @return {@code true} if the endpoint is interested in the read operation
+     *         and is ready to read, {@code false} otherwise.
+     */
+    public final boolean isReadable()
+    {
+        return isSignaled(OP_READ);
+    }
+
+    /**
+     * Indicates whether this key's endpoint is interested in the read operation
+     * and is ready to read. A call to this method is equal to executing
+     * {@code (events() & OP_WRITE) == OP_WRITE} or by executing
+     * {@code (isSignaled(OP_WRITE).
+     *
+     * @return {@code true} if the endpoint is interested in the write operation
+     *         and is ready to write, {@code false} otherwise.
+     */
+    public final boolean isWritable()
+    {
+        return isSignaled(OP_WRITE);
+    }
+
+    /**
+     * Indicates whether this key's endpoint is interested in the accept
+     * operation and is ready to accept new connections.
+     * A call to this method is equal to executing
+     * {@code (events() & OP_ACCEPT) == OP_ACCEPT} or by executing
+     * {@code (isSignaled(OP_ACCEPT).
+     * 
+     * @return {@code true} if the endpoint is interested in the accept operation
+     *         and is ready to accept new connections, {@code false} otherwise.
+     */
+    public final boolean isAcceptable()
+    {
+        return isSignaled(OP_ACCEPT);
+    }
+
+    /**
+     * Indicates whether this key's endpoint is interested in the connect
+     * operation and is ready to connect.
+     * A call to this method is equal to executing
+     * {@code (events() & OP_CONNECT) == OP_CONNECT} or by executing
+     * {@code (isSignaled(OP_CONNECT).
+     *
+     * @return {@code true} if the endpoint is interested in the connect operation
+     *         and is ready to connect, {@code false} otherwise.
+     */
+    public final boolean isConnectable()
+    {
+        return isSignaled(OP_CONNECT);
+    }
+
+    /**
      * Returns the endpoint for which this key was created.
      *
      * @return the related endpoint.

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionKeyImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionKeyImpl.java?rev=1130008&r1=1130007&r2=1130008&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionKeyImpl.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionKeyImpl.java
Wed Jun  1 05:41:19 2011
@@ -40,6 +40,16 @@ final class SelectionKeyImpl extends Sel
     public  Endpoint         endpoint;
     public  volatile boolean selected;
 
+    // Output selector events.
+    //
+    public static final int PRI         = 0x0010;
+    public static final int RDHUP       = 0x0020;
+    public static final int HANGUP      = 0x0040;
+    public static final int ERROR       = 0x0100;
+    public static final int NVAL        = 0x0200;
+    public static final int TIMEOUT     = 0x0400;
+
+    
     private static native void init0();
     static {
         init0();
@@ -65,7 +75,7 @@ final class SelectionKeyImpl extends Sel
     {
         // Mask out the revents with the ievents.
         //
-        return (revents & 0x0ff0) | (revents & ievents);
+        return (revents & 0x07f0) | (revents & ievents);
     }
 
     @Override
@@ -76,6 +86,27 @@ final class SelectionKeyImpl extends Sel
     }
 
     @Override
+    public boolean isSignaled(int op)
+    {
+        return (revents & ievents & op) != 0;
+    }
+    
+    public boolean isTimedout()
+    {
+        return (revents & TIMEOUT) != 0;
+    }
+
+    public boolean isFailed()
+    {
+        return (revents & (ERROR | NVAL)) != 0;
+    }
+
+    public boolean isHangup()
+    {
+        return (revents & (RDHUP | HANGUP)) != 0;
+    }
+
+    @Override
     public void cancel()
         throws ClosedSelectorException
     {



Mime
View raw message