Revision: 22445
Author:   [email protected]
Date:     Sun Apr 29 15:00:09 2012
Log:      Fixes issue 3190
http://code.google.com/p/mobicents/source/detail?r=22445

Added:
/trunk/servers/jain-slee/core/services/src/main/java/org/mobicents/slee/runtime/sbbentity/SbbEntityIDComparator.java
Deleted:
/trunk/servers/jain-slee/core/activities/src/main/java/org/mobicents/slee/runtime/activity/SbbEntityComparator.java
Modified:
/trunk/servers/jain-slee/core/activities/src/main/java/org/mobicents/slee/runtime/activity/ActivityContextImpl.java /trunk/servers/jain-slee/core/services/src/main/java/org/mobicents/slee/runtime/sbbentity/NonRootSbbEntityID.java /trunk/servers/jain-slee/core/services/src/main/java/org/mobicents/slee/runtime/sbbentity/RootSbbEntityID.java /trunk/servers/jain-slee/core/services/src/main/java/org/mobicents/slee/runtime/sbbentity/SbbEntityFactoryImpl.java /trunk/servers/jain-slee/core/spi/src/main/java/org/mobicents/slee/container/sbbentity/SbbEntityFactory.java

=======================================
--- /dev/null
+++ /trunk/servers/jain-slee/core/services/src/main/java/org/mobicents/slee/runtime/sbbentity/SbbEntityIDComparator.java Sun Apr 29 15:00:09 2012
@@ -0,0 +1,132 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.mobicents.slee.runtime.sbbentity;
+
+import java.util.Comparator;
+import java.util.LinkedList;
+
+import org.mobicents.slee.container.sbbentity.SbbEntityID;
+
+/**
+ * Comparator used to sort a set of {@link SbbEntityID} by priority.
+ *
+ * @author martins
+ *
+ */
+public class SbbEntityIDComparator implements Comparator<SbbEntityID> {
+
+       private final SbbEntityFactoryImpl sbbEntityFactory;
+
+       public SbbEntityIDComparator(SbbEntityFactoryImpl sbbEntityFactory) {
+               this.sbbEntityFactory = sbbEntityFactory;
+       }
+
+       /*
+        * (non-Javadoc)
+        *
+        * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+        */
+       public int compare(SbbEntityID sbbEntityID1, SbbEntityID sbbEntityID2) {
+               if (sbbEntityID1 == sbbEntityID2) {
+                       return 0;
+               }
+               if (sbbEntityID1 == null) {
+                       return 1;
+               }
+               if (sbbEntityID2 == null) {
+                       return -1;
+               }
+               return higherPrioritySbb(sbbEntityID1, sbbEntityID2);
+       }
+
+ private int higherPrioritySbb(SbbEntityID sbbEntityID1, SbbEntityID sbbEntityID2) {
+
+               final LinkedList<Byte> stack1 = priorityOfSbb(sbbEntityID1);
+               final LinkedList<Byte> stack2 = priorityOfSbb(sbbEntityID2);
+
+               // stacks may be null if sbb entity is removed concurrently
+               if (stack1 == null) {
+                       if (stack2 == null) {
+                               return 0;
+                       } else {
+                               return 1;
+                       }
+               }
+               else {
+                       if (stack2 == null) {
+                               return -1;
+                       }
+               }
+
+               // both are non null
+               byte priority1 = 0;
+               byte priority2 = 0;
+               while (true) {
+                       priority1 = stack1.removeFirst();
+                       priority2 = stack2.removeFirst();
+                       if (priority1 == priority2) {
+                               // sbb entities have the same ancestor.
+                               if (stack1.isEmpty()) {
+                                       if (stack2.isEmpty()) {
+                                               // compare id as string
+                                               return 
sbbEntityID1.toString().compareTo(sbbEntityID2.toString());
+                                       }
+                                       else {
+                                               return -1;
+                                       }
+                               } else if (stack2.isEmpty()) {
+                                       return 1;
+                               }
+                       } else if (priority1 > priority2) {
+                               return -1;
+                       }
+                       else {
+                               return 1;
+                       }
+               }
+       }
+
+       private LinkedList<Byte> priorityOfSbb(SbbEntityID sbbEntityID) {
+               final LinkedList<Byte> list = new LinkedList<Byte>();
+               // push priority of all non root sbb entities
+               SbbEntityCacheData sbbEntityCacheData = null;
+               while (!sbbEntityID.isRootSbbEntity()) {
+ sbbEntityCacheData = new SbbEntityCacheData(sbbEntityID,sbbEntityFactory.getSleeContainer().getCluster().getMobicentsCache());
+                       if(!sbbEntityCacheData.exists()) {
+ // edge case where a sbb entity was concurrently removed, ignore this sbb entity
+                               return null;
+                       }
+                       
list.addFirst(Byte.valueOf(sbbEntityCacheData.getPriority()));
+                       sbbEntityID = sbbEntityID.getParentSBBEntityID();
+               }
+               // push the root one
+ sbbEntityCacheData = new SbbEntityCacheData(sbbEntityID,sbbEntityFactory.getSleeContainer().getCluster().getMobicentsCache());
+               if(!sbbEntityCacheData.exists()) {
+ // edge case where a sbb entity was concurrently removed, ignore this sbb entity
+                       return null;
+               }
+               list.addFirst(Byte.valueOf(sbbEntityCacheData.getPriority()));
+               return list;
+       }
+
+}
=======================================
--- /trunk/servers/jain-slee/core/activities/src/main/java/org/mobicents/slee/runtime/activity/SbbEntityComparator.java Tue Apr 19 07:36:27 2011
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2011, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.mobicents.slee.runtime.activity;
-
-import java.util.Comparator;
-import java.util.LinkedList;
-
-import org.mobicents.slee.container.sbbentity.SbbEntity;
-import org.mobicents.slee.container.sbbentity.SbbEntityFactory;
-import org.mobicents.slee.container.sbbentity.SbbEntityID;
-
-/**
- * Comparator used to sort a set of sbb entities.
- *
- * @author martins
- *
- */
-public class SbbEntityComparator implements Comparator<SbbEntityID> {
-
-       private final SbbEntityFactory sbbEntityFactory;
-
-       /**
-        * @param sbbEntityFactory
-        */
-       public SbbEntityComparator(SbbEntityFactory sbbEntityFactory) {
-               this.sbbEntityFactory = sbbEntityFactory;
-       }
-
-       /*
-        * (non-Javadoc)
-        *
-        * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
-        */
-       public int compare(SbbEntityID sbbeId1, SbbEntityID sbbeId2) {
-
-               final SbbEntity sbbe1 = 
sbbEntityFactory.getSbbEntity(sbbeId1,true);
-               final SbbEntity sbbe2 = 
sbbEntityFactory.getSbbEntity(sbbeId2,true);
-
-               if (sbbe1 == null) {
-                       if (sbbe2 == null) {
-                               return 0;
-                       } else {
-                               return 1;
-                       }
-               } else {
-                       if (sbbe2 == null) {
-                               return -1;
-                       } else {
-                               return higherPrioritySbb(sbbe1, sbbe2);
-                       }
-               }
-
-       }
-
-       /**
-        *
-        * @param sbbe1
-        * @param sbbe2
-        * @return
-        */
-       private int higherPrioritySbb(SbbEntity sbbe1, SbbEntity sbbe2) {
-
-               final LinkedList<SbbEntity> stack1 = priorityOfSbb(sbbe1);
-               final LinkedList<SbbEntity> stack2 = priorityOfSbb(sbbe2);
-
-               // stacks may be null if sbb entity is removed concurrently
-               if (stack1 == null) {
-                       if (stack2 == null) {
-                               return 0;
-                       } else {
-                               return 1;
-                       }
-               }
-               else {
-                       if (stack2 == null) {
-                               return -1;
-                       }
-               }
-
-               // both are non null
-               SbbEntity sbb1a = null;
-               SbbEntity sbb2a = null;
-               while (true) {
-                       sbb1a = stack1.removeFirst();
-                       sbb2a = stack2.removeFirst();
-                       if (sbb1a == sbb2a) {
-                               // sbb entities have the same ancestor.
-                               if (stack1.isEmpty()) {
-                                       return -1;
-                               } else if (stack2.isEmpty()) {
-                                       return 1;
-                               }
-                       } else {
-                               if (sbb1a.getPriority() > sbb2a.getPriority()) {
-                                       return -1;
-                               }
-                               else {
-                                       return 1;
-                               }
-                       }
-               }
-       }
-
-       /**
-        *
-        * @param sbbe
-        * @return
-        */
-       private LinkedList<SbbEntity> priorityOfSbb(SbbEntity sbbe) {
-               final LinkedList<SbbEntity> list = new LinkedList<SbbEntity>();
-               // push all non root sbb entities
-               while (!sbbe.getSbbEntityId().isRootSbbEntity()) {
-                       list.addFirst(sbbe);
- sbbe = sbbEntityFactory.getSbbEntity(sbbe.getSbbEntityId().getParentSBBEntityID(),false);
-                       if (sbbe == null) {
- // edge case where a parent sbb entity was concurrently removed, ignore this sbb entity
-                               return null;
-                       }
-               }
-               // push the root one
-               list.addFirst(sbbe);
-
-               return list;
-       }
-
-}
=======================================
--- /trunk/servers/jain-slee/core/activities/src/main/java/org/mobicents/slee/runtime/activity/ActivityContextImpl.java Fri Apr 27 05:03:04 2012 +++ /trunk/servers/jain-slee/core/activities/src/main/java/org/mobicents/slee/runtime/activity/ActivityContextImpl.java Sun Apr 29 15:00:09 2012
@@ -22,10 +22,9 @@

 package org.mobicents.slee.runtime.activity;

+import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
-import java.util.SortedSet;
-import java.util.TreeSet;

 import javax.slee.Address;
 import javax.slee.EventTypeID;
@@ -91,9 +90,6 @@
         */
        protected final ActivityContextCacheData cacheData;

- private static final SbbEntityComparator sbbEntityComparator = new SbbEntityComparator(
-                       sleeContainer.getSbbEntityFactory());
-
        private final ActivityContextFactoryImpl factory;

        private Integer flags;
@@ -397,18 +393,20 @@
         * @return list of SbbEIDs
         *
         */
-       @SuppressWarnings({ "unchecked", "rawtypes" })
        public Set<SbbEntityID> getSortedSbbAttachmentSet(
                        Set<SbbEntityID> excludeSet) {
                final Set<SbbEntityID> sbbAttachementSet = cacheData
                                .getSbbEntitiesAttached();
-               final SortedSet orderSbbSet = new TreeSet(sbbEntityComparator);
+               Set<SbbEntityID> result = new HashSet<SbbEntityID>();
                for (SbbEntityID sbbEntityId : sbbAttachementSet) {
                        if (!excludeSet.contains(sbbEntityId)) {
-                               orderSbbSet.add(sbbEntityId);
+                               result.add(sbbEntityId);
                        }
                }
-               return orderSbbSet;
+               if (result.size() > 1) {
+                       result = 
sleeContainer.getSbbEntityFactory().sortByPriority(result);
+               }
+               return result;
        }

        public Set<SbbEntityID> getSbbAttachmentSet() {
=======================================
--- /trunk/servers/jain-slee/core/services/src/main/java/org/mobicents/slee/runtime/sbbentity/NonRootSbbEntityID.java Tue Apr 19 07:36:27 2011 +++ /trunk/servers/jain-slee/core/services/src/main/java/org/mobicents/slee/runtime/sbbentity/NonRootSbbEntityID.java Sun Apr 29 15:00:09 2012
@@ -124,7 +124,7 @@
        @Override
        public String toString() {
                if (toString == null) {
- toString = new StringBuilder(parentSbbEntityID.toString()).append("/").append(parentChildRelation).append("/").append(childID).toString(); + toString = new StringBuilder(parentSbbEntityID.toString()).append('/').append(parentChildRelation).append('/').append(childID).toString();
                }
                return toString;
        }
=======================================
--- /trunk/servers/jain-slee/core/services/src/main/java/org/mobicents/slee/runtime/sbbentity/RootSbbEntityID.java Tue Apr 19 07:36:27 2011 +++ /trunk/servers/jain-slee/core/services/src/main/java/org/mobicents/slee/runtime/sbbentity/RootSbbEntityID.java Sun Apr 29 15:00:09 2012
@@ -177,7 +177,7 @@
        public String toString() {
                if (toString == null) {
                        toString = new 
StringBuilder("/").append(serviceID.toString())
-                                       
.append("/").append(convergenceName).toString();
+                                       
.append('/').append(convergenceName).toString();
                }
                return toString;
        }
=======================================
--- /trunk/servers/jain-slee/core/services/src/main/java/org/mobicents/slee/runtime/sbbentity/SbbEntityFactoryImpl.java Tue Apr 19 07:36:27 2011 +++ /trunk/servers/jain-slee/core/services/src/main/java/org/mobicents/slee/runtime/sbbentity/SbbEntityFactoryImpl.java Sun Apr 29 15:00:09 2012
@@ -24,6 +24,7 @@

 import java.util.Collections;
 import java.util.Set;
+import java.util.TreeSet;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.locks.ReentrantLock;

@@ -59,7 +60,9 @@
        private static final boolean doTraceLogs = logger.isTraceEnabled();

        protected SbbEntityLockFacility lockFacility;
-
+
+ private final SbbEntityIDComparator sbbEntityIDComparator = new SbbEntityIDComparator(this);
+
        @Override
        public void sleeInitialization() {
                this.lockFacility = new SbbEntityLockFacility(sleeContainer);
@@ -331,10 +334,7 @@
                }
        }

-       /**
-        *
-        * @return
-        */
+       @Override
        public Set<SbbEntityID> getSbbEntityIDs() {
final SbbEntityFactoryCacheData cacheData = new SbbEntityFactoryCacheData(sleeContainer.getCluster());
                if (cacheData.exists()) {
@@ -344,4 +344,11 @@
                        return Collections.emptySet();
                }
        }
-}
+
+       @Override
+       public Set<SbbEntityID> sortByPriority(Set<SbbEntityID> ids) {
+ final Set<SbbEntityID> orderSbbSet = new TreeSet<SbbEntityID>(sbbEntityIDComparator);
+               orderSbbSet.addAll(ids);
+               return orderSbbSet;
+       }
+}
=======================================
--- /trunk/servers/jain-slee/core/spi/src/main/java/org/mobicents/slee/container/sbbentity/SbbEntityFactory.java Tue Apr 19 07:36:27 2011 +++ /trunk/servers/jain-slee/core/spi/src/main/java/org/mobicents/slee/container/sbbentity/SbbEntityFactory.java Sun Apr 29 15:00:09 2012
@@ -96,4 +96,13 @@
        public void removeSbbEntity(SbbEntity sbbEntity,
                        boolean useCurrentClassLoader);

-}
+       /**
+ * Orders the specified set of {@link SbbEntityID}, according to priority of + * related Sbb Entities. In case 2 Sbb Entities have same priority, order is
+        * defined by comparing the toString() of the IDs.
+        *
+        * @param ids
+        * @return
+        */
+       public Set<SbbEntityID> sortByPriority(Set<SbbEntityID> ids);
+}

Reply via email to