[jboss-svn-commits] JBL Code SVN: r26590 - in labs/jbosstm/trunk/XTS/WSAS/classes/com/arjuna/mwlabs/wsas: util and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon May 18 10:23:57 EDT 2009


Author: adinn
Date: 2009-05-18 10:23:57 -0400 (Mon, 18 May 2009)
New Revision: 26590

Modified:
   labs/jbosstm/trunk/XTS/WSAS/classes/com/arjuna/mwlabs/wsas/activity/ActivityImple.java
   labs/jbosstm/trunk/XTS/WSAS/classes/com/arjuna/mwlabs/wsas/activity/ActivityReaper.java
   labs/jbosstm/trunk/XTS/WSAS/classes/com/arjuna/mwlabs/wsas/activity/HLSManager.java
   labs/jbosstm/trunk/XTS/WSAS/classes/com/arjuna/mwlabs/wsas/activity/ReaperElement.java
   labs/jbosstm/trunk/XTS/WSAS/classes/com/arjuna/mwlabs/wsas/activity/ReaperThread.java
   labs/jbosstm/trunk/XTS/WSAS/classes/com/arjuna/mwlabs/wsas/util/HLSWrapper.java
Log:
got rid of uses of class OrderedList replacing them with a TreeList - fixes JBTM-109

Modified: labs/jbosstm/trunk/XTS/WSAS/classes/com/arjuna/mwlabs/wsas/activity/ActivityImple.java
===================================================================
--- labs/jbosstm/trunk/XTS/WSAS/classes/com/arjuna/mwlabs/wsas/activity/ActivityImple.java	2009-05-18 14:05:03 UTC (rev 26589)
+++ labs/jbosstm/trunk/XTS/WSAS/classes/com/arjuna/mwlabs/wsas/activity/ActivityImple.java	2009-05-18 14:23:57 UTC (rev 26590)
@@ -70,6 +70,7 @@
 import java.util.Hashtable;
 import java.util.Stack;
 import java.util.Enumeration;
+import java.util.Iterator;
 
 /**
  * The Activity.
@@ -299,12 +300,13 @@
 
 				try
 				{
-					OrderedList hls = HLSManager.HLServices();
-					OrderedListIterator iter = new OrderedListIterator(hls);
-					HLSWrapper elem = (HLSWrapper) iter.iterate();
+					Iterator<HLSWrapper> iter = HLSManager.HLServices();
+					HLSWrapper elem;
 
-					while (elem != null)
+					while (iter.hasNext())
 					{
+                        elem = iter.next();
+
 						Outcome result = null;
 
 						try
@@ -318,8 +320,6 @@
 						}
 
 						current = HLSManager.getOutcomeManager().processOutcome(current, result);
-
-						elem = (HLSWrapper) iter.iterate();
 					}
 				}
 				catch (SystemException ex)

Modified: labs/jbosstm/trunk/XTS/WSAS/classes/com/arjuna/mwlabs/wsas/activity/ActivityReaper.java
===================================================================
--- labs/jbosstm/trunk/XTS/WSAS/classes/com/arjuna/mwlabs/wsas/activity/ActivityReaper.java	2009-05-18 14:05:03 UTC (rev 26589)
+++ labs/jbosstm/trunk/XTS/WSAS/classes/com/arjuna/mwlabs/wsas/activity/ActivityReaper.java	2009-05-18 14:23:57 UTC (rev 26590)
@@ -39,10 +39,12 @@
 import com.arjuna.mw.wsas.completionstatus.*;
 
 import com.arjuna.mw.wsas.common.Environment;
-
-import com.arjuna.ats.internal.arjuna.template.OrderedList;
 import com.arjuna.ats.internal.arjuna.template.OrderedListIterator;
 
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.Iterator;
+
 /**
  * Class to record activities with non-zero timeout values, and
  * class to implement a activity reaper thread which terminates
@@ -56,12 +58,24 @@
 public class ActivityReaper
 {
 
-    public static final String NORMAL = "NORMAL";
-    public static final String DYNAMIC = "DYNAMIC";
-
-    public final long checkingPeriod ()
+    public final long sleepPeriod ()
     {
-	return _checkPeriod;
+        synchronized (_list) {
+            if (_list.isEmpty()) {
+                // sleep until a wakeup is notified
+                return 0;
+            } else {
+                long currentTime = System.currentTimeMillis();
+                long firstTimeout = _list.first()._absoluteTimeout;
+                if (currentTime >= firstTimeout) {
+                    // don't sleep just start work now
+                    return -1;
+                } else {
+                    // sleep for required number of milliseconds
+                    return (firstTimeout - currentTime);
+                }
+            }
+        }
     }
 
     /*
@@ -79,27 +93,19 @@
     
     public final boolean check (long timeout)
     {
-	if (_list == null)
-	    return true;
-	
-	OrderedListIterator iter = new OrderedListIterator(_list);
-	ReaperElement e = null;
+        ReaperElement element = null;
 
-	while ((e = (ReaperElement) iter.iterate()) != null)
-	{
-	    if (timeout >= e._absoluteTimeout)
-		break;
-	    else
-	    {
-		iter = null;
-		return true;
-	    }
-	}
+        synchronized(_list) {
+            if (_list.isEmpty()) {
+                return false;
+            }
+            
+            element = _list.first();
+            if (timeout < element._absoluteTimeout) {
+                return false;
+            }
+        }
 
-	iter = null;
-	
-	if (e != null)
-	{
 	    /*
 	     * Only force rollback if the activity is still running.
 	     */
@@ -108,7 +114,7 @@
 	    
 	    try
 	    {
-		status = e._activity.status();
+		status = element._activity.status();
 	    }
 	    catch (Exception ex)
 	    {
@@ -123,8 +129,6 @@
 
 		boolean problem = false;
 		
-		try
-		{
 		    try
 		    {
 			/*
@@ -139,7 +143,7 @@
 
 			//			e._activity.end(Failure.instance());
 
-			UserActivityFactory.userActivity().resume(new ActivityHierarchyImple(e._activity));
+			UserActivityFactory.userActivity().resume(new ActivityHierarchyImple(element._activity));
 			UserActivityFactory.userActivity().end(Failure.instance());
 			UserActivityFactory.userActivity().suspend();
 		    }
@@ -147,19 +151,14 @@
 		    {
 			problem = true;
 		    }
-		}
-		catch (Exception ex2)
-		{
-		    problem = true;
-		}
-		
+
 		if (problem)
 		{
 		    boolean error = false;
 		     
 		    try
 		    {
-			e._activity.setCompletionStatus(FailureOnly.instance());
+			element._activity.setCompletionStatus(FailureOnly.instance());
 		    }
 		    catch (Exception ex3)
 		    {
@@ -172,12 +171,11 @@
 		    }
 		}
 	    }
-	    
-	    _list.remove(e);
-	}
-	
-	System.gc();  // do some garbage collection while we're at it!
-	
+
+        synchronized (_list) {
+            _list.remove(element);
+        }
+
 	return true;
     }
     
@@ -185,16 +183,18 @@
      * @return the number of items in the reaper's list.
      */
 
-    public final synchronized long numberOfActivities ()
+    public final long numberOfActivities ()
     {
-	return ((_list == null) ? 0 : _list.size());
+        synchronized(_list) {
+            return _list.size();
+        }
     }
     
     /**
      * timeout is given in seconds, but we work in milliseconds.
      */
  
-    public final synchronized boolean insert (ActivityImple activity, int timeout)
+    public final boolean insert (ActivityImple activity, int timeout)
     {
 	/*
 	 * Ignore if the timeout is zero, since this means the activity
@@ -204,64 +204,46 @@
 	if (timeout == 0)
 	    return true;
     
-	ActivityReaper._lifetime += timeout;
-	
-	/*
-	 * If the timeout for this activity is less than the
-	 * current timeout for the reaper thread (or one is not set for
-	 * the reaper thread) then use that timeout and interrupt the thread
-	 * to get it to recheck.
-	 */
-
-	if ((timeout < _checkPeriod) || (_checkPeriod == Long.MAX_VALUE))
-	{
-	    _checkPeriod = timeout*1000;  // convert to milliseconds!
-	    ActivityReaper._reaperThread.interrupt();
-	}
-	
 	ReaperElement e = new ReaperElement(activity, timeout);
 
-	if ((_list != null) && _list.insert(e))
-	    return true;
-	else
-	{
-	    e = null;
-	    return false;
-	}
+        synchronized (_list) {
+            _list.add(e);
+        }
+        
+        // notify the reaper thread that the list has changed
+        synchronized (_reaperThread) {
+            _reaperThread.notify();
+        }
+
+        return true;
     }
 
-    public final synchronized boolean remove (ActivityImple act)
+    public final boolean remove (ActivityImple act)
     {
-	if ((_list == null) || (act == null))
-	    return false;
-    
-	ReaperElement e = null;
-	OrderedListIterator iter = new OrderedListIterator(_list);
-	boolean result = false;
-	boolean found = false;
-	
-	while (((e = (ReaperElement) iter.iterate()) != null) && !found)
-	{
-	    try
-	    {
-		found = e._activity.equals(act);
-	    }
-	    catch (Exception e2)
-	    {
-		break;
-	    }
-	}
+        if (act == null) {
+            return false;
+        }
 
-	iter = null;
+        boolean found = false;
+        synchronized (_list) {
+            Iterator<ReaperElement> iter = _list.iterator();
+            ReaperElement e = null;
+            while (iter.hasNext() && !found) {
+                e = iter.next();
+                if (e._activity.equals(act)) {
+                    _list.remove(e);
+                    found = true;
+                }
+            }
+        }
 
-	if (found)
-	{
-	    result = _list.remove(e);
-
-	    e = null;
-	}
-
-	return result;
+        if (found) {
+            // notify the reaper thread that the list has changed
+            synchronized (_reaperThread) {
+                _reaperThread.notify();
+            }
+        }
+        return false;
     }
 
     /**
@@ -269,44 +251,14 @@
      * threads. Could get priority from environment.
      */
 
-    public static synchronized ActivityReaper create (long checkPeriod)
+    public static synchronized ActivityReaper create ()
     {
-	if (ActivityReaper._theReaper == null)
+        // TODO -- problem here because nothing calls shutdown
+        
+	if (_theReaper == null)
 	{
-	    String mode = System.getProperty(Environment.REAPER_MODE);
+	    ActivityReaper._theReaper = new ActivityReaper();
 	    
-	    if (mode != null)
-	    {
-		if (mode.compareTo(ActivityReaper.DYNAMIC) == 0)
-		    ActivityReaper._dynamic = true;
-	    }
-	    
-	    if (!ActivityReaper._dynamic)
-	    {
-		String timeoutEnv = System.getProperty(Environment.REAPER_TIMEOUT);
-
-		if (timeoutEnv != null)
-		{
-		    Long l = null;
-		
-		    try
-		    {
-			l = new Long(timeoutEnv);
-			checkPeriod = l.longValue();
-			
-			l = null;
-		    }
-		    catch (NumberFormatException e)
-		    {
-			e.printStackTrace();
-		    }
-		}
-	    }
-	    else
-		checkPeriod = Long.MAX_VALUE;
-		
-	    ActivityReaper._theReaper = new ActivityReaper(checkPeriod);
-	    
 	    _reaperThread = new ReaperThread(ActivityReaper._theReaper);
 	    //	    _reaperThread.setPriority(Thread.MIN_PRIORITY);
 
@@ -315,14 +267,9 @@
 	    _reaperThread.start();
 	}
 
-	return ActivityReaper._theReaper;
+	return _theReaper;
     }
 
-    public static synchronized ActivityReaper create ()
-    {
-	return create(ActivityReaper.defaultCheckPeriod);
-    }
-    
     public static synchronized ActivityReaper activityReaper ()
     {
 	return activityReaper(false);
@@ -344,22 +291,11 @@
      * Don't bother synchronizing as this is only an estimate anyway.
      */
 
-    public static final long activityLifetime ()
-    {
-	return ActivityReaper._lifetime;
-    }
-
     public static final long defaultCheckPeriod = 120000;  // in milliseconds
 
-    ActivityReaper (long checkPeriod)
+    ActivityReaper ()
     {
-	_list = new OrderedList();
-	_checkPeriod = checkPeriod;
-
-	if (_list == null)
-	{
-	    throw new OutOfMemoryError();
-	}
+        _list = new TreeSet<ReaperElement>();
     }
 
     static final void reset ()
@@ -367,14 +303,11 @@
 	_theReaper = null;
     }
     
-    private OrderedList _list;
-    private long        _checkPeriod;
-    
+    private SortedSet<ReaperElement> _list;
+
     private static ActivityReaper _theReaper = null;
     private static ReaperThread   _reaperThread = null;
-    private static boolean        _dynamic = false;
-    private static long           _lifetime = 0;
- 
+
 }
 
 

Modified: labs/jbosstm/trunk/XTS/WSAS/classes/com/arjuna/mwlabs/wsas/activity/HLSManager.java
===================================================================
--- labs/jbosstm/trunk/XTS/WSAS/classes/com/arjuna/mwlabs/wsas/activity/HLSManager.java	2009-05-18 14:05:03 UTC (rev 26589)
+++ labs/jbosstm/trunk/XTS/WSAS/classes/com/arjuna/mwlabs/wsas/activity/HLSManager.java	2009-05-18 14:23:57 UTC (rev 26590)
@@ -41,9 +41,7 @@
 import com.arjuna.mw.wsas.exceptions.SystemException;
 import com.arjuna.mw.wsas.exceptions.InvalidHLSException;
 
-import com.arjuna.ats.internal.arjuna.template.OrderedList;
-import com.arjuna.ats.internal.arjuna.template.OrderedListElement;
-import com.arjuna.ats.internal.arjuna.template.OrderedListIterator;
+import java.util.*;
 
 /**
  * The HLS manager is the way in which an HLS can register
@@ -64,11 +62,14 @@
 
     public static final void addHLS (HLS service) throws InvalidHLSException, SystemException
     {
-	if (service == null)
+	if (service == null) {
 	    throw new InvalidHLSException();
-	else
-	    _hls.insert(new HLSWrapper(service));
+    } else {
+        synchronized(_hls) {
+	    _hls.add(new HLSWrapper(service));
+        }
     }
+    }
 
     /**
      * @message com.arjuna.mwlabs.wsas.activity.HLSManager_1 [com.arjuna.mwlabs.wsas.activity.HLSManager_1] - HLS not found!
@@ -82,36 +83,37 @@
 	{
 	    synchronized (_hls)
 	    {
-		OrderedListIterator iter = new OrderedListIterator(_hls);
-		OrderedListElement elem = iter.iterate();
-		
-		while ((elem != null) && (((HLSWrapper) elem).hls() != service))
-		{
-		    elem = iter.iterate();
-		}
-		
-		if (elem == null)
-		    throw new InvalidHLSException(wsasLogger.log_mesg.getString("com.arjuna.mwlabs.wsas.activity.HLSManager_1"));
-		else
-		    _hls.remove(elem);
-	    }
-	}
+            HLSWrapper elem = null;
+            boolean found = false;
+            Iterator<HLSWrapper> iter = _hls.iterator();
+            while (!found && iter.hasNext()) {
+                elem = iter.next();
+                if (elem.hls() == service) {
+                    found = true;
+                }
+            }
+            if (!found) {
+                throw new InvalidHLSException(wsasLogger.log_mesg.getString("com.arjuna.mwlabs.wsas.activity.HLSManager_1"));
+            } else {
+                _hls.remove(elem);
+            }
+        }
     }
+    }
 
     public static final HLS[] allHighLevelServices () throws SystemException
     {
 	synchronized (_hls)
 	{
 	    HLS[] toReturn = new HLS[(int) _hls.size()];
-	    OrderedListIterator iter = new OrderedListIterator(_hls);
-	    OrderedListElement elem = iter.iterate();
+        Iterator<HLSWrapper> iter = _hls.iterator();
+	    HLSWrapper elem;
 	    int i = 0;
 	    
-	    while (elem != null)
+	    while (iter.hasNext())
 	    {
-		toReturn[i] = ((HLSWrapper) elem).hls();
-		i++;
-		elem = iter.iterate();
+            elem = iter.next();
+            toReturn[i++] = ((HLSWrapper) elem).hls();
 	    }
 	    
 	    return toReturn;
@@ -137,12 +139,12 @@
 	}
     }
 
-    static final OrderedList HLServices ()
+    static final Iterator<HLSWrapper> HLServices ()
     {
-	return _hls;
+	return _hls.iterator();
     }
     
-    private static OrderedList _hls = new OrderedList(false); // order decreasing as higher is first
+    private static SortedSet<HLSWrapper> _hls = new TreeSet(); // order decreasing as higher is first
     private static OutcomeManager _outcomeManager = new OutcomeManagerImple();
     
 }

Modified: labs/jbosstm/trunk/XTS/WSAS/classes/com/arjuna/mwlabs/wsas/activity/ReaperElement.java
===================================================================
--- labs/jbosstm/trunk/XTS/WSAS/classes/com/arjuna/mwlabs/wsas/activity/ReaperElement.java	2009-05-18 14:05:03 UTC (rev 26589)
+++ labs/jbosstm/trunk/XTS/WSAS/classes/com/arjuna/mwlabs/wsas/activity/ReaperElement.java	2009-05-18 14:23:57 UTC (rev 26590)
@@ -31,9 +31,7 @@
 
 package com.arjuna.mwlabs.wsas.activity;
 
-import com.arjuna.ats.internal.arjuna.template.OrderedListElement;
-
-public class ReaperElement implements OrderedListElement
+public class ReaperElement implements Comparable<ReaperElement>
 {
 
     /*
@@ -56,34 +54,35 @@
 	_absoluteTimeout = timeout*1000 + System.currentTimeMillis();
     }
 
-    public final boolean equals (OrderedListElement e)
-    {
-	if (e instanceof ReaperElement)
-	    return (_absoluteTimeout == ((ReaperElement) e)._absoluteTimeout);
-	else
-	    return false;
-    }
+    public ActivityImple _activity;
+    public long          _absoluteTimeout;
+    public int           _timeout;
 
-    public final boolean lessThan (OrderedListElement e)
+    public int compareTo(ReaperElement o)
     {
-	if (e instanceof ReaperElement)
-	    return (_absoluteTimeout < ((ReaperElement)e)._absoluteTimeout);
-	else
-	    return false;
-    }
+        if (this == o) {
+            return 0;
+        }
 
-    public final boolean greaterThan (OrderedListElement e)
-    {
-	if (e instanceof ReaperElement)
-	    return (_absoluteTimeout > ((ReaperElement)e)._absoluteTimeout);
-	else
-	    return false;
+        long otherAbsoluteTimeout = o._absoluteTimeout;
+        if (_absoluteTimeout < otherAbsoluteTimeout) {
+            return -1;
+        } else if (_absoluteTimeout > otherAbsoluteTimeout) {
+            return 1;
+        } else {
+            // enforce law of trichotomy
+            int hashcode = this.hashCode();
+            int otherHashcode = o.hashCode();
+            if (hashcode < otherHashcode) {
+                return -1;
+            } else if (hashcode > otherHashcode) {
+                return 1;
+            } else {
+                // should not happen (often :-)
+                return 0;
+            }
+        }
     }
-
-    public ActivityImple _activity;
-    public long          _absoluteTimeout;
-    public int           _timeout;
-    
 }
 
 

Modified: labs/jbosstm/trunk/XTS/WSAS/classes/com/arjuna/mwlabs/wsas/activity/ReaperThread.java
===================================================================
--- labs/jbosstm/trunk/XTS/WSAS/classes/com/arjuna/mwlabs/wsas/activity/ReaperThread.java	2009-05-18 14:05:03 UTC (rev 26589)
+++ labs/jbosstm/trunk/XTS/WSAS/classes/com/arjuna/mwlabs/wsas/activity/ReaperThread.java	2009-05-18 14:23:57 UTC (rev 26590)
@@ -47,7 +47,7 @@
     public ReaperThread (ActivityReaper arg)
     {
 	_reaperObject = arg;
-	_sleepPeriod = _reaperObject.checkingPeriod();
+	_sleepPeriod = 0;
 	_shutdown = false;
 
 	this.setDaemon(true);
@@ -55,70 +55,43 @@
     
     public void run ()
     {
-	for (;;)
-	{
-	    /*
-	     * Cannot assume we sleep for the entire period. We may
-	     * be interrupted. If we are, just run a check anyway and
-	     * ignore.
-	     */
+        for (;;)
+        {
+            synchronized(this) {
+                // see if we need to stop checking
+                if (_shutdown) {
+                    return;
+                }
 
-	    boolean done = false;
-	    
-	    while (!done)
-	    {
-		_sleepPeriod = _reaperObject.checkingPeriod();
+                _sleepPeriod = _reaperObject.sleepPeriod();
+                if (_sleepPeriod > 0) {
+                    try {
+                        wait(_sleepPeriod);
+                    } catch (InterruptedException e) {
+                        // do nothing
+                    }
+                } else if (_sleepPeriod == 0) {
+                    try {
+                        wait();
+                    } catch (InterruptedException e) {
+                        // do nothing
+                    }
+                }
+                // we might have let go of the lock so see once again if we need to stop checking
+                if (_shutdown) {
+                    return;
+                }
+            }
 
-		long oldPeriod = _sleepPeriod;
-		long beforeTime = System.currentTimeMillis();
+            // see if we have any work to do
 
-		try
-		{
-		    Thread.sleep(_sleepPeriod);
-
-		    done = true;
-		}
-		catch (InterruptedException e1)
-		{
-		    /*
-		     * Has timeout been changed?
-		     */
-
-		    if (_reaperObject.checkingPeriod() != oldPeriod)
-		    {
-			done = true;
-		    }
-		    else
-		    {
-			long afterTime = System.currentTimeMillis();
-
-			if (afterTime - beforeTime < _reaperObject.checkingPeriod())
-			{
-			    done = true;
-			}
-		    }
-		}
-		catch (Exception e2)
-		{
-		    done = true;
-		}
-	    }
-
-	    if (_shutdown)
-		return;
-
-	    _reaperObject.check(System.currentTimeMillis());
-
-	    if (_reaperObject.numberOfActivities() == 0)
-	    {
-		_sleepPeriod = Long.MAX_VALUE;
-	    }
-	}
+            _reaperObject.check(System.currentTimeMillis());
+        }
     }
 
-    public void shutdown ()
+    public synchronized void shutdown ()
     {
-	_shutdown = true;
+        _shutdown = true;
     }
 
     private ActivityReaper _reaperObject;

Modified: labs/jbosstm/trunk/XTS/WSAS/classes/com/arjuna/mwlabs/wsas/util/HLSWrapper.java
===================================================================
--- labs/jbosstm/trunk/XTS/WSAS/classes/com/arjuna/mwlabs/wsas/util/HLSWrapper.java	2009-05-18 14:05:03 UTC (rev 26589)
+++ labs/jbosstm/trunk/XTS/WSAS/classes/com/arjuna/mwlabs/wsas/util/HLSWrapper.java	2009-05-18 14:23:57 UTC (rev 26590)
@@ -43,7 +43,7 @@
  * @since 1.0.
  */
 
-public class HLSWrapper implements OrderedListElement
+public class HLSWrapper implements Comparable<HLSWrapper>
 {
 
     public HLSWrapper (HLS hls)
@@ -51,75 +51,50 @@
 	_theHLS = hls;
     }
     
-    /**
-     * Are the two entries equal?
-     */
-
-    public boolean equals (OrderedListElement e)
-    {
-	if (e instanceof HLSWrapper)
-	{
-	    try
-	    {
-		return (boolean) (((HLSWrapper) e).hls().priority() == hls().priority());
-	    }
-	    catch (SystemException ex)
-	    {
-		return false;
-	    }
-	}
-	else
-	    return false;
-    }
-
-    /**
-     * Is the current entry less than the one in the parameter?
-     */
-
-    public boolean lessThan (OrderedListElement e)
-    {
-	if (e instanceof HLSWrapper)
-	{
-	    try
-	    {
-		return (boolean) (((HLSWrapper) e).hls().priority() < hls().priority());
-	    }
-	    catch (SystemException ex)
-	    {
-		return false;
-	    }
-	}
-	else
-	    return false;
-    }	
-
-    /**
-     * Is the current entry greater than the one in the parameter?
-     */
- 
-    public boolean greaterThan (OrderedListElement e)
-    {
-	if (e instanceof HLSWrapper)
-	{
-	    try
-	    {
-		return (boolean) (((HLSWrapper) e).hls().priority() > hls().priority());
-	    }
-	    catch (SystemException ex)
-	    {
-		return false;
-	    }
-	}
-	else
-	    return false;
-    }		
-
     public final HLS hls ()
     {
 	return _theHLS;
     }
     
     private HLS _theHLS;
-    
+
+    public int compareTo(HLSWrapper o) {
+        if (this == o) {
+            return 0;
+        }
+
+        // HLSes are sorted in priority order
+
+        int priority;
+        int otherPriority;
+        // services which barf are the lowest of the low
+        try {
+            priority = hls().priority();
+        } catch (SystemException se) {
+            priority = Integer.MIN_VALUE;
+        }
+        try {
+            otherPriority = o.hls().priority();
+        } catch (SystemException se) {
+            otherPriority = Integer.MIN_VALUE;
+        }
+        if (priority < otherPriority) {
+            return -1;
+        } else if (priority > otherPriority) {
+            return 1;
+        } else {
+            // be sure to enforce trichotomy
+            int hashcode = this.hashCode();
+            int otherHashcode = o.hashCode();
+            if (hashcode < otherHashcode) {
+                return -1;
+            } else if (hashcode > otherHashcode) {
+                return 1;
+            } else {
+                // hmm, should not happen (often :-)
+                return 0;
+            }
+        }
+    }
 }
 




More information about the jboss-svn-commits mailing list