commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1128558 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/net/ java/org/apache/commons/runtime/platform/unix/ native/include/acr/ native/os/unix/ native/shared/
Date Sat, 28 May 2011 05:56:13 GMT
Author: mturk
Date: Sat May 28 05:56:12 2011
New Revision: 1128558

URL: http://svn.apache.org/viewvc?rev=1128558&view=rev
Log:
Start implementing the network api

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Endpoint.java
  (with props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionKey.java
  (with props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
  (with props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketSelector.java
  (with props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/SelectionKeyImpl.java
  (with props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/SocketSelectorImpl.java
      - copied, changed from r1128327, commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/SelectorImpl.java
Removed:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/SelectorImpl.java
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalStrings.properties
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Selector.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketDescriptor.java
    commons/sandbox/runtime/trunk/src/main/native/include/acr/misc.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c
    commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
    commons/sandbox/runtime/trunk/src/main/native/shared/table.c

Added: 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=1128558&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Endpoint.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Endpoint.java
Sat May 28 05:56:12 2011
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.commons.runtime.net;
+
+import java.io.Closeable;
+import java.io.Flushable;
+import java.io.IOException;
+import java.io.SyncFailedException;
+import java.net.SocketException;
+import org.apache.commons.runtime.io.ClosedDescriptorException;
+import org.apache.commons.runtime.io.Descriptor;
+
+/**
+ * This class represents a network endpoint.
+ */
+public abstract class Endpoint implements Closeable
+{
+    /**
+     * Creates a new Endpoint object.
+     */
+    protected Endpoint()
+    {
+    }
+
+    /**
+     * Gets the endpoint's  descriptor object.
+     */
+    public abstract Descriptor descriptor();
+
+    /**
+     * Free the allocated resource by the Operating system.
+     * <p>
+     * Note that {@code Object.finalize()} method will call
+     * this function. However if the native code can block for
+     * long time explicit {@code close()} should be called.
+     * </p>
+     * @see java.io.Closeable#close()
+     * @throws IOException if an I/O error occurs.
+     */
+    public abstract void close()
+        throws IOException;
+    
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Endpoint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalStrings.properties
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalStrings.properties?rev=1128558&r1=1128557&r2=1128558&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalStrings.properties
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalStrings.properties
Sat May 28 05:56:12 2011
@@ -14,3 +14,4 @@
 # limitations under the License.
 addr.EHOSTNAME=Invalid hostname
 port.ERANGE=Port is outside allowed range
+socketd.CLOSED=Socket is already closed

Added: 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=1128558&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionKey.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionKey.java
Sat May 28 05:56:12 2011
@@ -0,0 +1,49 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime.net;
+
+import java.util.EnumSet;
+import org.apache.commons.runtime.io.Descriptor;
+import org.apache.commons.runtime.net.Endpoint;
+
+/**
+ * Selection key.
+ */
+public abstract class SelectionKey
+{
+
+    /**
+     * Constructs an instance of this class.
+     */
+    protected SelectionKey()
+    {
+    }
+
+    /**
+     * Retrieves this key's event set.
+     */
+    public abstract EnumSet<SelectionEvent> events();
+
+    /**
+     * Returns the selector for which this key was created.
+     */
+    public abstract Selector selector();
+
+    public abstract Endpoint attach(Endpoint ep);
+    public abstract Endpoint attachment();
+    
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SelectionKey.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Selector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Selector.java?rev=1128558&r1=1128557&r2=1128558&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Selector.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Selector.java
Sat May 28 05:56:12 2011
@@ -23,7 +23,7 @@ import org.apache.commons.runtime.Invali
 import org.apache.commons.runtime.io.InvalidDescriptorException;
 
 /**
- * Wait for some event on set of socket descriptors.
+ * Wait for some event on set of descriptors.
  */
 public abstract class Selector
 {
@@ -32,25 +32,6 @@ public abstract class Selector
         // No instance
     }
 
-    private static final int       maxSize;
-    private static native int      nmax0();
-    private static native Selector new0(int size)
-        throws OutOfMemoryError;
-    static {
-        maxSize = nmax0();
-    }
-
-    /**
-     * Creates a new pollset instance.
-     */
-    public static Selector newInstance(int size)
-        throws OutOfMemoryError
-    {
-        if (size == 0)
-            size = maxSize;
-        return new0(size);
-    }
-
     /**
      * Interrupt this pollset.
      */

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketDescriptor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketDescriptor.java?rev=1128558&r1=1128557&r2=1128558&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketDescriptor.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketDescriptor.java
Sat May 28 05:56:12 2011
@@ -50,7 +50,7 @@ final class SocketDescriptor extends Des
         throws IOException
     {
         if (fd == -1)
-            throw new ClosedDescriptorException("Socket is already closed");
+            throw new ClosedDescriptorException(Local.sm.get("socketd.CLOSED"));
         int rc = close0(fd);
         if (rc != 0)
             throw new SocketException(Status.describe(fd));

Added: 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=1128558&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
Sat May 28 05:56:12 2011
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.commons.runtime.net;
+
+import java.io.Closeable;
+import java.io.Flushable;
+import java.io.IOException;
+import java.io.SyncFailedException;
+import java.net.SocketException;
+import org.apache.commons.runtime.io.ClosedDescriptorException;
+import org.apache.commons.runtime.io.Descriptor;
+
+/**
+ * This class represents a socket endpoint.
+ */
+public class SocketEndpoint extends Endpoint
+{
+    private SocketDescriptor  sd;
+    /**
+     * Creates a new unconnected socket object.
+     */
+    private SocketEndpoint()
+    {
+    }
+
+    @Override
+    public Descriptor descriptor()
+    {
+        return sd;
+    }
+
+    @Override
+    public void close()
+        throws IOException
+    {
+        sd.close();
+    }
+
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketSelector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketSelector.java?rev=1128558&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketSelector.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketSelector.java
Sat May 28 05:56:12 2011
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.commons.runtime.net;
+
+import org.apache.commons.runtime.Status;
+import org.apache.commons.runtime.InvalidArgumentException;
+import org.apache.commons.runtime.io.InvalidDescriptorException;
+
+/**
+ * Wait for some event on set of socket descriptors.
+ */
+public abstract class SocketSelector extends Selector
+{
+    protected SocketSelector()
+    {
+        // No instance
+    }
+
+    private static final int             maxSize;
+    private static native int            nmax0();
+    private static native SocketSelector new0(int size)
+        throws OutOfMemoryError;
+    static {
+        maxSize = nmax0();
+    }
+
+    /**
+     * Creates a new pollset instance.
+     */
+    public static SocketSelector newInstance(int size)
+        throws OutOfMemoryError
+    {
+        if (size == 0)
+            size = maxSize;
+        return new0(size);
+    }
+
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketSelector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/SelectionKeyImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/SelectionKeyImpl.java?rev=1128558&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/SelectionKeyImpl.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/SelectionKeyImpl.java
Sat May 28 05:56:12 2011
@@ -0,0 +1,82 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.runtime.platform.unix;
+
+import org.apache.commons.runtime.net.Endpoint;
+import org.apache.commons.runtime.net.SelectionEvent;
+import org.apache.commons.runtime.net.SelectionKey;
+import org.apache.commons.runtime.net.Selector;
+import org.apache.commons.runtime.net.SocketEndpoint;
+
+import org.apache.commons.runtime.AlreadyExistsException;
+import org.apache.commons.runtime.InvalidArgumentException;
+import org.apache.commons.runtime.NoSuchObjectException;
+import org.apache.commons.runtime.OperationNotImplementedException;
+import org.apache.commons.runtime.SystemException;
+import org.apache.commons.runtime.Errno;
+import java.util.EnumSet;
+
+/**
+ * Selector implementation class.
+ * <p>
+ * </p>
+ *
+ * @since Runtime 1.0
+ */
+final class SelectionKeyImpl extends SelectionKey
+{
+
+    public  int                 ievents;
+    public  int                 revents;
+    private SocketSelectorImpl  selector;
+    private Endpoint            endpoint;
+
+    public SelectionKeyImpl(SocketSelectorImpl selector, int ievents)
+    {
+        this.selector = selector;
+        this.ievents  = ievents;
+        this.revents  = 0;
+        this.endpoint = null;
+    }
+
+    @Override
+    public EnumSet<SelectionEvent> events()
+    {
+        return SelectionEvent.valueOf(revents);
+    }
+
+    @Override
+    public Selector selector()
+    {
+        return selector;
+    }
+
+    @Override
+    public Endpoint attach(Endpoint ep)
+    {
+        Endpoint prev = endpoint;
+        endpoint = ep;
+        return prev;
+    }
+    
+    @Override
+    public Endpoint attachment()
+    {
+        return endpoint;
+    }
+    
+}
+

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/SelectionKeyImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/SocketSelectorImpl.java
(from r1128327, commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/SelectorImpl.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/SocketSelectorImpl.java?p2=commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/SocketSelectorImpl.java&p1=commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/SelectorImpl.java&r1=1128327&r2=1128558&rev=1128558&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/SelectorImpl.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/SocketSelectorImpl.java
Sat May 28 05:56:12 2011
@@ -15,13 +15,18 @@
  */
 package org.apache.commons.runtime.platform.unix;
 
+import java.util.ArrayList;
+import java.util.HashSet;
 import org.apache.commons.runtime.net.SelectionEvent;
+import org.apache.commons.runtime.net.SelectionKey;
 import org.apache.commons.runtime.net.Selector;
+import org.apache.commons.runtime.net.SocketSelector;
 import org.apache.commons.runtime.AlreadyExistsException;
 import org.apache.commons.runtime.InvalidArgumentException;
 import org.apache.commons.runtime.NoSuchObjectException;
 import org.apache.commons.runtime.OperationNotImplementedException;
 import org.apache.commons.runtime.SystemException;
+import org.apache.commons.runtime.Errno;
 
 /**
  * Selector implementation class.
@@ -30,26 +35,33 @@ import org.apache.commons.runtime.System
  *
  * @since Runtime 1.0
  */
-final class SelectorImpl extends Selector
+final class SocketSelectorImpl extends SocketSelector
 {
 
-    private SelectorImpl()
+    private SocketSelectorImpl()
     {
         // No Instance
     }
 
     private short[]             revents;
+    private SelectionKeyImpl[]  keyset;
     private long                pollset;
 
-    private static native long create0(int size)
+    private static native long  create0(int size)
         throws OutOfMemoryError,
                SystemException;
+    private static native void  destroy0(long pollset);
     private static native void  wakeup0(long pollset);
-    
-    private SelectorImpl(int size)
+    private static native int   add0(long pollset, SelectionKeyImpl key, int fd, int events,
int ttl);
+    private static native int   del0(long pollset, SelectionKeyImpl key, int fd);
+    private static native int   clear0(long pollset, SelectionKeyImpl[] set);
+    private static native int   wait0(long pollset, SelectionKeyImpl[] set, short[] events,
int timeout, boolean remove);
+
+    private SocketSelectorImpl(int size)
     {
         pollset = create0(size);
         revents = new short[size];
+        keyset  = new SelectionKeyImpl[size];
     }
 
     @Override

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/misc.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/misc.h?rev=1128558&r1=1128557&r2=1128558&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/misc.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/misc.h Sat May 28 05:56:12 2011
@@ -24,8 +24,11 @@ extern "C" {
 
 ACR_CLASS_CTOR(ArrayList);
 ACR_CLASS_DTOR(ArrayList);
+ACR_CLASS_CTOR(HashSet);
+ACR_CLASS_DTOR(HashSet);
 
 int     AcrArrayListAdd(JNI_STDARGS, jobject e);
+int     AcrHashSetAdd(JNI_STDARGS, jobject e);
 void    AcrLibLockAcquire(void);
 void    AcrLibLockRelease(void);
 

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c?rev=1128558&r1=1128557&r2=1128558&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c Sat May 28 05:56:12 2011
@@ -56,7 +56,7 @@ J_DECLARE_CLAZZ = {
     0,
     0,
     0,
-    ACR_UNX_CP "SelectorImpl"
+    ACR_UNX_CP "SocketSelectorImpl"
 };
 
 J_DECLARE_M_ID(0000) = {
@@ -107,7 +107,7 @@ static short reventt(short event)
 
 #if POLLSET_USE_POLL
 
-ACR_NET_EXPORT(jobject, Selector, new0)(JNI_STDARGS, jint size)
+ACR_NET_EXPORT(jobject, SocketSelector, new0)(JNI_STDARGS, jint size)
 {
     if (_clazzn.u == 1)
         return (*env)->NewObject(env, _clazzn.i, J4MID(0000), size);
@@ -118,7 +118,7 @@ ACR_NET_EXPORT(jobject, Selector, new0)(
     return (*env)->NewObject(env, _clazzn.i, J4MID(0000), size);
 }
 
-ACR_NET_EXPORT(jint, Selector, nmax0)(JNI_STDARGS)
+ACR_NET_EXPORT(jint, SocketSelector, nmax0)(JNI_STDARGS)
 {
     int nm = 0;
 #if HAVE_SYS_RESOURCE_H
@@ -134,7 +134,7 @@ ACR_NET_EXPORT(jint, Selector, nmax0)(JN
     return nm;
 }
 
-ACR_UNX_EXPORT(jlong, SelectorImpl, create0)(JNI_STDARGS, jint size)
+ACR_UNX_EXPORT(jlong, SocketSelectorImpl, create0)(JNI_STDARGS, jint size)
 {
     int rc;
     acr_pollset_t *ps;
@@ -186,7 +186,7 @@ cleanup:
     return 0;
 }
 
-ACR_UNX_EXPORT(void, SelectorImpl, destroy0)(JNI_STDARGS, jlong pollset)
+ACR_UNX_EXPORT(void, SocketSelectorImpl, destroy0)(JNI_STDARGS, jlong pollset)
 {
     int i;
     acr_pollset_t *ps = J2P(pollset, acr_pollset_t *);
@@ -225,8 +225,8 @@ ACR_UNX_EXPORT(void, SelectorImpl, destr
     AcrFree(ps);
 }
 
-ACR_UNX_EXPORT(jint, SelectorImpl, clear0)(JNI_STDARGS, jlong pollset,
-                                           jobject rsa)
+ACR_UNX_EXPORT(jint, SocketSelectorImpl, clear0)(JNI_STDARGS, jlong pollset,
+                                                 jobjectArray rs)
 {
     int i;
     int cnt = 0;
@@ -235,7 +235,7 @@ ACR_UNX_EXPORT(jint, SelectorImpl, clear
     pthread_mutex_lock(&ps->mutex);
     while (ps->state != 0) {
         if (ps->state == PSS_DESTROY) {
-            /* Interrupted by free0 */
+            /* Interrupted by destroy0 */
             pthread_mutex_unlock(&ps->mutex);
             return 0;
         }
@@ -254,11 +254,8 @@ ACR_UNX_EXPORT(jint, SelectorImpl, clear
             return 0;
         }
     }
-    for (i = 1; i < ps->used; i++, cnt++) {
-        if (AcrArrayListAdd(env, rsa, ps->ooset[i].obj) != 0)
-            break;
-    }
     for (i = 1; i < ps->used; i++) {
+        (*env)->SetObjectArrayElement(env, rs, cnt++, ps->ooset[i].obj);
         /* Unref the container. */
         (*env)->DeleteGlobalRef(env, ps->ooset[i].obj);
     }
@@ -267,7 +264,7 @@ ACR_UNX_EXPORT(jint, SelectorImpl, clear
     return cnt;
 }
 
-ACR_UNX_EXPORT(void, SelectorImpl, wakeup0)(JNI_STDARGS, jlong pollset)
+ACR_UNX_EXPORT(void, SocketSelectorImpl, wakeup0)(JNI_STDARGS, jlong pollset)
 {
     acr_pollset_t *ps = J2P(pollset, acr_pollset_t *);
 
@@ -280,9 +277,9 @@ ACR_UNX_EXPORT(void, SelectorImpl, wakeu
     pthread_mutex_unlock(&ps->mutex);
 }
 
-ACR_UNX_EXPORT(jint, SelectorImpl, wait0)(JNI_STDARGS, jlong pollset,
-                                          jobjectArray rs, jshortArray revents,
-                                          jint timeout, jboolean rmsignaled)
+ACR_UNX_EXPORT(jint, SocketSelectorImpl, wait0)(JNI_STDARGS, jlong pollset,
+                                                jobjectArray rs, jshortArray revents,
+                                                jint timeout, jboolean rmsignaled)
 {
     int i, ns, rc = 0;
     int rv = 0;
@@ -332,7 +329,7 @@ ACR_UNX_EXPORT(jint, SelectorImpl, wait0
         rc = ACR_GET_OS_ERROR();
     pthread_mutex_lock(&ps->mutex);
     if (ps->state == PSS_DESTROY) {
-        /* Interrupted by free0 */
+        /* Interrupted by destroy0 */
         pthread_cond_broadcast(&ps->wakeup);
         pthread_mutex_unlock(&ps->mutex);
         return 0;
@@ -438,8 +435,8 @@ ACR_UNX_EXPORT(jint, SelectorImpl, wait0
     return rv;
 }
 
-ACR_UNX_EXPORT(jint, SelectorImpl, add0)(JNI_STDARGS, jlong pollset, jobject fo,
-                                         jint f, jint events, jint ttlms)
+ACR_UNX_EXPORT(jint, SocketSelectorImpl, add0)(JNI_STDARGS, jlong pollset, jobject fo,
+                                               jint f, jint events, jint ttlms)
 {
     int i, rc = 0;
     acr_pollset_t *ps = J2P(pollset, acr_pollset_t *);
@@ -497,8 +494,8 @@ cleanup:
     return rc;
 }
 
-ACR_UNX_EXPORT(jint, SelectorImpl, del0)(JNI_STDARGS, jlong pollset,
-                                         jobject fo, jint f)
+ACR_UNX_EXPORT(jint, SocketSelectorImpl, del0)(JNI_STDARGS, jlong pollset,
+                                               jobject fo, jint f)
 {
     int i, rc = ACR_EOF;
     acr_pollset_t *ps = J2P(pollset, acr_pollset_t *);
@@ -519,7 +516,7 @@ ACR_UNX_EXPORT(jint, SelectorImpl, del0)
     }
 
     for (i = 1; i < ps->used; i++) {
-        if (ps->ooset[i].obj == fo) {
+        if ((*env)->IsSameObject(env, ps->ooset[i].obj, fo) == JNI_TRUE) {
             int dest = i;
             int used = ps->used;
             ps->used--;

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c?rev=1128558&r1=1128557&r2=1128558&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Sat May 28 05:56:12 2011
@@ -213,6 +213,7 @@ AcrInitCoreClasses(JNI_STDENV)
     ACR_CLASS_LOAD(System);
     ACR_CLASS_LOAD(Observer);
     ACR_CLASS_LOAD(ArrayList);
+    ACR_CLASS_LOAD(HashSet);
     return JNI_TRUE;
 }
 
@@ -246,6 +247,7 @@ AcrUnloadRuntimeClasses(JNI_STDENV)
     ACR_CLASS_UNLOAD(DatagramSocketImpl);
     ACR_CLASS_UNLOAD(FileDescriptor);
     ACR_CLASS_UNLOAD(Callback);
+    ACR_CLASS_UNLOAD(HashSet);
     ACR_CLASS_UNLOAD(ArrayList);
     ACR_CLASS_UNLOAD(Observer);
     ACR_CLASS_UNLOAD(System);

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/table.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/table.c?rev=1128558&r1=1128557&r2=1128558&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/table.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/table.c Sat May 28 05:56:12 2011
@@ -14,8 +14,53 @@
  * limitations under the License.
  */
 
+#include "acr/jniapi.h"
+#include "acr/clazz.h"
 #include "acr/table.h"
 #include "acr/error.h"
+#include "acr/misc.h"
+
+J_DECLARE_CLAZZ = {
+    INVALID_FIELD_BASE,
+    0,
+    0,
+    0,
+    "java/util/HashSet"
+};
+
+J_DECLARE_M_ID(0000) = {
+    0,
+    "add",
+    "(Ljava/lang/Object;)Z"
+};
+
+ACR_CLASS_CTOR(HashSet)
+{
+    if (AcrLoadClass(env, &_clazzn, 0) == JNI_FALSE)
+        return JNI_FALSE;
+    J_LOAD_METHOD(0000);
+    _clazzn.u = 1;
+    return JNI_TRUE;
+}
+
+ACR_CLASS_DTOR(HashSet)
+{
+    AcrUnloadClass(env, &_clazzn);
+}
+
+int
+AcrHashSetAdd(JNI_STDARGS, jobject e)
+{
+    int rv = ACR_EINIT;
+    if (CLAZZ_LOADED) {
+        CALL_METHOD1(Boolean, 0000, obj, e);
+        if ((*env)->ExceptionCheck(env) == JNI_TRUE)
+            rv = ACR_EGENERAL;
+        else
+            rv = 0;
+    }
+    return rv;
+}
 
 int
 AcrTableInit(acr_table_t *arr, int nelts, size_t esize)



Mime
View raw message