river-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter_firmst...@apache.org
Subject svn commit: r1488180 - in /river/jtsk/skunk/qa_refactor/trunk: qa/src/com/sun/jini/test/impl/joinmanager/ qa/src/com/sun/jini/test/impl/mercury/ qa/src/com/sun/jini/test/impl/start/ qa/src/com/sun/jini/test/services/lookupsimulator/ qa/src/com/sun/jini...
Date Fri, 31 May 2013 11:45:49 GMT
Author: peter_firmstone
Date: Fri May 31 11:45:48 2013
New Revision: 1488180

URL: http://svn.apache.org/r1488180
Log:
River-420 QA suite tests: delay export until after construction, more services converted to com.sun.jini.start.Starter

Added:
    river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/SharedGroupImplInit.java
      - copied, changed from r1487782, river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/AbstractSharedGroupInit.java
Removed:
    river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/AbstractSharedGroup.java
    river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/AbstractSharedGroupInit.java
Modified:
    river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/joinmanager/LeaseRenewDurRFE.java
    river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/TestGeneratorImpl.java
    river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/TestListenerImpl.java
    river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/TestPullListenerImpl.java
    river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/start/BadServiceProxyAccessorImpl.java
    river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/start/TestServiceImpl.java
    river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/services/lookupsimulator/LookupSimulatorImpl.java
    river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/discoveryservice/AbstractBaseTest.java
    river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/ActivateWrapper.java
    river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/NonActivatableServiceDescriptor.java
    river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/ServiceStarter.java
    river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/SharedGroupImpl.java
    river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/Starter.java

Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/joinmanager/LeaseRenewDurRFE.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/joinmanager/LeaseRenewDurRFE.java?rev=1488180&r1=1488179&r2=1488180&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/joinmanager/LeaseRenewDurRFE.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/joinmanager/LeaseRenewDurRFE.java Fri May 31 11:45:48 2013
@@ -78,6 +78,7 @@ import com.sun.jini.config.Config;
 import com.sun.jini.config.ConfigUtil;
 import com.sun.jini.logging.Levels;
 import com.sun.jini.qa.harness.Test;
+import com.sun.jini.start.Starter;
 
 import net.jini.activation.ActivationExporter;
 import net.jini.activation.ActivationGroup;
@@ -106,12 +107,16 @@ import java.rmi.activation.ActivationSys
 import java.rmi.activation.ActivationException;
 import java.rmi.MarshalledObject;
 import java.rmi.server.ExportException;
+import java.security.AccessControlContext;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 import java.util.List;
 import java.util.StringTokenizer;
 
 import javax.security.auth.Subject;
 import javax.security.auth.login.LoginContext;
+import javax.security.auth.login.LoginException;
 
 /**
  * This class verifies that the current implementation of the 
@@ -1057,193 +1062,274 @@ public class LeaseRenewDurRFE extends Ab
 
     static class RemoteTestServiceImpl implements ServerProxyTrust,
                                                   ProxyAccessor,
-                                                  RemoteTestServiceInterface
+                                                  RemoteTestServiceInterface,
+                                                  Starter
                                                   
     {
         private static final String COMPONENT_NAME = "test";
         private static final String JM_COMPONENT_NAME
                                              = "net.jini.lookup.JoinManager";
-        private int val = 0;
-        private long renewDur = Lease.FOREVER;
+        final private int val;
+        final private long renewDur;
 
-        private Configuration config;
-        private LoginContext loginContext = null;
-        private Uuid proxyID = null;
-        private ServiceID serviceID = null;
-        private ActivationID activationID;
-        private ActivationSystem activationSystem;
-        private Exporter serverExporter;
+        final private Configuration config;
+        final private LoginContext loginContext;
+        final private Uuid proxyID;
+        final private ServiceID serviceID;
+        final private ActivationID activationID;
+        final private ActivationSystem activationSystem;
+        volatile private boolean activationSystemUnregister;
+        final private Exporter serverExporter;
         private TestServiceProxy outerProxy;
         private RemoteTestServiceInterface innerProxy;
-        private String[] groupsToJoin = DiscoveryGroupManagement.NO_GROUPS;
-        private LookupLocator[] locatorsToJoin = new LookupLocator[0];
-        private LookupDiscoveryManager ldm;
+        final private String[] groupsToJoin;
+        final private LookupLocator[] locatorsToJoin;
+        final private LookupDiscoveryManager ldm;
         private JoinManager joinMgr;
+        private AccessControlContext context;
+        private boolean started = false;
 
         RemoteTestServiceImpl(ActivationID activationID,
                               MarshalledObject data) throws Exception
-        {
-            this.activationID = activationID;
-            activationSystem = ActivationGroup.getSystem();
-            init( (String[])data.get() );
+        {// All exceptions are thrown prior to this Object being created.
+            this(init((String[])data.get(), activationID, ActivationGroup.getSystem()));
         }//end constructor
+        
+        private RemoteTestServiceImpl(Init init){
+            config = init.config;
+            loginContext = init.loginContext;
+            proxyID = init.proxyID;
+            serviceID = init.serviceID;
+            activationID = init.activationID;
+            activationSystem = init.activationSystem;
+            serverExporter = init.serverExporter;
+            groupsToJoin = init.groupsToJoin;
+            locatorsToJoin = init.locatorsToJoin;
+            ldm = init.ldm;
+            context = init.context;
+            val = init.val.intValue();
+            renewDur = init.renewDur.longValue();
+        }
+        
+        public synchronized void start() throws Exception {
+            if (started) return;
+            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>(){
+
+                @Override
+                public Object run() throws Exception {
+                    innerProxy =
+                           (RemoteTestServiceInterface)serverExporter.export(RemoteTestServiceImpl.this);
+                    outerProxy = TestServiceProxy.createTestServiceProxy
+                                                  (innerProxy, proxyID, val, renewDur);
+                    joinMgr = new JoinManager(outerProxy, null, serviceID,
+                                              ldm, null, config);
+                    return null;
+                }
+                
+            }, context);
+            started = true;
+            context = null; //Be careful not to store things on the stack.
+        }
 
         public void exitService() throws RemoteException, ActivationException {
-            if (activationSystem != null) {
+            if (activationSystemUnregister) {
 	        activationSystem.unregisterGroup
                                           ( ActivationGroup.currentGroupID() );
-                activationSystem = null;     
+                activationSystemUnregister = false;
             }//endif
             (new DestroyThread()).start();
         }//end exitService
 
-        private void init(String[] args) throws Exception {
-            config = ConfigurationProvider.getInstance
-                                       ( args,
-                                         (this.getClass()).getClassLoader() );
+        private static Init init(   String[] args, 
+                                    ActivationID activationID, 
+                                    ActivationSystem activationSystem
+                                ) throws Exception 
+        {
+            Configuration config 
+                    = ConfigurationProvider.getInstance
+                           ( args,
+                             RemoteTestServiceImpl.class.getClassLoader() );
             try {
-                loginContext = (LoginContext)Config.getNonNullEntry
+                LoginContext loginContext = (LoginContext)Config.getNonNullEntry
                                                          (config,
                                                           COMPONENT_NAME,
                                                           "loginContext",
                                                           LoginContext.class);
                 logger.log(Levels.HANDLED,
                            " ***** loginContext retrieved *****");
-                initWithLogin(config, loginContext);
+                return initWithLogin(config, loginContext, activationID, activationSystem);
             } catch (NoSuchEntryException e) {
                 if(secureProto) {
                     logger.log(Levels.HANDLED, " ***** NO loginContext *****");
                 }//endif
-                doInit(config);
+                return doInit(config, null, activationID, activationSystem);
             }
         }//end init
 
-        private void initWithLogin(final Configuration config, 
-                                         LoginContext loginContext)
-                                                             throws Exception
+        private static Init initWithLogin(final Configuration config, 
+                                   final LoginContext loginContext, 
+                                   final ActivationID activationID, 
+                                   final ActivationSystem activationSystem
+                            ) throws LoginException, IOException, ConfigurationException 
         {
             loginContext.login();
             try {
-                Subject.doAsPrivileged
-                                  ( loginContext.getSubject(),
-                                    new PrivilegedExceptionAction() {
-                                        public Object run() throws Exception {
-                                            doInit(config);
-                                            return null;
-                                        }//end run
-                                    },
-                                    null );//end doAsPrivileged
-            } catch (Throwable e) {
-                if(e instanceof PrivilegedExceptionAction) e = e.getCause();
-                if(e instanceof IOException)  throw (IOException)e;
-                if(e instanceof ConfigurationException) 
-                                          throw (ConfigurationException)e;
-                throw new RuntimeException(e);
+                return Subject.doAsPrivileged
+                  ( loginContext.getSubject(),
+                    new PrivilegedExceptionAction<Init>() {
+                        public Init run() throws Exception {
+                            return doInit(  
+                                        config, 
+                                        loginContext, 
+                                        activationID, 
+                                        activationSystem
+                                    );
+                        }//end run
+                    },
+                    null );//end doAsPrivileged
+            } catch (PrivilegedActionException e) {
+                // Previous exception handling was broken, caught Throwable and
+                // checked for instance of PrivilegedExceptionAction,
+                // by mistake.
+                Exception ex = e.getException();
+                if(ex instanceof IOException)  throw (IOException)ex;
+                if(ex instanceof ConfigurationException) 
+                                          throw (ConfigurationException)ex;
+                throw new RuntimeException(ex);
             }
         }//end initWithLogin
+        
+        private static Init doInit( Configuration config, 
+                                    LoginContext loginContext, 
+                                    ActivationID activationID, 
+                                    ActivationSystem activationSystem
+                                  ) throws ConfigurationException, IOException 
+        {
+            return new Init(config, loginContext, activationID, activationSystem);
+        }//end doInit
+        
+        private static class Init {
+            Integer val;
+            Long renewDur;
+            Uuid proxyID;
+            ServiceID serviceID;
+            LookupLocator [] locatorsToJoin;
+            String[] groupsToJoin = DiscoveryGroupManagement.NO_GROUPS;
+            LookupDiscoveryManager ldm;
+            ActivationID activationID;
+            ActivationSystem activationSystem;
+            boolean activationSystemUnregister = false;
+            Exporter serverExporter;
+            LoginContext loginContext;
+            AccessControlContext context;
+            Configuration config;
+            
+            Init(Configuration config, 
+                    LoginContext loginContext,
+                    ActivationID activationID, 
+                    ActivationSystem activationSystem) 
+                    throws ConfigurationException, IOException
+            {
+                this.loginContext = loginContext;
+                this.config = config;
+                val = ((Integer)config.getEntry(COMPONENT_NAME,
+                                                "val",
+                                                int.class,
+                                                Integer.valueOf(0)));
+                renewDur = ((Long)config.getEntry
+                                                (JM_COMPONENT_NAME,
+                                                 "maxLeaseDuration",
+                                                 long.class,
+                                                 Long.valueOf(Lease.FOREVER)));
+                proxyID = UuidFactory.generate();
+                if(proxyID == null) throw new NullPointerException
+                                                              ("proxyID == null");
+
+                String serviceIDStr = (String)Config.getNonNullEntry
+                                                                 (config,
+                                                                  COMPONENT_NAME,
+                                                                  "serviceID",
+                                                                  String.class);
+                serviceID = ConfigUtil.createServiceID(serviceIDStr);
+                locatorsToJoin =
+                         (LookupLocator[])config.getEntry(COMPONENT_NAME, 
+                                                          "locatorsToJoin", 
+                                                          LookupLocator[].class, 
+                                                          new LookupLocator[0]);
+                /* display the overridden config items */
+                logger.log(Levels.HANDLED," TestService-"+val+": service ID = "
+                                      +serviceID);
+                for(int i=0; i<locatorsToJoin.length; i++) {
+                    logger.log(Levels.HANDLED," TestService-"+val+": locsToJoin["
+                                          +i+"] = "+locatorsToJoin[i]);
+                }//end loop
+                if(renewDur == Lease.FOREVER) {
+                    logger.log(Levels.HANDLED,
+                               " TestService-"+val+": lease duration = DEFAULT");
+                } else {
+                    logger.log(Levels.HANDLED,
+                               " TestService-"+val+": lease duration = "
+                               +renewDur);
+                }//endif
 
-        private void doInit(final Configuration config)  throws Exception {
-
-            val = ((Integer)config.getEntry(COMPONENT_NAME,
-                                            "val",
-                                            int.class,
-                                            new Integer(val))).intValue();
-            renewDur = ((Long)config.getEntry
-                                            (JM_COMPONENT_NAME,
-                                             "maxLeaseDuration",
-                                             long.class,
-                                             new Long(renewDur))).longValue();
-            proxyID = UuidFactory.generate();
-            if(proxyID == null) throw new NullPointerException
-                                                          ("proxyID == null");
-
-            String serviceIDStr = (String)Config.getNonNullEntry
-                                                             (config,
-                                                              COMPONENT_NAME,
-                                                              "serviceID",
-                                                              String.class);
-            serviceID = ConfigUtil.createServiceID(serviceIDStr);
-            locatorsToJoin =
-                     (LookupLocator[])config.getEntry(COMPONENT_NAME, 
-                                                      "locatorsToJoin", 
-                                                      LookupLocator[].class, 
-                                                      new LookupLocator[0]);
-            /* display the overridden config items */
-            logger.log(Levels.HANDLED," TestService-"+val+": service ID = "
-                                  +serviceID);
-            for(int i=0; i<locatorsToJoin.length; i++) {
-                logger.log(Levels.HANDLED," TestService-"+val+": locsToJoin["
-                                      +i+"] = "+locatorsToJoin[i]);
-            }//end loop
-            if(renewDur == Lease.FOREVER) {
-                logger.log(Levels.HANDLED,
-                           " TestService-"+val+": lease duration = DEFAULT");
-            } else {
-                logger.log(Levels.HANDLED,
-                           " TestService-"+val+": lease duration = "
-                           +renewDur);
-            }//endif
-
-            ldm = new LookupDiscoveryManager(groupsToJoin, locatorsToJoin,
-                                             null, config);
+                ldm = new LookupDiscoveryManager(groupsToJoin, locatorsToJoin,
+                                                 null, config);
 
-            ServerEndpoint endpoint = TcpServerEndpoint.getInstance(0);
-            InvocationLayerFactory ilFactory = new BasicILFactory();
-            Exporter defaultExporter = new BasicJeriExporter(endpoint,
-                                                             ilFactory,
-                                                             false,
-                                                             true);
-            if(activationID != null) {
-                ProxyPreparer aidPreparer =
-                  (ProxyPreparer)Config.getNonNullEntry
-                                                   (config,
-                                                    COMPONENT_NAME,
-                                                    "activationIdPreparer",
-                                                    ProxyPreparer.class,
-                                                    new BasicProxyPreparer());
-                ProxyPreparer aSysPreparer = 
-                  (ProxyPreparer)Config.getNonNullEntry
-                                                   (config,
-                                                    COMPONENT_NAME,
-                                                    "activationSystemPreparer",
-                                                    ProxyPreparer.class,
-                                                    new BasicProxyPreparer());
-                activationID = (ActivationID)aidPreparer.prepareProxy
-                                                               (activationID);
-                activationSystem = (ActivationSystem)aSysPreparer.prepareProxy
-                                                            (activationSystem);
-                defaultExporter = new ActivationExporter(activationID,
-                                                         defaultExporter);
-            }//endif(activationID != null)
-            try {
-                serverExporter = (Exporter)Config.getNonNullEntry
-                                                             (config,
-                                                              COMPONENT_NAME,
-                                                              "serverExporter",
-                                                              Exporter.class,
-                                                              defaultExporter);
-            } catch(ConfigurationException e) {
-                throw new ExportException("Configuration exception while "
-                                          +"retrieving service's exporter",
-                                          e);
+                ServerEndpoint endpoint = TcpServerEndpoint.getInstance(0);
+                InvocationLayerFactory ilFactory = new BasicILFactory();
+                Exporter defaultExporter = new BasicJeriExporter(endpoint,
+                                                                 ilFactory,
+                                                                 false,
+                                                                 true);
+                if(activationID != null) {
+                    ProxyPreparer aidPreparer =
+                      (ProxyPreparer)Config.getNonNullEntry
+                                                       (config,
+                                                        COMPONENT_NAME,
+                                                        "activationIdPreparer",
+                                                        ProxyPreparer.class,
+                                                        new BasicProxyPreparer());
+                    ProxyPreparer aSysPreparer = 
+                      (ProxyPreparer)Config.getNonNullEntry
+                                                       (config,
+                                                        COMPONENT_NAME,
+                                                        "activationSystemPreparer",
+                                                        ProxyPreparer.class,
+                                                        new BasicProxyPreparer());
+                    this.activationID = (ActivationID)aidPreparer.prepareProxy
+                                                                   (activationID);
+                    this.activationSystem = (ActivationSystem)aSysPreparer.prepareProxy
+                                                                (activationSystem);
+                    defaultExporter = new ActivationExporter(activationID,
+                                                             defaultExporter);
+                    activationSystemUnregister = true;
+                }//endif(activationID != null)
+                try {
+                    serverExporter = (Exporter)Config.getNonNullEntry
+                                                                 (config,
+                                                                  COMPONENT_NAME,
+                                                                  "serverExporter",
+                                                                  Exporter.class,
+                                                                  defaultExporter);
+                } catch(ConfigurationException e) {
+                    throw new ExportException("Configuration exception while "
+                                              +"retrieving service's exporter",
+                                              e);
+                }
+                context = AccessController.getContext();
             }
-            innerProxy =
-                   (RemoteTestServiceInterface)serverExporter.export(this);
-            outerProxy = TestServiceProxy.createTestServiceProxy
-                                          (innerProxy, proxyID, val, renewDur);
-            joinMgr = new JoinManager(outerProxy, null, serviceID,
-                                      ldm, null, config);
-        }//end doInit
+            
+        }
 
-        public TrustVerifier getProxyVerifier() {
+        public synchronized TrustVerifier getProxyVerifier() {
             return new ProxyVerifier(innerProxy, proxyID);
         }//end getProxyVerifier
 
-        public Object getProxy() {
+        public synchronized Object getProxy() {
             return innerProxy;
         }//end getProxy
 
-        public Object getServiceProxy() {
+        public synchronized Object getServiceProxy() {
             return outerProxy;
         }//end getServiceProxy
 

Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/TestGeneratorImpl.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/TestGeneratorImpl.java?rev=1488180&r1=1488179&r2=1488180&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/TestGeneratorImpl.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/TestGeneratorImpl.java Fri May 31 11:45:48 2013
@@ -24,6 +24,7 @@ import com.sun.jini.landlord.LeaseFactor
 import com.sun.jini.landlord.LeasePeriodPolicy;
 import com.sun.jini.landlord.LeasedResource;
 import com.sun.jini.landlord.FixedLeasePeriodPolicy;
+import com.sun.jini.start.Starter;
 import net.jini.config.Configuration;
 import net.jini.config.ConfigurationException;
 import net.jini.config.ConfigurationProvider;
@@ -40,6 +41,8 @@ import java.rmi.MarshalledObject;
 import java.rmi.NoSuchObjectException;
 import java.rmi.server.RemoteObject;
 import java.rmi.server.UnicastRemoteObject;
+import java.security.AccessControlContext;
+import java.security.AccessController;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 import java.util.ArrayList;
@@ -66,7 +69,7 @@ import net.jini.core.lease.LeaseMapExcep
 import net.jini.export.ProxyAccessor;
 
 public class TestGeneratorImpl 
-    implements TestGenerator, Landlord, TimeConstants, ProxyAccessor
+    implements TestGenerator, Landlord, TimeConstants, ProxyAccessor, Starter
 {
 
     private static Logger logger = Logger.getLogger("com.sun.jini.qa.harness");
@@ -74,7 +77,7 @@ public class TestGeneratorImpl 
     private static final String GENERATOR = 
         "com.sun.jini.test.impl.mercury.generator";
 
-    private Map regs = Collections.synchronizedMap(new HashMap());
+    private Map regs = new HashMap();
 
     private Exporter exporter;
 
@@ -87,8 +90,11 @@ public class TestGeneratorImpl 
     Uuid generatorUuid = null;
 
     LeaseFactory leaseFactory;
+    
+    AccessControlContext context;
+    private boolean started;
 
-    public Object getProxy() { return serverStub; }
+    public synchronized Object getProxy() { return serverStub; }
 
     public TestGeneratorImpl(String[] configArgs, LifeCycle lc) 
 	throws Exception 
@@ -139,16 +145,13 @@ public class TestGeneratorImpl 
 				  new BasicILFactory(), 
 				  false, 
 				  true));
-        // Export server instance and get its reference
-        serverStub = (TestGenerator)exporter.export(this);
 	generatorUuid = UuidFactory.generate();
-	leaseFactory = new LeaseFactory((Landlord) serverStub, generatorUuid);
         generatorLeasePolicy =
             new FixedLeasePeriodPolicy(
                 20 * MINUTES,     // Maximum lease is 2 minutes
                 1 * MINUTES      // Default lease is 1 hour
             );
-	
+	context = AccessController.getContext();
     }
 
     protected Object getNonNullEntry(Configuration config,
@@ -166,7 +169,7 @@ public class TestGeneratorImpl 
         return result;
     }
 
-    public EventRegistration register(long evID, MarshalledObject handback,
+    public synchronized EventRegistration register(long evID, MarshalledObject handback,
 					RemoteEventListener toInform,
 					long leaseLength)
 	throws UnknownEventException, LeaseDeniedException
@@ -181,11 +184,11 @@ public class TestGeneratorImpl 
 					lease, reg.getSequenceNumber());
     }
 
-    private Uuid leaseUuid(long evID) {
+    private synchronized Uuid leaseUuid(long evID) {
 	return UuidFactory.create(generatorUuid.getLeastSignificantBits(), evID);
     }
 
-    public RemoteEvent generateEvent(long evID, int maxTries)
+    public synchronized RemoteEvent generateEvent(long evID, int maxTries)
 	throws RemoteException, UnknownEventException
     {
 	TestRegistration reg = null;
@@ -241,7 +244,7 @@ public class TestGeneratorImpl 
     // LandLord methods
     //-----------------------
 
-    public long renew(Uuid cookie, long extension)
+    public synchronized long renew(Uuid cookie, long extension)
         throws LeaseDeniedException, UnknownLeaseException, RemoteException {
 	TestRegistration reg = (TestRegistration) regs.get(cookie);
 	synchronized (reg) {
@@ -285,7 +288,7 @@ public class TestGeneratorImpl 
 	}
     }
 
-    public void cancel(Uuid cookie)
+    public synchronized void cancel(Uuid cookie)
         throws UnknownLeaseException 
     {
 	TestRegistration reg = (TestRegistration) regs.remove(cookie);
@@ -309,11 +312,28 @@ public class TestGeneratorImpl 
 	return map;
     }
 
+    @Override
+    public final synchronized void start() throws Exception {
+        if (started) return;
+        started = true;
+        AccessController.doPrivileged(new PrivilegedExceptionAction<Object>(){
+
+            @Override
+            public Object run() throws Exception {
+                // Export server instance and get its reference
+                serverStub = (TestGenerator)exporter.export(TestGeneratorImpl.this);
+                leaseFactory = new LeaseFactory((Landlord) serverStub, generatorUuid);
+                return null;
+            }
+            
+        }, context);
+    }
+
 
     private class TestRegistration implements LeasedResource {
-	private Uuid uuid;
-	private MarshalledObject handback;
-	private RemoteEventListener toInform;
+	final private Uuid uuid;
+	final private MarshalledObject handback;
+	final private RemoteEventListener toInform;
 	private long expiration;
 	private long sequenceNumber;
 

Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/TestListenerImpl.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/TestListenerImpl.java?rev=1488180&r1=1488179&r2=1488180&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/TestListenerImpl.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/TestListenerImpl.java Fri May 31 11:45:48 2013
@@ -19,6 +19,7 @@ package com.sun.jini.test.impl.mercury;
 
 import com.sun.jini.proxy.BasicProxyTrustVerifier;
 import com.sun.jini.start.LifeCycle;
+import com.sun.jini.start.Starter;
 
 import net.jini.config.Configuration;
 import net.jini.config.ConfigurationException;
@@ -38,6 +39,8 @@ import net.jini.core.event.RemoteEventLi
 import java.rmi.Remote;
 import java.rmi.RemoteException;
 import java.rmi.server.UnicastRemoteObject;
+import java.security.AccessControlContext;
+import java.security.AccessController;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 import java.util.Collections;
@@ -50,9 +53,9 @@ import javax.security.auth.login.LoginEx
 
 
 public class TestListenerImpl
-    implements TestListener, ProxyAccessor, ServerProxyTrust
+    implements TestListener, ProxyAccessor, ServerProxyTrust, Starter
 {
-    private Map events = Collections.synchronizedMap(new HashMap());
+    private final Map events = new HashMap();
 
     private Exporter exporter;
     
@@ -60,8 +63,11 @@ public class TestListenerImpl
 
     private static final String LISTENER = 
         "com.sun.jini.test.impl.mercury.listener";
+    private boolean started;
+    
+    private AccessControlContext context;
 
-    public Object getProxy() { return serverStub; }
+    public synchronized Object getProxy() { return serverStub; }
 
     public TestListenerImpl(String[] configArgs, LifeCycle lc) throws Exception {
         final Configuration config =
@@ -110,8 +116,7 @@ public class TestListenerImpl
 				  new BasicILFactory(), 
 				  false, 
 				  true));
-        // Export server instance and get its reference
-        serverStub = (TestListener)exporter.export(this);
+        context = AccessController.getContext();
     }
 
     protected Object getNonNullEntry(Configuration config,
@@ -132,7 +137,7 @@ public class TestListenerImpl
     //
     // RemoteEventListener methods
     //
-    public void notify(RemoteEvent theEvent)
+    public synchronized void notify(RemoteEvent theEvent)
 	throws UnknownEventException, RemoteException
     {
 	//System.out.println(name + "::notify() - receiving event");
@@ -159,7 +164,10 @@ public class TestListenerImpl
 	RemoteEventHandle key = new RemoteEventHandle(theEvent);
 
         // See if we already have the handle
-	RemoteEventHandle incoming = (RemoteEventHandle) events.get(key);
+	RemoteEventHandle incoming;
+        synchronized (this){
+            incoming = (RemoteEventHandle) events.get(key);
+        }
 
         //String s = (incoming ==null) ? "not found" : "found";
 	//System.out.println("Event was " + s + ":" + incoming);
@@ -170,15 +178,31 @@ public class TestListenerImpl
 	    return true; // have it
     }
 
-    public long getEventCount() throws RemoteException {
+    public synchronized long getEventCount() throws RemoteException {
         int size = events.size();
 	// System.out.println(name + "::getEventCount() - " + size);
 	return size;
     }
 
-    public TrustVerifier getProxyVerifier() {
+    public synchronized TrustVerifier getProxyVerifier() {
 	return new BasicProxyTrustVerifier(serverStub);
     }
+
+    @Override
+    public final synchronized void start() throws Exception {
+        if (started) return;
+        started = true;
+        AccessController.doPrivileged(new PrivilegedExceptionAction<Object>(){
+
+            @Override
+            public Object run() throws Exception {
+                // Export server instance and get its reference
+                serverStub = (TestListener)exporter.export(TestListenerImpl.this);
+                return null;
+            }
+            
+        }, context);
+    }
 }
 
 

Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/TestPullListenerImpl.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/TestPullListenerImpl.java?rev=1488180&r1=1488179&r2=1488180&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/TestPullListenerImpl.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/TestPullListenerImpl.java Fri May 31 11:45:48 2013
@@ -18,6 +18,7 @@
 package com.sun.jini.test.impl.mercury;
 import com.sun.jini.proxy.BasicProxyTrustVerifier;
 import com.sun.jini.start.LifeCycle;
+import com.sun.jini.start.Starter;
 
 import net.jini.config.Configuration;
 import net.jini.config.ConfigurationException;
@@ -37,6 +38,8 @@ import net.jini.core.event.RemoteEventLi
 import java.rmi.Remote;
 import java.rmi.RemoteException;
 import java.rmi.server.UnicastRemoteObject;
+import java.security.AccessControlContext;
+import java.security.AccessController;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 import java.util.ArrayList;
@@ -53,20 +56,23 @@ import net.jini.event.MailboxPullRegistr
 import net.jini.event.InvalidIteratorException;
 
 public class TestPullListenerImpl 
-    implements TestPullListener, ProxyAccessor, ServerProxyTrust
+    implements TestPullListener, ProxyAccessor, ServerProxyTrust, Starter
 {
-    private Map events = Collections.synchronizedMap(new HashMap());
+    private final Map events = new HashMap();
 
     private Exporter exporter;
     
-    protected TestPullListener serverStub;
+    private TestPullListener serverStub;
 
     private static final String LISTENER = 
         "com.sun.jini.test.impl.mercury.listener";
+    
+    private AccessControlContext context;
+    private boolean started;
 
-    public Object getProxy() { return serverStub; }
+    public synchronized Object getProxy() { return serverStub; }
     
-    public TrustVerifier getProxyVerifier() {
+    public synchronized TrustVerifier getProxyVerifier() {
 	return new BasicProxyTrustVerifier(serverStub);
     }    
 
@@ -117,8 +123,7 @@ public class TestPullListenerImpl 
 				  new BasicILFactory(), 
 				  false, 
 				  true));
-        // Export server instance and get its reference
-        serverStub = (TestPullListener)exporter.export(this);
+        context = AccessController.getContext();
     }
 
     protected Object getNonNullEntry(Configuration config,
@@ -153,12 +158,15 @@ public class TestPullListenerImpl 
 	RemoteEventHandle key = new RemoteEventHandle(theEvent);
 
         // See if we already have the handle
-	RemoteEvent incoming = (RemoteEvent) events.get(key);
-
+        RemoteEvent incoming;
+        String eventString;
+        synchronized (events) {
+            incoming = (RemoteEvent) events.get(key);
+            eventString = events.toString();
+        }
         String s = (incoming ==null) ? "not found" : "found";
-	System.out.println("Desired event was " + s + ": " + key);
-	System.out.println("Events are:" + events.toString());
-
+        System.out.println("Desired event was " + s + ": " + key);
+        System.out.println("Events are:" + eventString);
 	if (incoming == null)
 	    return false; // don't have it
 	else
@@ -171,21 +179,43 @@ public class TestPullListenerImpl 
         ArrayList al = new ArrayList();
 	net.jini.event.RemoteEventIterator ri = 
 	    mr.getRemoteEvents();
-	for ( RemoteEvent event = ri.next(5000L); 
-	      event != null; 
-	      event = ri.next(5000L)) {
-	    events.put(new RemoteEventHandle(event), event); 
-            al.add(event);
-	}
+        synchronized (events){
+            for ( RemoteEvent event = ri.next(5000L); 
+                  event != null; 
+                  event = ri.next(5000L)) {
+                events.put(new RemoteEventHandle(event), event); 
+                al.add(event);
+            }
+        }
 	return al;
     }
     
     public Collection getCollectedRemoteEvents() {
-	return Collections.list(Collections.enumeration(events.values()));
+        synchronized (events){
+            return new ArrayList(events.values());
+        }
     }
 
     public int getCollectedRemoteEventsSize() {
-	return events.size();
+        synchronized (events){
+            return events.size();
+        }
+    }
+
+    @Override
+    public final synchronized void start() throws Exception {
+        if (started) return;
+        started = true;
+        AccessController.doPrivileged(new PrivilegedExceptionAction<Object>(){
+
+            @Override
+            public Object run() throws Exception {
+                // Export server instance and get its reference
+                serverStub = (TestPullListener) exporter.export(TestPullListenerImpl.this);
+                return null;
+            }
+            
+        }, context);
     }
 
 }

Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/start/BadServiceProxyAccessorImpl.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/start/BadServiceProxyAccessorImpl.java?rev=1488180&r1=1488179&r2=1488180&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/start/BadServiceProxyAccessorImpl.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/start/BadServiceProxyAccessorImpl.java Fri May 31 11:45:48 2013
@@ -20,6 +20,7 @@ package com.sun.jini.test.impl.start;
 import com.sun.jini.proxy.BasicProxyTrustVerifier;
 import com.sun.jini.start.LifeCycle;
 import com.sun.jini.start.ServiceProxyAccessor;
+import com.sun.jini.start.Starter;
 
 import net.jini.config.Configuration;
 import net.jini.config.ConfigurationException;
@@ -41,6 +42,8 @@ import java.rmi.MarshalledObject;
 import java.rmi.Remote;
 import java.rmi.RemoteException;
 import java.rmi.server.UnicastRemoteObject;
+import java.security.AccessControlContext;
+import java.security.AccessController;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 import java.util.Collections;
@@ -52,22 +55,26 @@ import javax.security.auth.login.LoginCo
 import javax.security.auth.login.LoginException;
 
 
+
 public class BadServiceProxyAccessorImpl 
-    implements BadServiceProxyAccessor, ProxyAccessor
+    implements BadServiceProxyAccessor, ProxyAccessor, Starter
 {
-    protected Object serverStub;
+    private Object serverStub;
+    private AccessControlContext context;
 
     private static final String BAD_SPA = 
         "com.sun.jini.test.impl.mercury.badSPA";
+    private Exporter exporter;
+    private boolean started;
 
     // ProxyAccessor - for activation code
-    public Object getProxy() { return serverStub; }
+    public synchronized Object getProxy() { return serverStub; }
 
     // ServiceProxyAccessor - for ServiceStarter code
     public Object getServiceProxy() { return null; }
 
     // ServerProxyTrust - for proxy preparation
-    public TrustVerifier getProxyVerifier() {
+    public synchronized TrustVerifier getProxyVerifier() {
 	return new BasicProxyTrustVerifier(serverStub);
     }
     // Activatable constructor
@@ -132,14 +139,13 @@ public class BadServiceProxyAccessorImpl
 
     /** Initialization common to both activatable and transient instances. */
     private void doInit(Configuration config) throws Exception {
-        Exporter exporter = (Exporter) getNonNullEntry(
+        exporter = (Exporter) getNonNullEntry(
             config, "exporter", Exporter.class,
             new BasicJeriExporter(TcpServerEndpoint.getInstance(0), 
 				  new BasicILFactory(), 
 				  false, 
 				  true));
-        // Export server instance and get its reference
-        serverStub = exporter.export(this);
+        context = AccessController.getContext();
     }
 
     protected Object getNonNullEntry(Configuration config,
@@ -157,6 +163,21 @@ public class BadServiceProxyAccessorImpl
         return result;
     }
 
+    @Override
+    public final synchronized void start() throws Exception {
+        if (started) return;
+        started = true;
+        AccessController.doPrivileged(new PrivilegedExceptionAction<Object>(){
+
+            @Override
+            public Object run() throws Exception {
+                // Export server instance and get its reference
+                serverStub =  exporter.export(BadServiceProxyAccessorImpl.this);
+                return null;
+            }
+            
+        }, context);
+    }
 }
 
 

Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/start/TestServiceImpl.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/start/TestServiceImpl.java?rev=1488180&r1=1488179&r2=1488180&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/start/TestServiceImpl.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/start/TestServiceImpl.java Fri May 31 11:45:48 2013
@@ -26,6 +26,7 @@ import java.rmi.MarshalledObject;
 import com.sun.jini.config.Config;
 import com.sun.jini.test.impl.start.TestService;
 import com.sun.jini.start.LifeCycle;
+import com.sun.jini.start.Starter;
 import net.jini.config.Configuration;
 import net.jini.config.ConfigurationException;
 import net.jini.config.ConfigurationProvider;
@@ -45,6 +46,8 @@ import java.io.FileInputStream;
 import java.io.ByteArrayOutputStream;
 import java.net.URL;
 import java.net.URLClassLoader;
+import java.security.AccessControlContext;
+import java.security.AccessController;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 import java.security.SecureClassLoader;
@@ -57,7 +60,7 @@ import javax.security.auth.login.LoginEx
 /**
  * Activatable implementation of the TestService interface.
  */
-public class TestServiceImpl implements TestService, ProxyAccessor {
+public class TestServiceImpl implements TestService, ProxyAccessor, Starter {
 
     private static volatile int staticInt = 0;
     
@@ -66,8 +69,11 @@ public class TestServiceImpl implements 
     private TestService serverStub = null;
 
     private static final String TEST_SERVICE = "com.sun.jini.testservice";
+    private boolean started;
+    private Exporter exporter;
+    private AccessControlContext context;
 
-    public Object getProxy() { return serverStub; }
+    public synchronized Object getProxy() { return serverStub; }
 
     // Activation constructor
     public TestServiceImpl(ActivationID activationID, MarshalledObject data)
@@ -124,19 +130,16 @@ public class TestServiceImpl implements 
     private void doInit(Configuration config) throws Exception {
         uuid = net.jini.id.UuidFactory.generate();
 
-        Exporter exporter = (Exporter) Config.getNonNullEntry(
+        exporter = (Exporter) Config.getNonNullEntry(
             config, TEST_SERVICE, "exporter", Exporter.class,
             new BasicJeriExporter(
                 TcpServerEndpoint.getInstance(0), new BasicILFactory(), false, true));
         System.out.println("service exporter is: "
             +  exporter);
-        // Export server instance and get its reference
-        serverStub = (TestService)exporter.export(this);
-        System.out.println("Service stub is: " + serverStub);
+        context = AccessController.getContext();
         
         // Store class loader ref in shared map
-        TestServiceSharedMap.storeClassLoader(
-            uuid, this.getClass().getClassLoader());
+        TestServiceSharedMap.storeClassLoader(uuid, this.getClass().getClassLoader());
     }
 
     // inherit javadoc
@@ -204,8 +207,11 @@ public class TestServiceImpl implements 
     {
         boolean result = false;
 	try {
-            ClassLoader thisClassLoader = 
-                (ClassLoader) TestServiceSharedMap.getClassLoader(uuid);
+            ClassLoader thisClassLoader;
+            synchronized (this){
+                thisClassLoader = 
+                    (ClassLoader) TestServiceSharedMap.getClassLoader(uuid);
+            }
             ClassLoader otherClassLoader = 
                 (ClassLoader) TestServiceSharedMap.getClassLoader(other);
             ArrayList thisLoaders = new ArrayList();
@@ -240,7 +246,24 @@ public class TestServiceImpl implements 
         l.add(c);
     }
     
-    public Uuid getUuid() throws RemoteException {
+    public synchronized Uuid getUuid() throws RemoteException {
         return uuid;
     }
+
+    @Override
+    public final synchronized void start() throws Exception {
+        if (started) return;
+        started = true;
+        AccessController.doPrivileged(new PrivilegedExceptionAction<Object>(){
+
+            @Override
+            public Object run() throws Exception {
+                // Export server instance and get its reference
+                serverStub =  (TestService) exporter.export(TestServiceImpl.this);
+                System.out.println("Service stub is: " + serverStub);
+                return null;
+            }
+            
+        }, context);
+    }
 }

Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/services/lookupsimulator/LookupSimulatorImpl.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/services/lookupsimulator/LookupSimulatorImpl.java?rev=1488180&r1=1488179&r2=1488180&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/services/lookupsimulator/LookupSimulatorImpl.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/services/lookupsimulator/LookupSimulatorImpl.java Fri May 31 11:45:48 2013
@@ -60,6 +60,9 @@ import com.sun.jini.start.LifeCycle;
 import net.jini.security.proxytrust.ServerProxyTrust;
 
 import com.sun.jini.config.Config;
+import com.sun.jini.start.Starter;
+import java.security.AccessControlContext;
+import java.security.AccessController;
 import net.jini.export.Exporter;
 import net.jini.export.ProxyAccessor;
 import net.jini.config.Configuration;
@@ -97,7 +100,8 @@ import net.jini.jeri.tcp.TcpServerEndpoi
  */
 public class LookupSimulatorImpl implements LookupSimulator, 
 					    ServerProxyTrust,
-					    ProxyAccessor
+					    ProxyAccessor,
+                                            Starter
 {
     private static Logger logger = Logger.getLogger("com.sun.jini.harness.test");
     private MethodConstraints locatorConstraints;
@@ -117,12 +121,14 @@ public class LookupSimulatorImpl impleme
     /** 64-bit buffer for use with secRand */
     private final byte[] secRandBuf8 = new byte[8];
     /* For synchronization instead of ReadersWriter locks used by reggie */
-    private Object lockObject = new Object();
-    private String unsupportedOperation = 
+    private final Object lockObject = new Object();
+    private final String unsupportedOperation = 
         "lookup service is a simulation; does not support requested operation";
     private LifeCycle lifeCycle;
     private LoginContext loginContext;
     boolean noneConfiguration;
+    private boolean started;
+    private AccessControlContext context;
 
     public LookupSimulatorImpl(ActivationID activationID, 
 			       MarshalledObject data)
@@ -205,11 +211,11 @@ public class LookupSimulatorImpl impleme
     }//end constructor
 
     // This method's javadoc is inherited from an interface of this class
-    public TrustVerifier getProxyVerifier() {
+    public synchronized TrustVerifier getProxyVerifier() {
 	return new LookupSimulatorProxyVerifier(myRef);
     }
 
-    public LookupLocator getConstrainedLocator(String host, int port) 
+    public synchronized LookupLocator getConstrainedLocator(String host, int port) 
     {
 	return new ConstrainableLookupLocator(host, port, locatorConstraints);
     }
@@ -222,7 +228,7 @@ public class LookupSimulatorImpl impleme
 	return getConstrainedLocator(loc.getHost(), loc.getPort());
     }
 
-    public LookupLocator getConstrainedLocator(String url) 
+    public synchronized LookupLocator getConstrainedLocator(String url) 
 	throws MalformedURLException
     {
 	return new ConstrainableLookupLocator(url, locatorConstraints);
@@ -233,11 +239,11 @@ public class LookupSimulatorImpl impleme
      *
      * @return the proxy
      */
-    public Object getServiceProxy() throws RemoteException {
+    public synchronized Object getServiceProxy() throws RemoteException {
 	return proxy;
     }
 
-    public Object getProxy() {
+    public synchronized Object getProxy() {
 	return myRef;
     }
 
@@ -279,7 +285,7 @@ public class LookupSimulatorImpl impleme
         throw new UnsupportedOperationException(unsupportedOperation);
     }//end getServiceTypes
 
-    public ServiceID getServiceID()  throws RemoteException {
+    public synchronized ServiceID getServiceID()  throws RemoteException {
         return serviceID;
     }//end getServiceID
 
@@ -299,7 +305,7 @@ public class LookupSimulatorImpl impleme
     /* DiscoveryAdmin methods */
     public String[] getMemberGroups() throws RemoteException {
         synchronized(lockObject) {
-            return memberGroups;
+            return memberGroups.clone();
         }//end sync
     }//end getGroups
     public void addMemberGroups(String[] groups) throws RemoteException {
@@ -383,10 +389,8 @@ public class LookupSimulatorImpl impleme
 						  Exporter.class,
 						  Configuration.NO_DEFAULT,
 						  activationID);
+            context = AccessController.getContext();
 	}
-	myRef = (LookupSimulator) serverExporter.export(this);
-        if (serviceID == null) serviceID = newServiceID();
-	proxy = LookupSimulatorProxy.getInstance(myRef, serviceID);
     }//end init
 
     /** Generate a new UUID */
@@ -443,6 +447,23 @@ public class LookupSimulatorImpl impleme
         return arr;
     }//end removeDups
 
+    @Override
+    public final synchronized void start() throws Exception {
+        if (started) return;
+        started = true;
+        AccessController.doPrivileged(new PrivilegedExceptionAction<Object>(){
+
+            @Override
+            public Object run() throws Exception {
+                myRef = (LookupSimulator) serverExporter.export(LookupSimulatorImpl.this);
+                if (serviceID == null) serviceID = newServiceID();
+                proxy = LookupSimulatorProxy.getInstance(myRef, serviceID);
+                return null;
+            }
+            
+        }, context);
+    }
+
     private class DestroyThread extends Thread {
         /** Create a non-daemon thread */
         public DestroyThread() {
@@ -450,33 +471,43 @@ public class LookupSimulatorImpl impleme
             setDaemon(false); // override inheritance from RMI daemon thread
         }//end constructor
         public void run() {
-            /* must unregister before unexport */
-            if (activationID != null) {
-                try {
-                    activationSystem.unregisterObject(activationID);
-                } catch (RemoteException e) {
-                    return;// give up until we can at least unregister
-                } catch (ActivationException e) { }
-            }//endif
-	    while (!serverExporter.unexport(false)) {
-		Thread.yield();
-	    }
-            if (activationID != null) {
-                try {
-                    while (!Activatable.inactive(activationID)) {
-                        Thread.yield();
-                    }//end loop
-                } catch (RemoteException e) {
-                } catch (ActivationException e) { }
-            }
-	    if (lifeCycle != null) {
-		lifeCycle.unregister(LookupSimulatorImpl.this);
-	    }
-            if (loginContext != null) {
-                try {
-                    loginContext.logout();
-                } catch (LoginException e) {
-                    logger.log(Level.FINE, "logout failed", e);
+            synchronized (LookupSimulatorImpl.this){
+                /* must unregister before unexport */
+                if (activationID != null) {
+                    try {
+                        activationSystem.unregisterObject(activationID);
+                    } catch (RemoteException e) {
+                        return;// give up until we can at least unregister
+                    } catch (ActivationException e) { }
+                }//endif
+                while (!serverExporter.unexport(false)) {
+                    try {
+                        LookupSimulatorImpl.this.wait(10);
+                    } catch (InterruptedException ex) {
+                        Thread.currentThread().interrupt();// restore interrupt.
+                    }
+                }
+                if (activationID != null) {
+                    try {
+                        while (!Activatable.inactive(activationID)) {
+                            try {
+                                LookupSimulatorImpl.this.wait(10);
+                            } catch (InterruptedException ex) {
+                                Thread.currentThread().interrupt();// restore interrupt.
+                            }
+                        }//end loop
+                    } catch (RemoteException e) {
+                    } catch (ActivationException e) { }
+                }
+                if (lifeCycle != null) {
+                    lifeCycle.unregister(LookupSimulatorImpl.this);
+                }
+                if (loginContext != null) {
+                    try {
+                        loginContext.logout();
+                    } catch (LoginException e) {
+                        logger.log(Level.FINE, "logout failed", e);
+                    }
                 }
             }
         }

Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/discoveryservice/AbstractBaseTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/discoveryservice/AbstractBaseTest.java?rev=1488180&r1=1488179&r2=1488180&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/discoveryservice/AbstractBaseTest.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/discoveryservice/AbstractBaseTest.java Fri May 31 11:45:48 2013
@@ -760,11 +760,11 @@ abstract public class AbstractBaseTest e
             proxy = exporter.export(this);
         }
 
-	public Object writeReplace() throws ObjectStreamException {
+	public synchronized Object writeReplace() throws ObjectStreamException {
 	    return proxy;
 	}
 
-	public TrustVerifier getProxyVerifier() {
+	public synchronized TrustVerifier getProxyVerifier() {
 	    return new BasicProxyTrustVerifier(proxy);
 	}
 

Modified: river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/ActivateWrapper.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/ActivateWrapper.java?rev=1488180&r1=1488179&r2=1488180&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/ActivateWrapper.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/ActivateWrapper.java Fri May 31 11:45:48 2013
@@ -194,7 +194,7 @@ public class ActivateWrapper implements 
      * The "wrapped" activatable object.
      * @serial
      */
-    private /*final*/ Object impl;
+    private final Object impl;
 
     /**
      * The parameter types for the "activation constructor".
@@ -470,6 +470,23 @@ public class ActivateWrapper implements 
 		constructor.setAccessible(true);
 		impl =
 		    constructor.newInstance(new Object[]{id, desc.data});
+                if (impl instanceof Starter) {
+                    ((Starter) impl).start();
+                } else {
+                    logger.log( Level.SEVERE,
+                        "Service {0} doesn''t implement {1} {2} {3} {4} {5} {6}", 
+                        new Object []
+                            {
+                                impl.getClass().getCanonicalName(),
+                                Starter.class.getCanonicalName(),
+                                "this service is likely to suffer from race",
+                                "conditions caused by export performed during", 
+                                "construction, or threads started while ''this''",
+                                "has been allowed to escape during construction",
+                                "https://www.securecoding.cert.org/confluence/display/java/TSM01-J.+Do+not+let+the+this+reference+escape+during+object+construction"
+                            } 
+                    );
+                }
  	        logger.log(Level.FINEST, 
 		    "Obtained implementation instance: {0}", impl);
 	    } finally {

Modified: river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/NonActivatableServiceDescriptor.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/NonActivatableServiceDescriptor.java?rev=1488180&r1=1488179&r2=1488180&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/NonActivatableServiceDescriptor.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/NonActivatableServiceDescriptor.java Fri May 31 11:45:48 2013
@@ -676,7 +676,23 @@ public class NonActivatableServiceDescri
                 constructor);
             constructor.setAccessible(true);
             impl = constructor.newInstance(argParms);
-            if (impl instanceof Starter) ((Starter) impl).start();
+            if (impl instanceof Starter) {
+                ((Starter) impl).start();
+            } else {
+                logger.log( Level.SEVERE,
+                    "Service {0} doesn''t implement {1} {2} {3} {4} {5} {6}", 
+                    new Object []
+                        {
+                            impl.getClass().getCanonicalName(),
+                            Starter.class.getCanonicalName(),
+                            "this service is likely to suffer from race",
+                            "conditions caused by export performed during", 
+                            "construction, or threads started while ''this''",
+                            "has been allowed to escape during construction",
+                            "https://www.securecoding.cert.org/confluence/display/java/TSM01-J.+Do+not+let+the+this+reference+escape+during+object+construction"
+                        } 
+                );
+            }
             logger.log(Level.FINEST,
                 "Obtained implementation instance: {0}", impl);
             if (impl instanceof ServiceProxyAccessor) {

Modified: river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/ServiceStarter.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/ServiceStarter.java?rev=1488180&r1=1488179&r2=1488180&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/ServiceStarter.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/ServiceStarter.java Fri May 31 11:45:48 2013
@@ -285,7 +285,6 @@ public class ServiceStarter {
 	    try {
    	        if (desc != null) {
 		    result = desc.create(config);
-                    if (result instanceof Starter) ((Starter) result).start();
 	        } 
 	    } catch (Exception e) {
 	        problem = e;

Modified: river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/SharedGroupImpl.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/SharedGroupImpl.java?rev=1488180&r1=1488179&r2=1488180&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/SharedGroupImpl.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/SharedGroupImpl.java Fri May 31 11:45:48 2013
@@ -18,21 +18,37 @@
 
 package com.sun.jini.start;
 
+import java.io.IOException;
 import java.rmi.MarshalledObject;
 import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.rmi.activation.ActivationException;
+import java.rmi.activation.ActivationGroup;
 import java.rmi.activation.ActivationID;
 import java.rmi.activation.ActivationSystem;
+import java.rmi.server.ExportException;
+import java.security.AccessControlContext;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import javax.security.auth.Subject;
 import javax.security.auth.login.LoginContext;
 import net.jini.activation.ActivationExporter;
+import net.jini.config.Configuration;
+import net.jini.config.ConfigurationException;
+import net.jini.config.ConfigurationProvider;
+import net.jini.core.constraint.RemoteMethodControl;
 import net.jini.export.Exporter;
+import net.jini.export.ProxyAccessor;
 import net.jini.jeri.BasicILFactory;
 import net.jini.jeri.BasicJeriExporter;
 import net.jini.jeri.tcp.TcpServerEndpoint;
 import net.jini.security.BasicProxyPreparer;
 import net.jini.security.ProxyPreparer;
+import net.jini.security.TrustVerifier;
+import net.jini.security.proxytrust.ServerProxyTrust;
 
 /**
  * The provided implementation
@@ -174,14 +190,238 @@ import net.jini.security.ProxyPreparer;
  * @author Sun Microsystems, Inc.
  *
  */
-public class SharedGroupImpl extends AbstractSharedGroup implements Remote {
+public class SharedGroupImpl implements Remote, 
+       SharedGroupBackEnd, ServerProxyTrust, ProxyAccessor, Starter {
+    
+    /** Component name for configuration entries */
+    static final String START_PACKAGE = "com.sun.jini.start";
+
+    /** Configure logger */
+    static final Logger logger =
+        Logger.getLogger(START_PACKAGE + ".sharedGroup");
+
+    /** Our prepared activation ID reference */
+    private final ActivationID activationID;
+
+    /** The prepared activation system reference */
+    private volatile ActivationSystem activationSystem;
+    
+    /** The inner proxy of this server */
+    private Remote ourStub;
+
+    /** <code>LoginContext</code> for this service. */
+    private final LoginContext loginContext;
+    
+    /** The exporter for exporting and unexporting */
+    protected final Exporter exporter;
+    
+    private final AccessControlContext context;
+
     /**
      * Activation constructor. 
      */
     SharedGroupImpl(ActivationID activationID, MarshalledObject data)
 	throws Exception
     {
-        super(activationID, data);
-        export();
+	this(getInit(activationID, data));
+    }
+    
+    private static SharedGroupImplInit getInit(ActivationID activationID, 
+                                                            MarshalledObject data)
+            throws IOException, ClassNotFoundException, ConfigurationException, Exception
+    {
+        LoginContext loginContext = null;
+        try {
+            logger.entering(SharedGroupImpl.class.getName(), "SharedGroupImpl", 
+                new Object[] { activationID, data}); 
+            String[] configArgs = (String[])data.get();	
+            Configuration config = ConfigurationProvider.getInstance(configArgs);
+            loginContext = (LoginContext) config.getEntry(
+                START_PACKAGE, "loginContext", LoginContext.class, null);
+            SharedGroupImplInit init = null;
+                if (loginContext != null) {
+                    init = doInitWithLogin(config, activationID, loginContext);
+                } else {
+                    init = doInit(config, activationID, null);
+                }
+            return init;
+        } catch (Exception e) {
+            // If we get here an instance of SharedGroupImpl hasn't been
+            // created, it's constructor won't be called and exporting doesn't
+            // occur.
+            if (loginContext != null) {
+                try {
+                    loginContext.logout();
+                    logger.finest("SharedGroupImpl logged-out.");
+                } catch (Exception ex) {
+                    logger.log(Level.FINEST, 
+                        "Problem logging out for SharedGroupImpl.", ex);
+                }
+            }
+            throw e;
+        } finally {
+            logger.exiting(SharedGroupImpl.class.getName(), "SharedGroupImpl");
+        }
+    }
+    
+    private SharedGroupImpl(SharedGroupImplInit init){
+            activationSystem = init.activationSystem;
+            this.activationID = init.activationID;
+            exporter = init.exporter;
+            context = init.context;
+            loginContext = init.loginContext;
+    }       
+
+    private static SharedGroupImplInit doInitWithLogin(final Configuration config, 
+                                                    final ActivationID id, 
+                                                    final LoginContext loginContext) 
+                                                throws Exception
+    {
+        loginContext.login();
+        try {
+            return Subject.doAsPrivileged(
+                loginContext.getSubject(),
+                new PrivilegedExceptionAction<SharedGroupImplInit>() {
+                    public SharedGroupImplInit run() throws Exception {
+                        doInit(config, id, loginContext);
+                        return null;
+                    }
+                },
+                null);
+        } catch (PrivilegedActionException e) {
+            throw e.getException();
+        }
+    }
+    
+    private static SharedGroupImplInit doInit(Configuration config, 
+                                                    ActivationID id, 
+                                                    LoginContext loginContext) 
+                                                            throws Exception 
+    {
+        return new SharedGroupImplInit(config, id, loginContext);
+    }
+    
+    public final synchronized void start() throws ExportException {
+        try {
+            // Export service
+            
+            ourStub = AccessController.doPrivileged(new PrivilegedExceptionAction<Remote>(){
+
+                @Override
+                public Remote run() throws ExportException {
+                    return exporter.export(SharedGroupImpl.this);	
+                }
+                
+            }, context);
+        } catch (PrivilegedActionException ex) {
+            ExportException e = (ExportException) ex.getException();
+            cleanup();
+            throw e;
+        }
+                	
+        logger.log(Level.FINEST, "Exported service proxy: {0}",
+            ourStub);
+    }
+
+    // javadoc inherited from supertype
+    public void destroyVM() throws RemoteException, ActivationException {
+	logger.entering(SharedGroupImpl.class.getName(), "destroyVM"); 
+	/*
+	 * Would like to synch access to activationSystem, but need
+	 * to avoid holding locks across remote invocations.
+	 */
+        if (activationSystem != null) {
+	    activationSystem.unregisterGroup(
+		ActivationGroup.currentGroupID());
+                logger.finest("ActivationGroup unregistered.");
+		/* Unregistering the group implicitly unregisters
+		 * all the objects associated with that group as well.
+		 */
+	    activationSystem = null;     
+	}
+        (new SharedGroupImpl.DestroyThread()).start();
+	logger.exiting(SharedGroupImpl.class.getName(), "destroyVM"); 
+    }
+
+    /**
+     * Private utility method which attempts to roll back from 
+     * from a failed initialization attempt. 
+     */
+    private void cleanup() {
+	logger.entering(SharedGroupImpl.class.getName(), "cleanup"); 
+        /* 
+	 * Caller decides whether or not to unregister this object.
+	 */
+        if (exporter != null) {
+            try {
+	        // Unexport object so that no new calls come in
+	        exporter.unexport(true);
+                logger.finest("SharedGroupImpl unexported.");
+	    } catch (Exception e) {
+                logger.log(Level.FINEST, 
+		    "Problem unexporting SharedGroupImpl.", e);
+	    }
+        }
+		
+	if (loginContext != null) {
+	    try {
+		loginContext.logout();
+                logger.finest("SharedGroupImpl logged-out.");
+	    } catch (Exception e) {
+                logger.log(Level.FINEST, 
+		    "Problem logging out for SharedGroupImpl.", e);
+	    }
+	}
+	logger.exiting(SharedGroupImpl.class.getName(), "cleanup"); 
+    }
+
+    /**
+     * Termination thread code.  We do this in a separate thread to
+     * allow the calling thread to return normally. This is not guaranteed
+     * since it's still possible for the VM to exit before the calling
+     * thread returns.
+     */
+    private class DestroyThread extends Thread {
+
+        /** Create a non-daemon thread */
+        public DestroyThread() {
+            super("DestroyThread");
+            /* override inheritance from RMI daemon thread */
+            setDaemon(false);
+        }
+
+        public void run() {
+            logger.entering(SharedGroupImpl.DestroyThread.class.getName(), 
+                "run");
+ 
+            logger.finest("Calling System.exit() ...");
+
+	    /*
+	     * Forcefully destroy the VM, in case there are any lingering 
+	     * threads.
+	     */
+	    System.exit(0);
+        }
+    }
+    // inherit javadoc
+    public synchronized Object getProxy() {
+        logger.entering(SharedGroupImpl.class.getName(), 
+                "getProxy");
+        logger.exiting(SharedGroupImpl.class.getName(), 
+                "getProxy", ourStub);
+	return ourStub;
+    }
+    
+    //////////////////////////////////////////
+    // ProxyTrust Method
+    //////////////////////////////////////////
+    //inherit javadoc
+    public synchronized TrustVerifier getProxyVerifier( ) {
+        /* No verifier if the server isn't secure */
+        if (!(ourStub instanceof RemoteMethodControl)) {
+            throw new UnsupportedOperationException();
+        } else {
+            return new ProxyVerifier((SharedGroupBackEnd)ourStub);
+        }
     }
 }

Copied: river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/SharedGroupImplInit.java (from r1487782, river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/AbstractSharedGroupInit.java)
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/SharedGroupImplInit.java?p2=river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/SharedGroupImplInit.java&p1=river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/AbstractSharedGroupInit.java&r1=1487782&r2=1488180&rev=1488180&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/AbstractSharedGroupInit.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/SharedGroupImplInit.java Fri May 31 11:45:48 2013
@@ -36,35 +36,35 @@ import net.jini.security.BasicProxyPrepa
 import net.jini.security.ProxyPreparer;
 
 /**
- *  This is created and discarded during construction of (@link AbstractSharedGroup).
+ *  This is created and discarded during construction of (@link SharedGroupImpl).
  */
-class AbstractSharedGroupInit {
+class SharedGroupImplInit {
     ActivationSystem activationSystem;
     ActivationID activationID;
     Exporter exporter;
     AccessControlContext context;
     LoginContext loginContext;
     
-    AbstractSharedGroupInit(Configuration config, ActivationID id, LoginContext LoginContext) throws Exception {
+    SharedGroupImplInit(Configuration config, ActivationID id, LoginContext LoginContext) throws Exception {
         ProxyPreparer activationSystemPreparer =
             (ProxyPreparer) config.getEntry(
-                AbstractSharedGroup.START_PACKAGE, "activationSystemPreparer",
+                SharedGroupImpl.START_PACKAGE, "activationSystemPreparer",
                 ProxyPreparer.class, new BasicProxyPreparer());
 	if (activationSystemPreparer == null) {
-             throw new ConfigurationException(AbstractSharedGroup.START_PACKAGE 
+             throw new ConfigurationException(SharedGroupImpl.START_PACKAGE 
 	     + ".activationSystemPreparer entry should not be null");
         }
-        AbstractSharedGroup.logger.log(Level.FINE, AbstractSharedGroup.START_PACKAGE + ".activationSystemPreparer: {0}",
+        SharedGroupImpl.logger.log(Level.FINE, SharedGroupImpl.START_PACKAGE + ".activationSystemPreparer: {0}",
             activationSystemPreparer);
 	    
 	ProxyPreparer activationIdPreparer = (ProxyPreparer)
-	    config.getEntry(AbstractSharedGroup.START_PACKAGE, "activationIdPreparer",
+	    config.getEntry(SharedGroupImpl.START_PACKAGE, "activationIdPreparer",
 	    ProxyPreparer.class, new BasicProxyPreparer());
 	if (activationIdPreparer == null) {
-             throw new ConfigurationException(AbstractSharedGroup.START_PACKAGE 
+             throw new ConfigurationException(SharedGroupImpl.START_PACKAGE 
 	     + ".activationIdPreparer entry should not be null");
         }
-        AbstractSharedGroup.logger.log(Level.FINE, AbstractSharedGroup.START_PACKAGE + ".activationIdPreparer: {0}",
+        SharedGroupImpl.logger.log(Level.FINE, SharedGroupImpl.START_PACKAGE + ".activationIdPreparer: {0}",
             activationIdPreparer);
 	    
         // Prepare activation subsystem
@@ -75,11 +75,11 @@ class AbstractSharedGroupInit {
 	activationSystem = (ActivationSystem) 
 	    activationSystemPreparer.prepareProxy(
                 ActivationGroup.getSystem());
-        AbstractSharedGroup.logger.log(Level.FINE, "Prepared ActivationSystem: {0}",
+        SharedGroupImpl.logger.log(Level.FINE, "Prepared ActivationSystem: {0}",
             activationSystem);
 	activationID = (ActivationID)  
 	    activationIdPreparer.prepareProxy(id);
-        AbstractSharedGroup.logger.log(Level.FINEST, "Prepared ActivationID: {0}",
+        SharedGroupImpl.logger.log(Level.FINEST, "Prepared ActivationID: {0}",
             activationID);
 
         /**
@@ -87,7 +87,7 @@ class AbstractSharedGroupInit {
 	 * the prepared activationID.
 	 */
 	exporter = (Exporter) config.getEntry(
-                AbstractSharedGroup.START_PACKAGE, "exporter", Exporter.class, 
+                SharedGroupImpl.START_PACKAGE, "exporter", Exporter.class, 
 		new ActivationExporter(
 		    activationID,
 		    new BasicJeriExporter(
@@ -95,10 +95,10 @@ class AbstractSharedGroupInit {
 			new BasicILFactory(), false, true)),
 		activationID);
 	if (exporter == null) {
-             throw new ConfigurationException(AbstractSharedGroup.START_PACKAGE 
+             throw new ConfigurationException(SharedGroupImpl.START_PACKAGE 
 	     + ".exporter entry should not be null");
         }
-        AbstractSharedGroup.logger.log(Level.FINE, AbstractSharedGroup.START_PACKAGE + ".exporter: {0}",
+        SharedGroupImpl.logger.log(Level.FINE, SharedGroupImpl.START_PACKAGE + ".exporter: {0}",
             exporter);
 	context = AccessController.getContext();
 	

Modified: river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/Starter.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/Starter.java?rev=1488180&r1=1488179&r2=1488180&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/Starter.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/Starter.java Fri May 31 11:45:48 2013
@@ -35,8 +35,8 @@ public interface Starter {
      * services to avoid throwing an exception during construction to avoid
      * finalizer attacks.
      * <p>
-     * The implementation is required to ensure start() is only executed once,
-     * additional invocations must return immediately.
+     * The implementation is required to ensure start() is idempotent 
+     * (only executed once, additional invocations must return immediately).
      * 
      * @throws Exception if there's a problem with construction or startup.
      */



Mime
View raw message