Revision: 16391
Author: [email protected]
Date: Wed Jan 12 21:27:10 2011
Log: Fix for http://code.google.com/p/mobicents/issues/detail?id=2265
Modify /stream API to use Javolution API
http://code.google.com/p/mobicents/source/detail?r=16391

Modified:
/trunk/protocols/ss7/hardware/dahdi/java/src/main/java/org/mobicents/ss7/hardware/dahdi/Selector.java /trunk/protocols/ss7/management/linkset/src/main/java/org/mobicents/ss7/linkset/oam/LinksetSelector.java /trunk/protocols/ss7/mtp/mtp-impl/src/main/java/org/mobicents/protocols/ss7/mtp/Mtp3.java
 /trunk/protocols/ss7/pom.xml

=======================================
--- /trunk/protocols/ss7/hardware/dahdi/java/src/main/java/org/mobicents/ss7/hardware/dahdi/Selector.java Mon Dec 27 04:35:56 2010 +++ /trunk/protocols/ss7/hardware/dahdi/java/src/main/java/org/mobicents/ss7/hardware/dahdi/Selector.java Wed Jan 12 21:27:10 2011
@@ -18,8 +18,8 @@
 package org.mobicents.ss7.hardware.dahdi;

 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
+
+import javolution.util.FastList;

 import org.apache.log4j.Logger;
 import org.mobicents.protocols.ss7.mtp.Mtp1;
@@ -27,101 +27,114 @@
 import org.mobicents.protocols.stream.api.Stream;
 import org.mobicents.protocols.stream.api.StreamSelector;

+/**
+ *
+ * @author amit bhayani
+ *
+ */
 public class Selector implements StreamSelector {

     private final static String LIB_NAME = "mobicents-dahdi-linux";
-
+
     public final static int READ = 0x01;
     public final static int WRITE = 0x02;
-
+
     /** array of selected file descriptors */
     private int fds[] = new int[16];
-
+
     /** array of registered channels */
-    private ArrayList<Mtp1> registered = new ArrayList();
-
+    private FastList<Mtp1> registered = new FastList<Mtp1>();
+
     private int ops;
-
+
     /** array of selected channels */
-    private ArrayList<SelectorKey> selected = new ArrayList();
+    private FastList<SelectorKey> selected = new FastList<SelectorKey>();
     private static Logger logger = Logger.getLogger(Selector.class);
-
+
     static {
-       try {
-                        System.loadLibrary(LIB_NAME);
-                        System.out.println("Loaded library 
mobicents-dahdi-linux");
-               } catch (Exception e) {
-                       e.printStackTrace();
-               }
-    }
-
+        try {
+            System.loadLibrary(LIB_NAME);
+            System.out.println("Loaded library mobicents-dahdi-linux");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
     public Selector() {
-
-    }
-
+
+    }
+
     /**
      * Register channel with this selector.
-     *
-     * @param channel the channel to register.
-     */
+     *
+     * @param channel
+     *            the channel to register.
+     */
     public SelectorKey register(Channel channel) {
-       //add channel instance to the collection
-       registered.add(channel);
-       //perform actual registration
-       logger.info("Registering file descriptor:" + ((Channel) channel).fd);
-       doRegister(((Channel)channel).fd);
-
+        // add channel instance to the collection
+        registered.add(channel);
+        // perform actual registration
+ logger.info("Registering file descriptor:" + ((Channel) channel).fd);
+        doRegister(((Channel) channel).fd);
+
         SelectorKeyImpl key = new SelectorKeyImpl(channel, this);
         channel.selectorKey = key;
         return key;
     }
-
+
     /**
      * Unregister channel.
-     *
-     * @param channel the channel to unregister.
+     *
+     * @param channel
+     *            the channel to unregister.
      */
     public void unregister(Channel channel) {
-       registered.remove(channel);
+        registered.remove(channel);
         channel.selectorKey = null;
-       doUnregister(((Channel)channel).fd);
-    }
-
+        doUnregister(((Channel) channel).fd);
+    }
+
     /**
      * Registers pipe for polling.
-     *
-     *@param fd the file descriptor.
+     *
+     * @param fd
+     *            the file descriptor.
      */
     public native void doRegister(int fd);
-
+
     /**
      * Unregisters pipe from polling.
-     *
-     * @param fd the file descriptor.
-     */
+     *
+     * @param fd
+     *            the file descriptor.
+     */
     public native void doUnregister(int fd);
-
+
     /**
      * Delegates select call to unix poll function.
-     *
-     * @param fds the list of file descriptors.
-     * @param key selection key.
+     *
+     * @param fds
+     *            the list of file descriptors.
+     * @param key
+     *            selection key.
      * @return the number of selected channels.
-     */
+     */
     public native int doPoll(int[] fds, int key, int timeout);

- public Collection<SelectorKey> selectNow(int ops, int timeout) throws IOException {
-       int count = doPoll(fds, ops, 20);
-       selected.clear();
-       for (int i = 0; i < count; i++) {
-           for (Mtp1 chan : registered) {
-               Channel channel = (Channel) chan;
-               if (channel.fd == fds[i]) {
-                   selected.add(channel.selectorKey);
-               }
-           }
-       }
-       return selected;
+    public FastList<SelectorKey> selectNow(int ops, int timeout)
+            throws IOException {
+        int count = doPoll(fds, ops, 20);
+        selected.clear();
+        for (int i = 0; i < count; i++) {
+ for (FastList.Node<Mtp1> n = registered.head(), end = registered
+                    .tail(); (n = n.getNext()) != end;) {
+                Channel channel = (Channel) n.getValue();
+                if (channel.fd == fds[i]) {
+                    selected.add(channel.selectorKey);
+                }
+            }
+        }
+        return selected;
     }

     public void setOperation(int v) {
@@ -148,7 +161,7 @@
         throw new UnsupportedOperationException("Not supported yet.");
     }

-    public Collection<Stream> getRegisteredStreams() {
+    public FastList<Stream> getRegisteredStreams() {
         throw new UnsupportedOperationException("Not supported yet.");
     }
 }
=======================================
--- /trunk/protocols/ss7/management/linkset/src/main/java/org/mobicents/ss7/linkset/oam/LinksetSelector.java Wed Dec 29 10:30:02 2010 +++ /trunk/protocols/ss7/management/linkset/src/main/java/org/mobicents/ss7/linkset/oam/LinksetSelector.java Wed Jan 12 21:27:10 2011
@@ -1,8 +1,8 @@
 package org.mobicents.ss7.linkset.oam;

 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
+
+import javolution.util.FastList;

 import org.apache.log4j.Logger;
 import org.mobicents.protocols.stream.api.SelectorKey;
@@ -20,10 +20,10 @@
     private static final Logger logger = Logger
             .getLogger(LinksetSelector.class);

-    private ArrayList<Stream> registered = new ArrayList<Stream>();
+    private FastList<Stream> registered = new FastList<Stream>();

     /** array of selected channels */
-    private ArrayList<SelectorKey> selected = new ArrayList<SelectorKey>();
+    private FastList<SelectorKey> selected = new FastList<SelectorKey>();

     public LinksetSelector() {
         // TODO Auto-generated constructor stub
@@ -50,7 +50,7 @@
         throw new UnsupportedOperationException("Not supported yet.");
     }

-    public Collection<Stream> getRegisteredStreams() {
+    public FastList<Stream> getRegisteredStreams() {
         return registered;
     }

@@ -58,7 +58,7 @@
         throw new UnsupportedOperationException("Not supported yet.");
     }

-    public Collection<SelectorKey> selectNow(int operation, int timeout)
+    public FastList<SelectorKey> selectNow(int operation, int timeout)
             throws IOException {

         selected.clear();
=======================================
--- /trunk/protocols/ss7/mtp/mtp-impl/src/main/java/org/mobicents/protocols/ss7/mtp/Mtp3.java Tue Jan 4 21:41:36 2011 +++ /trunk/protocols/ss7/mtp/mtp-impl/src/main/java/org/mobicents/protocols/ss7/mtp/Mtp3.java Wed Jan 12 21:27:10 2011
@@ -29,9 +29,10 @@
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.List;

+import javolution.util.FastList;
+
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 import org.mobicents.protocols.stream.api.SelectorKey;
@@ -219,14 +220,14 @@

     public void run() {
         try {
- Collection<SelectorKey> selected = selector.selectNow(StreamSelector.OP_READ, 20);
-            for (SelectorKey key : selected) {
-                ((Mtp2)((Mtp1) key.getStream()).getLink()).doRead();
-            }
-
+ FastList<SelectorKey> selected = selector.selectNow(StreamSelector.OP_READ, 20); + for (FastList.Node<SelectorKey> n = selected.head(), end = selected.tail(); (n = n.getNext()) != end;) { + ((Mtp2)((Mtp1) n.getValue().getStream()).getLink()).doRead();
+            }
+
             selected = selector.selectNow(StreamSelector.OP_WRITE, 20);
-            for (SelectorKey key : selected) {
-                ((Mtp2)((Mtp1) key.getStream()).getLink()).doWrite();
+ for (FastList.Node<SelectorKey> n = selected.head(), end = selected.tail(); (n = n.getNext()) != end;) { + ((Mtp2)((Mtp1) n.getValue().getStream()).getLink()).doWrite();
             }

             this.executor.tick();
=======================================
--- /trunk/protocols/ss7/pom.xml        Sun Jan  9 04:39:47 2011
+++ /trunk/protocols/ss7/pom.xml        Wed Jan 12 21:27:10 2011
@@ -30,7 +30,7 @@
                 <compile.source>1.5</compile.source>
                 <!-- mobicents but not strictly ss7 -->
                 <asn.version>1.0.0.BETA3</asn.version>
-                <stream.version>1.0.0.BETA2</stream.version>
+                <stream.version>1.0.0-SNAPSHOT</stream.version>

         </properties>

Reply via email to