commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1130103 - in /commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net: Endpoint.java LocalSocketEndpoint.java SelectionKey.java SelectionKeyImpl.java SocketEndpoint.java
Date Wed, 01 Jun 2011 11:28:43 GMT
Author: mturk
Date: Wed Jun  1 11:28:43 2011
New Revision: 1130103

URL: http://svn.apache.org/viewvc?rev=1130103&view=rev
Log:
Make key's endpoint final

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Endpoint.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketEndpoint.java
    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
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Endpoint.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Endpoint.java?rev=1130103&r1=1130102&r2=1130103&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Endpoint.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Endpoint.java
Wed Jun  1 11:28:43 2011
@@ -33,7 +33,7 @@ import org.apache.commons.runtime.Overfl
 public abstract class Endpoint implements Closeable
 {
     private EndpointType type;
-
+    
     private Endpoint()
     {
         // No instance

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketEndpoint.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketEndpoint.java?rev=1130103&r1=1130102&r2=1130103&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketEndpoint.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketEndpoint.java
Wed Jun  1 11:28:43 2011
@@ -146,7 +146,7 @@ public class LocalSocketEndpoint extends
         if (sd.closed())
             throw new ClosedDescriptorException();
         AbstractSelector sel = (AbstractSelector)selector;
-        if (key == null)
+        if (key == null || key.ievents == 0)
             key = new SelectionKeyImpl(sel, this);
         if (key.selector != sel)
             throw new IllegalSelectorException();

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=1130103&r1=1130102&r2=1130103&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 11:28:43 2011
@@ -16,6 +16,7 @@
 
 package org.apache.commons.runtime.net;
 
+import org.apache.commons.runtime.InvalidArgumentException;
 import org.apache.commons.runtime.io.Descriptor;
 import org.apache.commons.runtime.net.Endpoint;
 
@@ -72,8 +73,12 @@ public abstract class SelectionKey
      *
      * @param set The new event set.
      * @return this selection key.
+     *
+     * @throws InvalidArgumentException if the bits in set does
+     *          not correspond to valid operation.
      */
-    public abstract SelectionKey events(int set);
+    public abstract SelectionKey events(int set)
+        throws InvalidArgumentException;
 
     /**
      * Indicates whether this key's endpoint is interested in the given

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=1130103&r1=1130102&r2=1130103&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 11:28:43 2011
@@ -37,7 +37,7 @@ final class SelectionKeyImpl extends Sel
     public  int                         ievents;
     public  int                         revents;
     public  final AbstractSelector      selector;
-    public  Endpoint                    endpoint;
+    public  final Endpoint              endpoint;
     public  volatile boolean            selected;
 
     // Output selector events.
@@ -65,7 +65,7 @@ final class SelectionKeyImpl extends Sel
     }
 
     @Override
-    public Endpoint endpoint()
+    public final Endpoint endpoint()
     {
         return endpoint;
     }
@@ -80,8 +80,11 @@ final class SelectionKeyImpl extends Sel
 
     @Override
     public SelectionKey events(int set)
+        throws InvalidArgumentException
     {
-        ievents = set;
+        if ((set & 0x000f) == 0)
+            throw new InvalidArgumentException();
+        ievents = set & 0x000f;
         return this;
     }
 
@@ -118,11 +121,12 @@ final class SelectionKeyImpl extends Sel
     /**
      * Called from the Selector.close() native method for all currently
      * registered keys.
+     * This method invalidates the key
      */
     public void reset()
     {
+        ievents  = 0;
         revents  = 0;
         selected = false;
-        endpoint = null;
     }
 }

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java?rev=1130103&r1=1130102&r2=1130103&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
Wed Jun  1 11:28:43 2011
@@ -141,7 +141,7 @@ public class SocketEndpoint extends Endp
         if (sd.closed())
             throw new ClosedDescriptorException();
         AbstractSelector sel = (AbstractSelector)selector;
-        if (key == null)
+        if (key == null || key.ievents == 0)
             key = new SelectionKeyImpl(sel, this);
         if (key.selector != sel)
             throw new IllegalSelectorException();



Mime
View raw message