Author: peter_firmstone Date: Thu Nov 15 07:20:59 2012 New Revision: 1409671
URL: http://svn.apache.org/viewvc?rev=1409671&view=rev Log: Fix up some synchronization issues, more logging output to assist debugging. Modified: river/jtsk/trunk/qa/src/com/sun/jini/qa/harness/AdminManager.java river/jtsk/trunk/qa/src/com/sun/jini/test/share/BaseQATest.java Modified: river/jtsk/trunk/qa/src/com/sun/jini/qa/harness/AdminManager.java URL: http://svn.apache.org/viewvc/river/jtsk/trunk/qa/src/com/sun/jini/qa/harness/AdminManager.java?rev=1409671&r1=1409670&r2=1409671&view=diff ============================================================================== --- river/jtsk/trunk/qa/src/com/sun/jini/qa/harness/AdminManager.java (original) +++ river/jtsk/trunk/qa/src/com/sun/jini/qa/harness/AdminManager.java Thu Nov 15 07:20:59 2012 @@ -26,6 +26,9 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -118,19 +121,19 @@ public class AdminManager { Logger.getLogger("com.sun.jini.qa.harness"); /** A mapping of service name prefixes to their index counters. */ - private HashMap serviceCounters = new HashMap(); + private final Map serviceCounters = new HashMap(); /** The set of admins to be managed by this manager. */ - private HashSet createdAdminSet = new HashSet(); + private final Set createdAdminSet = new HashSet(); /** The <code>QAConfig</code> object */ - private QAConfig config; + private final QAConfig config; /** the admin for the shared group managed by this class. */ - private SharedGroupAdmin sharedGroupAdmin; + private volatile SharedGroupAdmin sharedGroupAdmin = null; /** The admin for the shared non-activatable group */ - private NonActivatableGroupAdmin nonActivatableGroupAdmin; + private volatile NonActivatableGroupAdmin nonActivatableGroupAdmin = null; /** * Construct an <code>AdminManager</code>. @@ -323,7 +326,9 @@ public class AdminManager { + "serviceName '" + serviceName + "'"); } - createdAdminSet.add(admin); + synchronized (createdAdminSet){ + createdAdminSet.add(admin); + } return admin; } @@ -398,15 +403,17 @@ public class AdminManager { * admin cannot be found. */ public Admin getAdmin(Object proxy) { - Iterator it = createdAdminSet.iterator(); - while (it.hasNext()) { - Admin ad = (Admin) it.next(); - Object p = ad.getProxy(); - if (p != null && p.equals(proxy)) { - return ad; - } - } - return null; + synchronized (createdAdminSet){ + Iterator it = createdAdminSet.iterator(); + while (it.hasNext()) { + Admin ad = (Admin) it.next(); + Object p = ad.getProxy(); + if (p != null && p.equals(proxy)) { + return ad; + } + } + return null; + } } /** @@ -834,27 +841,29 @@ public class AdminManager { ArrayList nonActList = new ArrayList(); ArrayList actSystemList = new ArrayList(); ArrayList classServerList = new ArrayList(); - Iterator it = createdAdminSet.iterator(); - while (it.hasNext()) { - Admin admin = (Admin) it.next(); - if (admin.getProxy() == null) { // never started - it.remove(); // must use iterator's remove method - continue; - } - if (admin.getProxy() instanceof ServiceRegistrar) { - lusList.add(admin); - } else if (admin instanceof SharedGroupAdmin) { - sharedList.add(admin); - } else if (admin instanceof NonActivatableGroupAdmin) { - nonActList.add(admin); - } else if (admin instanceof ActivationSystemAdmin) { - actSystemList.add(admin); - } else if (admin instanceof ClassServerAdmin) { - classServerList.add(admin); - } else { - svcList.add(admin); - } - } + synchronized (createdAdminSet){ + Iterator it = createdAdminSet.iterator(); + while (it.hasNext()) { + Admin admin = (Admin) it.next(); + if (admin.getProxy() == null) { // never started + it.remove(); // must use iterator's remove method + continue; + } + if (admin.getProxy() instanceof ServiceRegistrar) { + lusList.add(admin); + } else if (admin instanceof SharedGroupAdmin) { + sharedList.add(admin); + } else if (admin instanceof NonActivatableGroupAdmin) { + nonActList.add(admin); + } else if (admin instanceof ActivationSystemAdmin) { + actSystemList.add(admin); + } else if (admin instanceof ClassServerAdmin) { + classServerList.add(admin); + } else { + svcList.add(admin); + } + } + } ArrayList[] lists = new ArrayList[] {svcList, lusList, sharedList, @@ -862,8 +871,8 @@ public class AdminManager { actSystemList, classServerList}; for (int i = 0; i < lists.length; i++) { - ArrayList list = lists[i]; - it = list.iterator(); + List list = lists[i]; + Iterator it = list.iterator(); /* Step through the iterator destroying each service */ while(it.hasNext()) { Admin admin = (Admin) it.next(); @@ -905,47 +914,49 @@ public class AdminManager { if (service == null) { return true; } - Iterator it = createdAdminSet.iterator(); - while(it.hasNext()) { - Admin admin = (Admin) it.next(); - if (admin == null) { - continue; - } - Object proxy = admin.getProxy(); - // proxy will be null if the service wasn't started - if (proxy == null || (! proxy.equals(service))) { - continue; - } - try { - logger.log(Level.FINE, - "destroying service: " + proxy.getClass()); - if (admin instanceof ActivatableServiceStarterAdmin) { - ActivatableServiceStarterAdmin - ssa = (ActivatableServiceStarterAdmin) admin; - int destroyCode = ssa.stopAndWait(nSecsWait); - if(nSecsWait <= 0) {//doesn't care if act group still there - destroyCode = ServiceDestroyer.DESTROY_SUCCESS; - } - handleDestroyCode(destroyCode); - return destroyCode == ServiceDestroyer.DESTROY_SUCCESS ; - } else { - admin.stop(); - } - if (admin == sharedGroupAdmin) { - sharedGroupAdmin = null; - } - if (admin == nonActivatableGroupAdmin) { - nonActivatableGroupAdmin = null; - } - return true; - } catch(RemoteException e) { - logger.log(Level.FINE, "RemoteException stopping service", e); - } catch(ActivationException e) { - logger.log(Level.FINE, "ActivationException stopping service:", e); + synchronized (createdAdminSet){ + Iterator it = createdAdminSet.iterator(); + while(it.hasNext()) { + Admin admin = (Admin) it.next(); + if (admin == null) { + continue; + } + Object proxy = admin.getProxy(); + // proxy will be null if the service wasn't started + if (proxy == null || (! proxy.equals(service))) { + continue; + } + try { + logger.log(Level.FINE, + "destroying service: " + proxy.getClass()); + if (admin instanceof ActivatableServiceStarterAdmin) { + ActivatableServiceStarterAdmin + ssa = (ActivatableServiceStarterAdmin) admin; + int destroyCode = ssa.stopAndWait(nSecsWait); + if(nSecsWait <= 0) {//doesn't care if act group still there + destroyCode = ServiceDestroyer.DESTROY_SUCCESS; + } + handleDestroyCode(destroyCode); + return destroyCode == ServiceDestroyer.DESTROY_SUCCESS ; + } else { + admin.stop(); + } + if (admin == sharedGroupAdmin) { + sharedGroupAdmin = null; + } + if (admin == nonActivatableGroupAdmin) { + nonActivatableGroupAdmin = null; + } + return true; + } catch(RemoteException e) { + logger.log(Level.FINE, "RemoteException stopping service", e); + } catch(ActivationException e) { + logger.log(Level.FINE, "ActivationException stopping service:", e); + } + finally { + it.remove(); // must use iterator's remove + } } - finally { - it.remove(); // must use iterator's remove - } } return false; } @@ -1024,7 +1035,11 @@ public class AdminManager { * @return the <code>Iterator</code> */ Iterator iterator() { - return createdAdminSet.iterator(); + Set set = new HashSet(); + synchronized (createdAdminSet){ + set.addAll(createdAdminSet); + } + return set.iterator(); } /** @@ -1066,8 +1081,10 @@ public class AdminManager { } public AbstractServiceAdmin[] getAllAdmins() { - AbstractServiceAdmin[] admins = - new AbstractServiceAdmin[createdAdminSet.size()]; - return (AbstractServiceAdmin[]) createdAdminSet.toArray(admins); + synchronized (createdAdminSet){ + AbstractServiceAdmin[] admins = + new AbstractServiceAdmin[createdAdminSet.size()]; + return (AbstractServiceAdmin[]) createdAdminSet.toArray(admins); + } } } Modified: river/jtsk/trunk/qa/src/com/sun/jini/test/share/BaseQATest.java URL: http://svn.apache.org/viewvc/river/jtsk/trunk/qa/src/com/sun/jini/test/share/BaseQATest.java?rev=1409671&r1=1409670&r2=1409671&view=diff ============================================================================== --- river/jtsk/trunk/qa/src/com/sun/jini/test/share/BaseQATest.java (original) +++ river/jtsk/trunk/qa/src/com/sun/jini/test/share/BaseQATest.java Thu Nov 15 07:20:59 2012 @@ -1438,7 +1438,10 @@ abstract public class BaseQATest extends for(int i=0;i<lookupsStarted.size();i++) { LocatorGroupsPair pair = (LocatorGroupsPair)lookupsStarted.get(i); int curPort = (pair.locator).getPort(); - if(port == curPort) return true; + if(port == curPort) { + logger.log(Level.FINE, "port in use: " + port); + return true; + } }//end loop return false; }//end portInUse @@ -1569,8 +1572,9 @@ abstract public class BaseQATest extends = (LocatorGroupsPair)addLookupsToStart.get(j); int port = (pair.locator).getPort(); if(portInUse(port)) port = 0; - String hostname = startLookup(i,port, pair.locator.getHost()); + startLookup(i,port, pair.locator.getHost()); if(port == 0) { + logger.log(Level.FINEST, "port was equal to zero"); Object locGroupsPair = lookupsStarted.get(i); addLookupsToStart.set(j,locGroupsPair); allLookupsToStart.set(i,locGroupsPair); @@ -1614,6 +1618,7 @@ abstract public class BaseQATest extends protected String startLookup(int indx, int port, String serviceHost) throws Exception { logger.log(Level.FINE, " starting lookup service "+indx); + logger.log(Level.FINEST, serviceHost + ":"+ port); /* retrieve the member groups with which to configure the lookup */ String[] memberGroups = (String[])memberGroupsList.get(indx); ServiceRegistrar lookupProxy = null;
