You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@river.apache.org by pe...@apache.org on 2013/03/17 13:32:11 UTC

svn commit: r1457436 - in /river/jtsk/skunk/qa_refactor/trunk: qa/src/com/sun/jini/test/impl/outrigger/matching/ qa/src/com/sun/jini/test/impl/outrigger/transaction/ src/com/sun/jini/lease/ src/com/sun/jini/outrigger/ src/com/sun/jini/reggie/ src/com/s...

Author: peter_firmstone
Date: Sun Mar 17 12:32:10 2013
New Revision: 1457436

URL: http://svn.apache.org/r1457436
Log:
Numerous refactorings and updates, including delayed starting of services with com.sun.jini.start.Starter until after construction is complete, Outrigger now utilises delayed starting for JMM compliant safe construction.

RemoteEvents and some subclasses are now immutable, protected fields with existing get methods have been made private, these could remain protected and be final to remain compatible, will change back to protected if requested.

Added:
    river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/Starter.java   (with props)
Modified:
    river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/outrigger/matching/MatchTestCore.java
    river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/outrigger/transaction/TransactionTestBase.java
    river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/lease/BasicRenewalFailureEvent.java
    river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/outrigger/AvailabilityRegistrationWatcher.java
    river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/outrigger/EventRegistrationWatcher.java
    river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/outrigger/OutriggerServerImpl.java
    river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/outrigger/OutriggerServerWrapper.java
    river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/reggie/RegistrarEvent.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/net/jini/core/event/EventRegistration.java
    river/jtsk/skunk/qa_refactor/trunk/src/net/jini/core/event/RemoteEvent.java
    river/jtsk/skunk/qa_refactor/trunk/src/net/jini/core/lookup/ServiceEvent.java
    river/jtsk/skunk/qa_refactor/trunk/src/net/jini/discovery/LookupDiscovery.java
    river/jtsk/skunk/qa_refactor/trunk/src/net/jini/discovery/RemoteDiscoveryEvent.java
    river/jtsk/skunk/qa_refactor/trunk/src/net/jini/lease/ExpirationWarningEvent.java
    river/jtsk/skunk/qa_refactor/trunk/src/net/jini/space/AvailabilityEvent.java

Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/outrigger/matching/MatchTestCore.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/outrigger/matching/MatchTestCore.java?rev=1457436&r1=1457435&r2=1457436&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/outrigger/matching/MatchTestCore.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/outrigger/matching/MatchTestCore.java Sun Mar 17 12:32:10 2013
@@ -51,19 +51,19 @@ public abstract class MatchTestCore exte
      * Not valid until <code>construct()</code> is called.
      * @see MatchTestBase#construct
      */
-    protected boolean useIfExists = false;
+    protected volatile boolean useIfExists = false;
 
     /**
      * The space under test
      */
-    protected JavaSpace space;
+    protected volatile JavaSpace space;
 
     /**
      * Time in milliseconds to wait for a read or take.
      * Not valid until <code>construct()</code> is called.
      */
-    protected long queryTimeOut; // 10 seconds
-    private long tryShutdown;
+    protected volatile long queryTimeOut; // 10 seconds
+    private volatile long tryShutdown;
 
     /**
      * Convince method for doing a read on the JavaSpace, uses the

Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/outrigger/transaction/TransactionTestBase.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/outrigger/transaction/TransactionTestBase.java?rev=1457436&r1=1457435&r2=1457436&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/outrigger/transaction/TransactionTestBase.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/outrigger/transaction/TransactionTestBase.java Sun Mar 17 12:32:10 2013
@@ -84,6 +84,7 @@ public abstract class TransactionTestBas
         try {
             ((Administrable) services[serviceIndex]).getAdmin();
         } catch (Throwable e) {
+            e.printStackTrace(System.err);
             throw new TestException("Could not pre-activate service"
                     + " under test", e);
         }

Modified: river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/lease/BasicRenewalFailureEvent.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/lease/BasicRenewalFailureEvent.java?rev=1457436&r1=1457435&r2=1457436&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/lease/BasicRenewalFailureEvent.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/lease/BasicRenewalFailureEvent.java Sun Mar 17 12:32:10 2013
@@ -46,14 +46,14 @@ public class BasicRenewalFailureEvent ex
      *
      * @serial
      */
-    private MarshalledInstance marshalledThrowable;
+    private final MarshalledInstance marshalledThrowable;
 
     /**
      * Lease, in marshalled form, returned by <code>getLease</code> method.
      *
      * @serial 
      */
-    private MarshalledInstance marshalledLease;
+    private final MarshalledInstance marshalledLease;
 
     /**
      * Transient cache of lease returned by <code>getLease</code> method.  

Modified: river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/outrigger/AvailabilityRegistrationWatcher.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/outrigger/AvailabilityRegistrationWatcher.java?rev=1457436&r1=1457435&r2=1457436&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/outrigger/AvailabilityRegistrationWatcher.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/outrigger/AvailabilityRegistrationWatcher.java Sun Mar 17 12:32:10 2013
@@ -356,14 +356,14 @@ abstract class AvailabilityRegistrationW
 		if (getExpiration() < now) {
 		    doneFor = true; // Our registration has expired, remove it
 		}
-	    }
-
-	    // Now that we are outside the lock kill our watcher if doneFor.
-	    if (doneFor) {
-		cancel();
-		return;
-	    }
+	    
 
+                // Now that we are outside the lock kill our watcher if doneFor.
+                if (doneFor) {
+                    cancel();
+                    return;
+                }
+            }
 	    getListener(preparer).notify(
 		new OutriggerAvailabilityEvent(source, eventID, ourSeqNumber, 
 					       handback, isVisible, rep));

Modified: river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/outrigger/EventRegistrationWatcher.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/outrigger/EventRegistrationWatcher.java?rev=1457436&r1=1457435&r2=1457436&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/outrigger/EventRegistrationWatcher.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/outrigger/EventRegistrationWatcher.java Sun Mar 17 12:32:10 2013
@@ -318,31 +318,33 @@ abstract class EventRegistrationWatcher 
 		    // We need to send an event!
 		    seqNum = currentSeqNum;
 		}
-	    }
+	    
 
-	    // Now that we are outside the lock kill our watcher if doneFor.
-	    if (doneFor) {
-		cancel();
-		return;
-	    }
+                // cancel is a synchronized method with the same lock.
+                if (doneFor) {
+                    cancel();
+                    return;
+                }
 
-	    /* The only way to get here is through a path that sets
-	     * seqNum to the non-initial values
-	     */
-	    assert seqNum != -1;
+                /* The only way to get here is through a path that sets
+                 * seqNum to the non-initial values
+                 */
+                assert seqNum != -1;
 
-	    /* If we are here then we need to send an event (probably
+
+
+                // success!, update lastSeqNumDelivered, but don't go backward
+	    
+		if (seqNum > lastSeqNumDelivered)
+		    lastSeqNumDelivered = seqNum;
+	    }
+            
+             /* If we are here then we need to send an event (probably
 	     * someone could have sent our event between the time
 	     * we released the lock and now).
 	     */
 	    getListener(preparer).notify(
 		new RemoteEvent(source, eventID, seqNum, handback));
-
-	    // success!, update lastSeqNumDelivered, but don't go backward
-	    synchronized (EventRegistrationWatcher.this) {
-		if (seqNum > lastSeqNumDelivered)
-		    lastSeqNumDelivered = seqNum;
-	    }
 	}
 	
 	

Modified: river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/outrigger/OutriggerServerImpl.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/outrigger/OutriggerServerImpl.java?rev=1457436&r1=1457435&r2=1457436&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/outrigger/OutriggerServerImpl.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/outrigger/OutriggerServerImpl.java Sun Mar 17 12:32:10 2013
@@ -28,6 +28,7 @@ import com.sun.jini.landlord.LocalLandlo
 import com.sun.jini.landlord.LeaseFactory;
 import com.sun.jini.logging.Levels;
 import com.sun.jini.start.LifeCycle;
+import com.sun.jini.start.Starter;
 
 import net.jini.id.Uuid;
 import net.jini.id.UuidFactory;
@@ -88,6 +89,8 @@ import java.util.Map;
 import java.util.Set;
 import java.util.Stack;
 import java.util.WeakHashMap;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicLong;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -142,7 +145,7 @@ import javax.security.auth.login.LoginEx
  */
 public class OutriggerServerImpl 
     implements OutriggerServer, TimeConstants, LocalLandlord, Recover,
-	       ServerProxyTrust 
+	       ServerProxyTrust, Starter
 {	
     /**
      * Component name we use to find items in the configuration and loggers.
@@ -214,47 +217,47 @@ public class OutriggerServerImpl 
      * List of <code>com.sun.jini.outrigger.EntryHolder</code>s for 
      * each specific type.
      */
-    private EntryHolderSet	contents;
+    private final EntryHolderSet contents;
 
     /**
      * A list of known subclasses of each class of entry.
      */
-    private final TypeTree	types = new TypeTree();
+    private final TypeTree types = new TypeTree();
 
     /**
      * A list of hashes to check against class types.
      */
-    private final HashMap	typeHashes = new HashMap();
+    private final HashMap<String,Long> typeHashes = new HashMap<String,Long>();
 
     /**
      * Templates for which someone has registered interest
      */
-    private TransitionWatchers	templates;
+    private final TransitionWatchers templates;
 
     /**
      * A map from event registration cookies to 
      * <code>EventRegistrationRecord</code> instances
      */
-    final private Map eventRegistrations =
-	Collections.synchronizedMap(new java.util.HashMap());
+    final private Map<Uuid,LeasedResource> eventRegistrations =
+	Collections.synchronizedMap(new java.util.HashMap<Uuid,LeasedResource>());
 
     /**
      * A map from contents result cookies to <code>ContentsQuery</code> objects.
      */
-    final private Map contentsQueries = 
-	Collections.synchronizedMap(new java.util.HashMap());
+    final private Map<Uuid,LeasedResource> contentsQueries = 
+	Collections.synchronizedMap(new java.util.HashMap<Uuid,LeasedResource>());
 
     /**
      * The transactions recovered after restart. This table
-     * is discarded after recovery
+     * is cleared after recovery
      */
-    private Map 		recoveredTxns;
+    private final Map<Long,Txn> recoveredTxns = new ConcurrentHashMap<Long,Txn>();
 
     /**
      * The transactions in which this space is a participant.
      * Includes broken <code>Txn</code>s.
      */
-    private TxnTable            txnTable;
+    private final TxnTable txnTable;
 
     /**
      * The crash count.  This must be different each boot that forgets
@@ -267,7 +270,7 @@ public class OutriggerServerImpl 
      *
      * @serial
      */
-    private TemplateReaper templateReaperThread;
+    private final TemplateReaper templateReaperThread;
 
     /**
      * The reaper thread for removed entries. 
@@ -277,39 +280,39 @@ public class OutriggerServerImpl 
      *
      * @serial
      */
-    private EntryReaper	entryReaperThread;
+    private final EntryReaper entryReaperThread;
 
     /**
      * The reaper thread for expired contents queries
      *
      * @serial
      */
-    private ContentsQueryReaper contentsQueryReaperThread;
+    private final ContentsQueryReaper contentsQueryReaperThread;
 
     /**
      * Object that recored operations on entries and makes sure they
      * get seen by the watchers in <code>templates</code>.
      */
-    private OperationJournal operationJournal;
+    private final OperationJournal operationJournal;
 
     /**
      * The notification object
      *
      * @serial
      */
-    private Notifier  	      notifier;
+    private volatile Notifier notifier;
 
     /** 
      * Object that queues up lease expirations for future logging.
      * Only allocated if we have a store, otherwise left
      * <code>null</code>
      */
-    private ExpirationOpQueue expirationOpQueue;
+    private final ExpirationOpQueue expirationOpQueue;
 
     /**
      * The monitor for ongoing transactions.
      */
-    private TxnMonitor txnMonitor;
+    private final TxnMonitor txnMonitor;
 
     /**
      * The wrapper that intercepts incoming remote calls for locking
@@ -324,14 +327,14 @@ public class OutriggerServerImpl 
     /**
      * Object we used to export ourselves.
      */
-    private Exporter exporter;
+    private final Exporter exporter;
 
     /**
      * The remote ref (e.g. stub or dynamic proxy) for this
      * server.
      * @serial
      */
-    private OutriggerServer ourRemoteRef;
+    private final OutriggerServer ourRemoteRef;
 
     /**
      * The <code>Uuid</code> for this service. Used in the 
@@ -339,28 +342,28 @@ public class OutriggerServerImpl 
      * implement reference equality. We also derive our
      * <code>ServiceID</code> from it.
      */
-    private Uuid topUuid = null;
+    private volatile Uuid topUuid = null;
 
     /**
      * The proxy for this space.
      *
      * @serial
      */
-    private SpaceProxy2 spaceProxy;
+    private volatile SpaceProxy2 spaceProxy;
 
     /**
      * The admin proxy for this space.
      *
      * @serial
      */
-    private AdminProxy adminProxy;
+    private volatile AdminProxy adminProxy;
 
     /**
      * The participant proxy for this space
      *
      * @serial
      */
-    private ParticipantProxy participantProxy;
+    private volatile ParticipantProxy participantProxy;
 
     /**
      * Holds the basis/lower bound for all sequence numbers issued.
@@ -379,32 +382,32 @@ public class OutriggerServerImpl 
      * [See the JavaSpaces Service Specification for detail on "fully
      *  ordered".]
      */
-    private long sessionId = 0;
+    private final AtomicLong sessionId = new AtomicLong();
 
     /**
      * Policy used to create and renew leases on entries
      */
-    private LeasePeriodPolicy entryLeasePolicy; 
+    private final LeasePeriodPolicy entryLeasePolicy; 
 
     /**
      * Policy used to create and renew leases on event registrations
      */
-    private LeasePeriodPolicy eventLeasePolicy;
+    private final LeasePeriodPolicy eventLeasePolicy;
 
     /**
      * Policy used to create and renew leases on event contents queries
      */
-    private LeasePeriodPolicy contentsLeasePolicy;
+    private final LeasePeriodPolicy contentsLeasePolicy;
 
     /**
      * Factory we use to create leases
      */
-    private LeaseFactory leaseFactory;
+    private volatile LeaseFactory leaseFactory;
 
     /**
      * @serial
      */
-    private JoinStateManager joinStateManager = new JoinStateManager();
+    private final JoinStateManager joinStateManager = new JoinStateManager();
 
     /** 
      * Our IDs 64 bits secure random numbers, this is 
@@ -413,26 +416,26 @@ public class OutriggerServerImpl 
     private static final SecureRandom idGen = new SecureRandom();
 
     /** Our activation ID, <code>null</code> if we are not activatable */
-    private ActivationID activationID;
+    private final ActivationID activationID;
 
     /** 
      * A prepared reference to the activation system, <code>null</code> if
      * we are not activatable.
      */
-    private ActivationSystem activationSystem;
+    private final ActivationSystem activationSystem;
 
       
     /**
      * Store - The reference to the persistent store, if any.
      */
-    private Store	store; 
+    private volatile Store store; 
 
     /**
      * Log object to record state and operation information. The
      * store provides this object. Will be <code>null</code> if
      * this is a transient server instance.
      */
-    private LogOps	log;
+    private volatile LogOps log = null;
 
     /** The map of <code>Uuid</code> to active iterations */
     private final Map iterations = 
@@ -442,42 +445,52 @@ public class OutriggerServerImpl 
     private final LoginContext loginContext;
 
     /** <code>ProxyPreparer</code> for transaction managers */
-    private ProxyPreparer transactionManagerPreparer;
+    private final ProxyPreparer transactionManagerPreparer;
 
     /** <code>ProxyPreparer</code> for event listeners */
-    private ProxyPreparer listenerPreparer;
+    private final ProxyPreparer listenerPreparer;
 
     /** 
      * <code>ProxyPreparer</code> for transaction managers 
      * that get recovered from the store. <code>null</code> if
      * this is not a persistent space.
      */
-    private ProxyPreparer recoveredTransactionManagerPreparer;
+    private final ProxyPreparer recoveredTransactionManagerPreparer;
 
     /** 
      * <code>ProxyPreparer</code> for event listeners
      * that get recovered from the store. <code>null</code> if
      * this is not a persistent space.
      */
-    private ProxyPreparer recoveredListenerPreparer;
+    private final ProxyPreparer recoveredListenerPreparer;
 
     /** Max number of entries to return in a next call */
-    private int nextLimit;
+    private final int nextLimit;
 
     /** Max number of entries to return in a take multiple call */
-    private int takeLimit;
+    private final int takeLimit;
 
     /**
      * When destroying the space, how long to wait for a clean
      * unexport (which allows the destroy call to return) before
      * giving up calling <code>unexport(true)</code>
      */
-    private long maxUnexportDelay;
+    private final long maxUnexportDelay;
 
     /**
      * Length of time to sleep between unexport attempts
      */
-    private long unexportRetryDelay;
+    private final long unexportRetryDelay;
+    
+    // Synchronized access with thisl
+    private boolean started = false;
+    /** Temporary start state Object variables set to null after start */
+    private Configuration config;
+    private Thread starter;
+    private Throwable thrown;
+    private Exception except;
+    private boolean persistent;
+    private long maxServerQueryTimeout;
 
     /**
      * Create a new <code>OutriggerServerImpl</code> server (possibly a
@@ -507,34 +520,34 @@ public class OutriggerServerImpl 
      *         in the configuration is non-null and throws 
      *         an exception when login is attempted.  
      */
-    OutriggerServerImpl(ActivationID activationID, LifeCycle lifeCycle,
+    OutriggerServerImpl(final ActivationID activationID, LifeCycle lifeCycle,
 			String[] configArgs, final boolean persistent,
-			OutriggerServerWrapper wrapper) 
+			final OutriggerServerWrapper wrapper) 
 	throws IOException, ConfigurationException, LoginException,
 	       ActivationException
     {	
 	this.lifeCycle = lifeCycle;
-	this.activationID = activationID;
 	this.serverGate = wrapper;
-
+        this.persistent = persistent;
+        InitHolder h = null;
+        LoginContext loginContext = null;
 	try {
 	    final Configuration config = 
 		ConfigurationProvider.getInstance(configArgs,
 						  getClass().getClassLoader());
-
+            this.config = config;
 	    loginContext = (LoginContext) config.getEntry(
 		COMPONENT_NAME, "loginContext", LoginContext.class, null);
 	    if (loginContext == null) {
-		init(config, persistent);
+		h = init(config, persistent, activationID, wrapper);
 	    } else {
 		loginContext.login();
 		try {
-		    Subject.doAsPrivileged(
+		    h = Subject.doAsPrivileged(
 			loginContext.getSubject(),
-			new PrivilegedExceptionAction() {
-			    public Object run() throws Exception {
-				init(config, persistent);
-				return null;
+			new PrivilegedExceptionAction<InitHolder>() {
+			    public InitHolder run() throws Exception {
+				return init(config, persistent, activationID, wrapper);
 			    }
 			},
 			null);
@@ -544,21 +557,251 @@ public class OutriggerServerImpl 
 	    }
 	} catch (IOException e) {
 	    unwindConstructor(e);
-	    throw e;
+	    except = e;
 	} catch (ConfigurationException e) {
 	    unwindConstructor(e);
-	    throw e;
+	    except = e;
 	} catch (LoginException e) {
 	    unwindConstructor(e);
-	    throw e;	    
+	    except = e;	    
 	} catch (RuntimeException e) {
 	    unwindConstructor(e);
-	    throw e;
+	    except = e;
 	} catch (Throwable e) {
 	    unwindConstructor(e);
-	    throw (Error)e;
+            thrown = e;
 	}
-	lifecycleLogger.log(Level.INFO, "Outrigger server started: {0}", this);
+        if (thrown == null && except == null) {
+            lifecycleLogger.log(Level.INFO, "Outrigger server started: {0}", this);
+            this.loginContext = loginContext;
+            this.activationID = h.activationID;
+            txnMonitor = h.txnMonitor;
+            activationSystem = h.activationSystem;
+            transactionManagerPreparer = h.transactionManagerPreparer;
+            listenerPreparer = h.listenerPreparer;
+            exporter = h.exporter;
+            ourRemoteRef = h.ourRemoteRef;
+            contents = h.contents;
+            templates = h.templates;
+            operationJournal = h.operationJournal;
+            expirationOpQueue = h.expirationOpQueue;
+            recoveredTransactionManagerPreparer = h.recoveredTransactionManagerPreparer;
+            recoveredListenerPreparer = h.recoveredListenerPreparer;
+            txnTable = h.txnTable;
+            leaseFactory = h.leaseFactory;
+            entryLeasePolicy = h.entryLeasePolicy;
+            eventLeasePolicy = h.eventLeasePolicy;
+            contentsLeasePolicy = h.contentsLeasePolicy;
+            nextLimit = h.nextLimit;
+            takeLimit = h.takeLimit;
+            maxUnexportDelay = h.maxUnexportDelay;
+            unexportRetryDelay = h.unexportRetryDelay;
+            notifier = h.notifier; 
+            templateReaperThread = h.templateReaperThread;
+            entryReaperThread = h.entryReaperThread;
+            contentsQueryReaperThread = h.contentsQueryReaperThread;
+            starter = h.starter;
+            maxServerQueryTimeout = h.maxServerQueryTimeout;
+        } else {
+            lifecycleLogger.log(Level.SEVERE, "Failed to construct Outrigger server", except == null ? thrown : except);
+            this.loginContext = null;
+            this.activationID = null;
+            txnMonitor = null;
+            activationSystem = null;
+            transactionManagerPreparer = null;
+            listenerPreparer = null;
+            exporter = null;
+            ourRemoteRef = null;
+            contents = null;
+            templates = null;
+            operationJournal = null;
+            expirationOpQueue = null;
+            recoveredTransactionManagerPreparer = null;
+            recoveredListenerPreparer = null;
+            txnTable = null;
+            leaseFactory = null;
+            entryLeasePolicy = null;
+            eventLeasePolicy = null;
+            contentsLeasePolicy = null;
+            nextLimit = 0;
+            takeLimit = 0;
+            maxUnexportDelay = 0;
+            unexportRetryDelay = 0;
+            notifier = null; 
+            templateReaperThread = null;
+            entryReaperThread = null;
+            contentsQueryReaperThread = null;
+            starter = null;
+            maxServerQueryTimeout = 0;
+        }
+    }
+    
+    public void start() throws Exception {
+        // Threads are created with login context if it exists, but started in
+        // privileged context.
+        synchronized (this){
+            if (started) return;
+            started = true;
+        }
+        if (thrown != null) throw (Error) thrown;
+        if (except != null) throw except;
+        try {
+            // This takes a while the first time, so let's get it going
+            starter.start();
+
+            // Get store from configuration
+            if (persistent) {
+                store = (Store)Config.getNonNullEntry(config,
+                                                      COMPONENT_NAME,
+                                                      "store", Store.class);
+                expirationOpQueue.start();
+            }
+            // If we have a store, recover the log
+            if (store != null) {
+                log = store.setupStore(this);
+
+                // Record this boot
+                //
+                log.bootOp(System.currentTimeMillis(), getSessionId());
+                recoverTxns();
+            } else if (activationID != null || persistent) {
+                /* else we don't have a store, if we need one complain
+                 * will be logged by constructor
+                 */
+                throw new ConfigurationException("Must provide for a " +
+                    "store for component " + COMPONENT_NAME + ", by providing " +
+                    "valid values for the store or " +
+                    PERSISTENCE_DIR_CONFIG_ENTRY + " entries if creating " +
+                    " a persistent space");
+            }
+
+            /* Now that we have recovered any store we have, create a 
+             * Uuid if there was not one in the store.
+             */
+            if (topUuid == null) {
+                topUuid = UuidFactory.generate();
+                if (log != null)
+                    log.uuidOp(topUuid);
+            }		
+
+            if (ourRemoteRef instanceof RemoteMethodControl) {
+                spaceProxy = new ConstrainableSpaceProxy2(ourRemoteRef, topUuid,
+                    maxServerQueryTimeout, null);
+                adminProxy = 
+                    new ConstrainableAdminProxy(ourRemoteRef, topUuid, null);
+                participantProxy =
+                    new ConstrainableParticipantProxy(ourRemoteRef, topUuid, null);
+            } else {
+                spaceProxy = new SpaceProxy2(ourRemoteRef, topUuid, 
+                                             maxServerQueryTimeout);
+                adminProxy = new AdminProxy(ourRemoteRef, topUuid);
+                participantProxy = new ParticipantProxy(ourRemoteRef, topUuid);
+            }
+
+            leaseFactory = new LeaseFactory(ourRemoteRef, topUuid);
+
+            /* Kick off independent threads. */
+
+            // start the JoinStateManager
+            joinStateManager.startManager(config, log, spaceProxy,
+                new ServiceID(topUuid.getMostSignificantBits(),
+                              topUuid.getLeastSignificantBits()),
+                attributesFor());
+            // Notifier uses TaskManager, which doesn't start threads until given tasks.
+            notifier = new Notifier(spaceProxy, recoveredListenerPreparer, config);
+            operationJournal.start();
+            templateReaperThread.start(); 
+            entryReaperThread.start(); 
+            contentsQueryReaperThread.start();
+        } catch (Exception e) {
+            // Clean up and rethrow.
+            lifecycleLogger.log(Level.SEVERE, "Failed to start Outrigger server", e);
+            // If we created a JoinStateManager,
+            
+            try {
+                joinStateManager.destroy();
+            } catch (Throwable t) {
+                // Ignore and go on
+            }
+            
+            if (expirationOpQueue != null)
+                expirationOpQueue.terminate();
+
+            if (txnMonitor != null) {
+                try {
+                    txnMonitor.destroy();
+                } catch (Throwable t) {
+                    // Ignore and go on
+                }
+            }
+
+            // Interrupt and join independent threads
+            if (notifier != null) {
+                try {
+                    notifier.terminate();
+                } catch (Throwable t) {
+                    // Ignore and go on
+                }
+            }
+
+            if (operationJournal != null) {
+                try {
+                    operationJournal.terminate();
+                } catch (Throwable t) {
+                    // Ignore and go on
+                }	       
+            }
+
+            unwindReaper(templateReaperThread);
+            unwindReaper(entryReaperThread);
+            unwindReaper(contentsQueryReaperThread);
+
+            // Close (but do not destroy) the store
+            if (store != null) {
+                try {
+                    store.close();
+                } catch (Throwable t) {
+                    // Ignore and go on
+                }
+            }
+            throw e;
+        } finally {
+            config = null;
+            starter = null;
+            except = null;
+            thrown = null;
+        }
+    }
+
+    private static class InitHolder {
+        ActivationID activationID;
+        TxnMonitor txnMonitor;
+        ActivationSystem activationSystem;
+        ProxyPreparer transactionManagerPreparer;
+        ProxyPreparer listenerPreparer;
+        Exporter exporter;
+        OutriggerServer ourRemoteRef;
+        EntryHolderSet contents;
+        TransitionWatchers templates;
+        OperationJournal operationJournal;
+        ExpirationOpQueue expirationOpQueue;
+        ProxyPreparer recoveredTransactionManagerPreparer;
+	ProxyPreparer recoveredListenerPreparer;
+        TxnTable txnTable;
+        LeaseFactory leaseFactory;
+        LeasePeriodPolicy entryLeasePolicy;
+        LeasePeriodPolicy eventLeasePolicy;
+        LeasePeriodPolicy contentsLeasePolicy;
+        int nextLimit;
+        int takeLimit;
+        long maxUnexportDelay;
+        long unexportRetryDelay;
+        Notifier notifier; 
+        TemplateReaper templateReaperThread;
+        EntryReaper entryReaperThread;
+        ContentsQueryReaper contentsQueryReaperThread;
+        Thread starter;
+        long maxServerQueryTimeout;
     }
 
     /**
@@ -580,238 +823,180 @@ public class OutriggerServerImpl 
      *         <code>data</code>.
      * @throws ConfigurationException if the <code>Configuration</code> is 
      * malformed.  */
-    private void init(Configuration config, boolean persistent) 
+    private InitHolder init(Configuration config, 
+                        boolean persistent, 
+                        ActivationID activationID,
+                        OutriggerServerWrapper serverGate) 
     	throws IOException, ConfigurationException, ActivationException
     {
-	txnMonitor = new TxnMonitor(this, config);
-
-	/* Get the activation related preparers we need */
-
-	// Default do nothing preparer
-	final ProxyPreparer defaultPreparer = 
-	    new net.jini.security.BasicProxyPreparer();
-
-	if (activationID != null) {
-	    final ProxyPreparer aidPreparer = 
-		(ProxyPreparer)Config.getNonNullEntry(config,
-		    COMPONENT_NAME, "activationIdPreparer",
-		    ProxyPreparer.class, defaultPreparer);
-                
-	    final ProxyPreparer aSysPreparer =
-		(ProxyPreparer)Config.getNonNullEntry(config,
-		     COMPONENT_NAME, "activationSystemPreparer",
-		     ProxyPreparer.class, defaultPreparer);
-
-	    activationID = 
-		(ActivationID)aidPreparer.prepareProxy(activationID);
-	    activationSystem =
-		(ActivationSystem)aSysPreparer.prepareProxy(
-		    ActivationGroup.getSystem());
-	}
-
-
-	// The preparers that all outrigger's need
-	transactionManagerPreparer = 
-	    (ProxyPreparer)Config.getNonNullEntry(config, 
-		COMPONENT_NAME, "transactionManagerPreparer",
-		ProxyPreparer.class, defaultPreparer);
-
-	listenerPreparer = 
-	    (ProxyPreparer)Config.getNonNullEntry(config, 
-		COMPONENT_NAME, "listenerPreparer",
-		ProxyPreparer.class, defaultPreparer);
-
-	/* Export the server. */
-
-	// Get the exporter
-
-	/* What we use for the default (or in the default activatable case
-	 * what we make the underlying exporter).
-	 */
-	final Exporter basicExporter = 
-	    new BasicJeriExporter(TcpServerEndpoint.getInstance(0),
-				  new BasicILFactory(), false, true);
-	if (activationID == null) {
-	    exporter = (Exporter)Config.getNonNullEntry(config,
-		COMPONENT_NAME,	"serverExporter", Exporter.class,
-		basicExporter);
-	} else {
-	    exporter = (Exporter)Config.getNonNullEntry(config, 
-		COMPONENT_NAME,	"serverExporter", Exporter.class,
-		new ActivationExporter(activationID, basicExporter),
-		activationID);
-	}
-
-	ourRemoteRef = (OutriggerServer)exporter.export(serverGate);
-
-	// Create our top level proxy
-	final long maxServerQueryTimeout =
-	    Config.getLongEntry(config, COMPONENT_NAME, 
-		"maxServerQueryTimeout", Long.MAX_VALUE, 1, Long.MAX_VALUE);
-
-	/* Initialize various fields that will be filled in during
-	 * log recovery.
-	 */
-	contents = new EntryHolderSet(this);
-	templates = new TransitionWatchers(this);
-	
-	// This takes a while the first time, so let's get it going
-	new Thread() {
-	    public void run() {
-		OutriggerServerImpl.nextID();
-	    }
-	}.start();
-
-	// Use this (trivially) in log recovery
-	operationJournal = new OperationJournal(templates);
-
-	// Needs to be null so logging is not performed
-	// while store (if any) does recovery.
-	log = null;
-
-	// Get store from configuration
-
-	if (persistent) {
-	    store = (Store)Config.getNonNullEntry(config,
-						  COMPONENT_NAME,
-						  "store", Store.class);
+        InitHolder h = new InitHolder();
+        try {
+            h.txnMonitor = new TxnMonitor(this, config);
+            /* Get the activation related preparers we need */
 
-	    /* If we have a store we need a ExpirationOpQueue and the
-	     * preparers for recovered proxies.
-	     */
-	    expirationOpQueue = new ExpirationOpQueue(this);
-	    expirationOpQueue.setDaemon(true);
-	    expirationOpQueue.start();
-
-	    recoveredTransactionManagerPreparer = 
-		(ProxyPreparer)Config.getNonNullEntry(config, 
-		    COMPONENT_NAME, "recoveredTransactionManagerPreparer", 
-		    ProxyPreparer.class, defaultPreparer);
-
-	    recoveredListenerPreparer = 
-		(ProxyPreparer)Config.getNonNullEntry(config, 
-		    COMPONENT_NAME, "recoveredListenerPreparer", 
+            // Default do nothing preparer
+            final ProxyPreparer defaultPreparer = 
+                new net.jini.security.BasicProxyPreparer();
+
+            if (activationID != null) {
+                final ProxyPreparer aidPreparer = 
+                    (ProxyPreparer)Config.getNonNullEntry(config,
+                        COMPONENT_NAME, "activationIdPreparer",
+                        ProxyPreparer.class, defaultPreparer);
+
+                final ProxyPreparer aSysPreparer =
+                    (ProxyPreparer)Config.getNonNullEntry(config,
+                         COMPONENT_NAME, "activationSystemPreparer",
+                         ProxyPreparer.class, defaultPreparer);
+
+                h.activationID = 
+                    (ActivationID)aidPreparer.prepareProxy(h.activationID);
+                h.activationSystem =
+                    (ActivationSystem)aSysPreparer.prepareProxy(
+                        ActivationGroup.getSystem());
+            }
+
+
+            // The preparers that all outrigger's need
+            h.transactionManagerPreparer = 
+                (ProxyPreparer)Config.getNonNullEntry(config, 
+                    COMPONENT_NAME, "transactionManagerPreparer",
                     ProxyPreparer.class, defaultPreparer);
-	}
-
-	/* Now that we have a recoveredTransactionManagerPreparer
-	 * (if we need one) create the TxnTable
-	 */
-	txnTable = new TxnTable(recoveredTransactionManagerPreparer);
-
-	// If we have a store, recover the log
-	if (store != null) {
-	    log = store.setupStore(this);
-	    
-	    // Record this boot
-	    //
-	    log.bootOp(System.currentTimeMillis(), getSessionId());
-	    recoverTxns();
-	} else if (activationID != null || persistent) {
-	    /* else we don't have a store, if we need one complain
-	     * will be logged by constructor
-	     */
-	    throw new ConfigurationException("Must provide for a " +
-	        "store for component " + COMPONENT_NAME + ", by providing " +
-		"valid values for the store or " +
-	        PERSISTENCE_DIR_CONFIG_ENTRY + " entries if creating " +
-		" a persistent space");
-	}
-
-	/* Now that we have recovered any store we have, create a 
-	 * Uuid if there was not one in the store.
-	 */
-	if (topUuid == null) {
-	    topUuid = UuidFactory.generate();
-	    if (log != null)
-		log.uuidOp(topUuid);
-	}		
-
-	if (ourRemoteRef instanceof RemoteMethodControl) {
-	    spaceProxy = new ConstrainableSpaceProxy2(ourRemoteRef, topUuid,
-		maxServerQueryTimeout, null);
-	    adminProxy = 
-		new ConstrainableAdminProxy(ourRemoteRef, topUuid, null);
-	    participantProxy =
-		new ConstrainableParticipantProxy(ourRemoteRef, topUuid, null);
-	} else {
-	    spaceProxy = new SpaceProxy2(ourRemoteRef, topUuid, 
-					 maxServerQueryTimeout);
-	    adminProxy = new AdminProxy(ourRemoteRef, topUuid);
-	    participantProxy = new ParticipantProxy(ourRemoteRef, topUuid);
-	}
-
-	leaseFactory = new LeaseFactory(ourRemoteRef, topUuid);
-
-	/* Initialize any non-persistent state we have
-	 */
-
-	// Create lease policy objects
-	entryLeasePolicy = (LeasePeriodPolicy)Config.getNonNullEntry(
-	    config, COMPONENT_NAME, "entryLeasePeriodPolicy",
-            LeasePeriodPolicy.class, 
-	    new FixedLeasePeriodPolicy(Long.MAX_VALUE, 1 * DAYS));
-
-	eventLeasePolicy = (LeasePeriodPolicy)Config.getNonNullEntry(
-	    config, COMPONENT_NAME, "eventLeasePeriodPolicy",
-	    LeasePeriodPolicy.class, 
-	    new FixedLeasePeriodPolicy(1 * HOURS, 1 * HOURS));
 
-	contentsLeasePolicy = (LeasePeriodPolicy)Config.getNonNullEntry(
-	    config, COMPONENT_NAME, "contentsLeasePeriodPolicy",
-	    LeasePeriodPolicy.class, 
-	    new FixedLeasePeriodPolicy(1 * HOURS, 1 * HOURS));
-
-	nextLimit = Config.getIntEntry(config, COMPONENT_NAME, 
-            "iteratorBatchSize", 100, 1, Integer.MAX_VALUE);
-
-	takeLimit = Config.getIntEntry(config, COMPONENT_NAME, 
-            "takeMultipleLimit", 100, 1, Integer.MAX_VALUE);
-
-	maxUnexportDelay = Config.getLongEntry(config, COMPONENT_NAME, 
-	    "maxUnexportDelay", 2 * MINUTES, 0, Long.MAX_VALUE);
-
-	unexportRetryDelay = Config.getLongEntry(config, COMPONENT_NAME, 
-	    "unexportRetryDelay", SECONDS, 1, Long.MAX_VALUE);
-
-	/* Kick off independent threads.
-	 */
+            h.listenerPreparer = 
+                (ProxyPreparer)Config.getNonNullEntry(config, 
+                    COMPONENT_NAME, "listenerPreparer",
+                    ProxyPreparer.class, defaultPreparer);
 
-	// start the JoinStateManager
-	joinStateManager.startManager(config, log, spaceProxy,
-	    new ServiceID(topUuid.getMostSignificantBits(),
-			  topUuid.getLeastSignificantBits()),
-	    attributesFor());
+            /* Export the server. */
 
-	operationJournal.setDaemon(true);
-	operationJournal.start();
+            // Get the exporter
 
-	notifier = 
-	    new Notifier(spaceProxy, recoveredListenerPreparer, config);
- 
-	final long reapingInterval = 
-	    Config.getLongEntry(config, COMPONENT_NAME,	"reapingInterval", 
-				10000, 1, Long.MAX_VALUE);
-
-	final int reapingPriority = 
-	    Config.getIntEntry(config, COMPONENT_NAME,"reapingPriority", 
-		Thread.NORM_PRIORITY, Thread.MIN_PRIORITY, 
-		Thread.MAX_PRIORITY);
-                
-	templateReaperThread = new TemplateReaper(reapingInterval);
-	templateReaperThread.setPriority(reapingPriority);
-	templateReaperThread.setDaemon(true);
-	templateReaperThread.start(); 
-
-	entryReaperThread = new EntryReaper(reapingInterval);
-	entryReaperThread.setPriority(reapingPriority);
-	entryReaperThread.setDaemon(true);
-	entryReaperThread.start(); 
-
-	contentsQueryReaperThread = new ContentsQueryReaper(reapingInterval);
-	contentsQueryReaperThread.setPriority(reapingPriority);
-	contentsQueryReaperThread.setDaemon(true);
-	contentsQueryReaperThread.start();
+            /* What we use for the default (or in the default activatable case
+             * what we make the underlying exporter).
+             */
+            final Exporter basicExporter = 
+                new BasicJeriExporter(TcpServerEndpoint.getInstance(0),
+                                      new BasicILFactory(), false, true);
+            if (activationID == null) {
+                h.exporter = (Exporter)Config.getNonNullEntry(config,
+                    COMPONENT_NAME,	"serverExporter", Exporter.class,
+                    basicExporter);
+            } else {
+                h.exporter = (Exporter)Config.getNonNullEntry(config, 
+                    COMPONENT_NAME,	"serverExporter", Exporter.class,
+                    new ActivationExporter(activationID, basicExporter),
+                    activationID);
+            }
+
+            h.ourRemoteRef = (OutriggerServer)h.exporter.export(serverGate);
+
+            // Create our top level proxy
+            h.maxServerQueryTimeout =
+                Config.getLongEntry(config, COMPONENT_NAME, 
+                    "maxServerQueryTimeout", Long.MAX_VALUE, 1, Long.MAX_VALUE);
+
+            /* Initialize various fields that will be filled in during
+             * log recovery.
+             */
+            h.contents = new EntryHolderSet(this);
+            h.templates = new TransitionWatchers(this);
+
+            // This takes a while the first time, so let's get it going
+            h.starter = new Thread() {
+                public void run() {
+                    OutriggerServerImpl.nextID();
+                }
+            };
+
+
+            // Use this (trivially) in log recovery
+            h.operationJournal = new OperationJournal(h.templates);
+            h.operationJournal.setDaemon(true);
+
+
+            if (persistent){
+                /* If we have a store we need a ExpirationOpQueue and the
+                 * preparers for recovered proxies.
+                 */
+                h.expirationOpQueue = new ExpirationOpQueue(this);
+                h.expirationOpQueue.setDaemon(true);
+                h.recoveredTransactionManagerPreparer = 
+                    (ProxyPreparer)Config.getNonNullEntry(config, 
+                        COMPONENT_NAME, "recoveredTransactionManagerPreparer", 
+                        ProxyPreparer.class, defaultPreparer);
+
+                h.recoveredListenerPreparer = 
+                    (ProxyPreparer)Config.getNonNullEntry(config, 
+                        COMPONENT_NAME, "recoveredListenerPreparer", 
+                        ProxyPreparer.class, defaultPreparer);
+            }
+            /* Now that we have a recoveredTransactionManagerPreparer
+             * (if we need one) create the TxnTable
+             */
+            h.txnTable = new TxnTable(h.recoveredTransactionManagerPreparer);
+
+            /* Initialize any non-persistent state we have */
+
+            // Create lease policy objects
+            h.entryLeasePolicy = (LeasePeriodPolicy)Config.getNonNullEntry(
+                config, COMPONENT_NAME, "entryLeasePeriodPolicy",
+                LeasePeriodPolicy.class, 
+                new FixedLeasePeriodPolicy(Long.MAX_VALUE, 1 * DAYS));
+
+            h.eventLeasePolicy = (LeasePeriodPolicy)Config.getNonNullEntry(
+                config, COMPONENT_NAME, "eventLeasePeriodPolicy",
+                LeasePeriodPolicy.class, 
+                new FixedLeasePeriodPolicy(1 * HOURS, 1 * HOURS));
+
+            h.contentsLeasePolicy = (LeasePeriodPolicy)Config.getNonNullEntry(
+                config, COMPONENT_NAME, "contentsLeasePeriodPolicy",
+                LeasePeriodPolicy.class, 
+                new FixedLeasePeriodPolicy(1 * HOURS, 1 * HOURS));
+
+            h.nextLimit = Config.getIntEntry(config, COMPONENT_NAME, 
+                "iteratorBatchSize", 100, 1, Integer.MAX_VALUE);
+
+            h.takeLimit = Config.getIntEntry(config, COMPONENT_NAME, 
+                "takeMultipleLimit", 100, 1, Integer.MAX_VALUE);
+
+            h.maxUnexportDelay = Config.getLongEntry(config, COMPONENT_NAME, 
+                "maxUnexportDelay", 2 * MINUTES, 0, Long.MAX_VALUE);
+
+            h.unexportRetryDelay = Config.getLongEntry(config, COMPONENT_NAME, 
+                "unexportRetryDelay", SECONDS, 1, Long.MAX_VALUE);
+
+
+            // Create threads but don't start.
+            final long reapingInterval = 
+                Config.getLongEntry(config, COMPONENT_NAME,	"reapingInterval", 
+                                    10000, 1, Long.MAX_VALUE);
+
+            final int reapingPriority = 
+                Config.getIntEntry(config, COMPONENT_NAME,"reapingPriority", 
+                    Thread.NORM_PRIORITY, Thread.MIN_PRIORITY, 
+                    Thread.MAX_PRIORITY);
+
+            h.templateReaperThread = new TemplateReaper(reapingInterval);
+            h.templateReaperThread.setPriority(reapingPriority);
+            h.templateReaperThread.setDaemon(true);
+            h.entryReaperThread = new EntryReaper(reapingInterval);
+            h.entryReaperThread.setPriority(reapingPriority);
+            h.entryReaperThread.setDaemon(true);
+            h.contentsQueryReaperThread = new ContentsQueryReaper(reapingInterval);
+            h.contentsQueryReaperThread.setPriority(reapingPriority);
+            h.contentsQueryReaperThread.setDaemon(true);
+            return h;
+        } catch (IOException e) {
+            unwindExporter(h.ourRemoteRef, h.exporter);
+            throw e;
+        } catch (ConfigurationException e){
+            unwindExporter(h.ourRemoteRef, h.exporter);
+            throw e;
+        } catch (ActivationException e){
+            unwindExporter(h.ourRemoteRef, h.exporter);
+            throw e;
+        }
     }
 
     /**
@@ -827,64 +1012,18 @@ public class OutriggerServerImpl 
 
 	lifecycleLogger.log(Level.SEVERE, 
 	    "exception encountered while (re)starting server", cause);
-
-	// If we created a JoinStateManager,
-	try {
-	    joinStateManager.destroy();
-	} catch (Throwable t) {
-	    // Ignore and go on
-	}
-
-	// If we exported, unexport, use force=true since no calls we
-	// care about should be in progress.
-	if (ourRemoteRef != null) {
-	    try {
-		exporter.unexport(true);
-	    } catch (Throwable t) {
-		// Ignore and go on
-	    }
-	}
-
-	if (expirationOpQueue != null)
-	    expirationOpQueue.terminate();
-
-	if (txnMonitor != null) {
-	    try {
-		txnMonitor.destroy();
-	    } catch (Throwable t) {
-		// Ignore and go on
-	    }
-	}
-
-	// Interrupt and join independent threads
-	if (notifier != null) {
-	    try {
-		notifier.terminate();
-	    } catch (Throwable t) {
-		// Ignore and go on
-	    }
-	}
-
-	if (operationJournal != null) {
-	    try {
-		operationJournal.terminate();
-	    } catch (Throwable t) {
-		// Ignore and go on
-	    }	       
-	}
-
-	unwindReaper(templateReaperThread);
-	unwindReaper(entryReaperThread);
-	unwindReaper(contentsQueryReaperThread);
-
-	// Close (but do not destroy) the store
-	if (store != null) {
-	    try {
-		store.close();
-	    } catch (Throwable t) {
-		// Ignore and go on
-	    }
-	}
+    }
+    
+    private void unwindExporter(OutriggerServer os, Exporter e){
+        // If we exported, unexport, use force=true since no calls we
+            // care about should be in progress.
+            if (os != null) {
+                try {
+                    e.unexport(true);
+                } catch (Throwable t) {
+                    // Ignore and go on
+                }
+            }
     }
 
     /** Kill the given reaper as quickly and quietly */
@@ -907,7 +1046,7 @@ public class OutriggerServerImpl 
      */
     private void recoverTxns() {
 
-	if (recoveredTxns == null)
+	if (recoveredTxns.isEmpty())
 	    return;
 
 	// Only PREPARED transactions are recovered. Since the txn
@@ -924,11 +1063,11 @@ public class OutriggerServerImpl 
 	// Monitor all of the pending transactions
 	//
 	monitor(values);
-	recoveredTxns = null;		// done with this list
+	recoveredTxns.clear();		// done with this list
     }
 
     long getSessionId() {
-	return sessionId;
+	return sessionId.get();
     }
 
     /**
@@ -3319,9 +3458,9 @@ public class OutriggerServerImpl 
      * @see LogOps#bootOp
      */  
     public void recoverSessionId(long sessionId) {
-	long    bumpValue = Integer.MAX_VALUE;
+            long    bumpValue = Integer.MAX_VALUE;
 
-	this.sessionId = sessionId + bumpValue;
+            this.sessionId.addAndGet(bumpValue);
     }    
 
     public void recoverJoinState(StoredObject state) throws Exception {
@@ -3357,10 +3496,6 @@ public class OutriggerServerImpl 
     {
 	Txn txn = new Txn(txnId.longValue());
 	transaction.restore(txn);
-
-	if (recoveredTxns == null)
-	    recoveredTxns = new HashMap();
-
 	recoveredTxns.put(txnId, txn);
     }
 
@@ -3369,7 +3504,7 @@ public class OutriggerServerImpl 
 	    return null;
 
 	Txn txn;
-	if((recoveredTxns == null) || 
+	if((recoveredTxns.isEmpty()) || 
 	   ((txn = (Txn)recoveredTxns.get(txnId)) == null))
 	    throw new InternalSpaceException("recover of write/take with " +
 					     "unknown txnId" );

Modified: river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/outrigger/OutriggerServerWrapper.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/outrigger/OutriggerServerWrapper.java?rev=1457436&r1=1457435&r2=1457436&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/outrigger/OutriggerServerWrapper.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/outrigger/OutriggerServerWrapper.java Sun Mar 17 12:32:10 2013
@@ -47,6 +47,7 @@ import net.jini.config.ConfigurationExce
 import net.jini.id.Uuid;
 
 import com.sun.jini.start.LifeCycle;
+import com.sun.jini.start.Starter;
 
 /**
  * For various reasons there is code that we would like
@@ -60,7 +61,7 @@ import com.sun.jini.start.LifeCycle;
  * @since 2.0
  */
 class OutriggerServerWrapper 
-    implements OutriggerServer, ServerProxyTrust, ProxyAccessor
+    implements OutriggerServer, ServerProxyTrust, ProxyAccessor, Starter
 {
     /** The object being delegated to */     
     private final OutriggerServerImpl delegate;
@@ -484,4 +485,8 @@ class OutriggerServerWrapper 
 	gate();
 	return delegate.getProxyVerifier();
     }
+
+    public void start() throws Exception {
+        ((Starter) delegate).start();
+    }
 }

Modified: river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/reggie/RegistrarEvent.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/reggie/RegistrarEvent.java?rev=1457436&r1=1457435&r2=1457436&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/reggie/RegistrarEvent.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/reggie/RegistrarEvent.java Sun Mar 17 12:32:10 2013
@@ -36,20 +36,20 @@ class RegistrarEvent extends ServiceEven
     private static final long serialVersionUID = 2L;
 
     /**
-     * The new state of the item, or null if the item has been
+     * The new state of the serviceItem, or null if the serviceItem has been
      * deleted from the lookup service.  This is either a ServiceItem
      * or an Item (to be converted to a ServiceItem when unmarshalled).
      *
      * @serial
      */
-    protected Object item;
+    private Object serviceItem;
     /**
-     * The service ID of the item that triggered the event.  This field is used
+     * The service ID of the serviceItem that triggered the event.  This field is used
      * instead of the inherited serviceID field (which is set to null) and is
      * written directly as a 128-bit value in order to avoid potential codebase
      * annotation loss (see bug 4745728).
      */
-    protected transient ServiceID servID;
+    private transient ServiceID servID;
 
     /**
      * Simple constructor.
@@ -58,9 +58,9 @@ class RegistrarEvent extends ServiceEven
      * @param eventID the registration eventID
      * @param seqNo the sequence number of this event
      * @param handback the client handback
-     * @param serviceID the serviceID of the item that triggered the event
+     * @param serviceID the serviceID of the serviceItem that triggered the event
      * @param transition the transition that triggered the event
-     * @param item the new state of the item, or null if deleted
+     * @param serviceItem the new state of the serviceItem, or null if deleted
      */
     public RegistrarEvent(Object source,
 			  long eventID,
@@ -71,16 +71,16 @@ class RegistrarEvent extends ServiceEven
 			  Item item)
     {
 	super(source, eventID, seqNo, handback, null, transition);
-	this.item = item;
+	this.serviceItem = item;
 	servID = serviceID;
     }
 
     /**
-     * Returns the new state of the item, or null if the item was deleted
+     * Returns the new state of the serviceItem, or null if the serviceItem was deleted
      * from the lookup service.
      */
     public ServiceItem getServiceItem() {
-	return (ServiceItem)item;
+	return (ServiceItem)serviceItem;
     }
 
     // javadoc inherited from ServiceEvent
@@ -90,7 +90,7 @@ class RegistrarEvent extends ServiceEven
 
     /**
      * Writes the default serializable field value for this instance, followed
-     * by the item's service ID encoded as specified by the
+     * by the serviceItem's service ID encoded as specified by the
      * ServiceID.writeBytes method.
      */
     private void writeObject(ObjectOutputStream out) throws IOException {
@@ -100,8 +100,8 @@ class RegistrarEvent extends ServiceEven
 
     /**
      * Reads the default serializable field value for this instance, followed
-     * by the item's service ID encoded as specified by the
-     * ServiceID.writeBytes method.  If the value of the item field is an Item
+     * by the serviceItem's service ID encoded as specified by the
+     * ServiceID.writeBytes method.  If the value of the serviceItem field is an Item
      * instance, converts it to a ServiceItem.
      */
     private void readObject(ObjectInputStream in)
@@ -109,7 +109,7 @@ class RegistrarEvent extends ServiceEven
     {
 	in.defaultReadObject();
 	servID = new ServiceID(in);
-	if (item instanceof Item)
-	    item = ((Item)item).get();
+	if (serviceItem instanceof Item)
+	    serviceItem = ((Item)serviceItem).get();
     }
 }

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=1457436&r1=1457435&r2=1457436&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 Sun Mar 17 12:32:10 2013
@@ -672,7 +672,7 @@ public class NonActivatableServiceDescri
                 constructor);
             constructor.setAccessible(true);
             impl = constructor.newInstance(argParms);
-            
+            if (impl instanceof Starter) ((Starter) impl).start();
             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=1457436&r1=1457435&r2=1457436&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 Sun Mar 17 12:32:10 2013
@@ -285,6 +285,7 @@ public class ServiceStarter {
 	    try {
    	        if (desc != null) {
 		    result = desc.create(config);
+                    if (result instanceof Starter) ((Starter) result).start();
 	        } 
 	    } catch (Exception e) {
 	        problem = e;

Added: 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=1457436&view=auto
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/Starter.java (added)
+++ river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/Starter.java Sun Mar 17 12:32:10 2013
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.sun.jini.start;
+
+/**
+ * Implemented by a service to enable starting after construction.
+ * 
+ */
+public interface Starter {
+    /**
+     * Called by the ServiceStarter after construction, allows the service to
+     * delay starting threads until construction is complete, to allow safe
+     * publication of the service in accordance with the JMM.
+     * 
+     * In addition to starting threads after construction, it also allows
+     * services to avoid throwing an exception during construction to avoid
+     * finalise attacks.
+     * 
+     * @throws Exception if there's a problem with construction or startup.
+     */
+    public void start() throws Exception;
+}

Propchange: river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/start/Starter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: river/jtsk/skunk/qa_refactor/trunk/src/net/jini/core/event/EventRegistration.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/net/jini/core/event/EventRegistration.java?rev=1457436&r1=1457435&r2=1457436&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/net/jini/core/event/EventRegistration.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/net/jini/core/event/EventRegistration.java Sun Mar 17 12:32:10 2013
@@ -18,6 +18,8 @@
 
 package net.jini.core.event;
 
+import java.io.IOException;
+import java.io.ObjectInputStream;
 import net.jini.core.lease.Lease;
 
 /**
@@ -49,31 +51,33 @@ public class EventRegistration implement
      *
      * @serial
      */
-    protected long eventID;
+    private final long eventID;
 
     /**
      * The event source.
      *
      * @serial
      */
-    protected Object source;
+    private final Object source;
 
     /**
      * The registration lease.
      *
      * @serial
      */
-    protected Lease lease;
+    private final Lease lease;
 
     /**
      * The current sequence number.
      *
      * @serial
      */
-    protected long seqNum;
+    private final long seqNum;
 
     /**
      * Constructs an <tt>EventRegistration</tt> object.
+     * 
+     * Immutable since 2.3.0
      *
      * @param eventID  a <tt>long</tt> representing the event identifier
      * @param source   an <tt>Object</tt> representing the event source
@@ -135,4 +139,15 @@ public class EventRegistration implement
     public long getSequenceNumber() {
 	return seqNum;
     }
+    
+    /**
+     * Default read object, in case of future evolution.
+     * @serial
+     * @param in
+     * @throws IOException
+     * @throws ClassNotFoundException 
+     */
+    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException{
+        in.defaultReadObject();
+    }
 }

Modified: river/jtsk/skunk/qa_refactor/trunk/src/net/jini/core/event/RemoteEvent.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/net/jini/core/event/RemoteEvent.java?rev=1457436&r1=1457435&r2=1457436&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/net/jini/core/event/RemoteEvent.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/net/jini/core/event/RemoteEvent.java Sun Mar 17 12:32:10 2013
@@ -72,6 +72,8 @@ import java.rmi.MarshalledObject;
  * RemoteEvent object being sent occurs outside of the scope of the
  * transaction (but is visible within the transaction).
  *
+ * Immutable since 2.3.0
+ * 
  * @author Sun Microsystems, Inc.
  *
  * @since 1.0
@@ -85,28 +87,28 @@ public class RemoteEvent extends java.ut
      *
      * @serial
      */
-    protected Object source;
+    private final Object source;
 
     /**
      * The event identifier.
      *
      * @serial
      */
-    protected long eventID;
+    private final long eventID;
 
     /**
      * The event sequence number.
      *
      * @serial
      */
-    protected long seqNum;
+    private final long seqNum;
 
     /**
      * The handback object.
      *
      * @serial
      */
-    protected MarshalledObject handback;
+    private final MarshalledObject handback;
 
     /**
      * Constructs a RemoteEvent object.
@@ -134,7 +136,16 @@ public class RemoteEvent extends java.ut
 	this.seqNum = seqNum;
 	this.handback = handback;
     }
-
+    
+    /**
+     * The object on which the RemoteEvent initially occurred.
+     *
+     * @return   The object on which the RemoteEvent initially occurred.
+     */
+    public Object getSource(){
+        return source;
+    }
+    
     /**
      * Returns the event identifier, used to identify the kind of event
      * relative to the object in which the event occurred.

Modified: river/jtsk/skunk/qa_refactor/trunk/src/net/jini/core/lookup/ServiceEvent.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/net/jini/core/lookup/ServiceEvent.java?rev=1457436&r1=1457435&r2=1457436&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/net/jini/core/lookup/ServiceEvent.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/net/jini/core/lookup/ServiceEvent.java Sun Mar 17 12:32:10 2013
@@ -113,7 +113,7 @@ public abstract class ServiceEvent exten
 	        sBuffer.append("UNKNOWN_TRANSITION:").append(
 	            transition);
 	}
-	sBuffer.append(", source=").append(source).append(
+	sBuffer.append(", source=").append(getSource()).append(
 	    ", eventID=").append(getID()).append(
 	    ", seqNum=").append(getSequenceNumber()).append(
 	    ", handback=").append(getRegistrationObject());

Modified: river/jtsk/skunk/qa_refactor/trunk/src/net/jini/discovery/LookupDiscovery.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/net/jini/discovery/LookupDiscovery.java?rev=1457436&r1=1457435&r2=1457436&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/net/jini/discovery/LookupDiscovery.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/net/jini/discovery/LookupDiscovery.java Sun Mar 17 12:32:10 2013
@@ -2122,6 +2122,7 @@ public class LookupDiscovery implements 
             announcementTimerThread = null;
             announceeThread = null;
             notifierThread = null;
+            started = true;
             return;
         } 
         
@@ -2159,6 +2160,9 @@ public class LookupDiscovery implements 
     /**
      * In previous releases threads were started in the constructor, however
      * this violates safe construction according to the JMM.
+     * <p>
+     * Threads will be started automatically when a <code>DiscoveryListener</code>
+     * is added, if start hasn't been called.
      * 
      * @since 2.2.1
      */

Modified: river/jtsk/skunk/qa_refactor/trunk/src/net/jini/discovery/RemoteDiscoveryEvent.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/net/jini/discovery/RemoteDiscoveryEvent.java?rev=1457436&r1=1457435&r2=1457436&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/net/jini/discovery/RemoteDiscoveryEvent.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/net/jini/discovery/RemoteDiscoveryEvent.java Sun Mar 17 12:32:10 2013
@@ -536,7 +536,7 @@ public class RemoteDiscoveryEvent extend
     {
         s.defaultReadObject();
         /* Verify source */
-        if(source == null) {
+        if(getSource() == null) {
             throw new InvalidObjectException("RemoteDiscoveryEvent.readObject "
                                             +"failure - source field is null");
         }//endif

Modified: river/jtsk/skunk/qa_refactor/trunk/src/net/jini/lease/ExpirationWarningEvent.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/net/jini/lease/ExpirationWarningEvent.java?rev=1457436&r1=1457435&r2=1457436&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/net/jini/lease/ExpirationWarningEvent.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/net/jini/lease/ExpirationWarningEvent.java Sun Mar 17 12:32:10 2013
@@ -72,6 +72,6 @@ public class ExpirationWarningEvent exte
      * @return the lease associated with the source of this event
      */
     public Lease getRenewalSetLease() {
-	return ((LeaseRenewalSet) source).getRenewalSetLease();
+	return ((LeaseRenewalSet) getSource()).getRenewalSetLease();
     }
 }

Modified: river/jtsk/skunk/qa_refactor/trunk/src/net/jini/space/AvailabilityEvent.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/net/jini/space/AvailabilityEvent.java?rev=1457436&r1=1457435&r2=1457436&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/net/jini/space/AvailabilityEvent.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/net/jini/space/AvailabilityEvent.java Sun Mar 17 12:32:10 2013
@@ -82,10 +82,10 @@ public abstract class AvailabilityEvent 
     {
 	in.defaultReadObject();
 
-	if (source == null)
+	if (getSource() == null)
 	    throw new InvalidObjectException("null source reference");
 
-	if (!(source instanceof JavaSpace)) 
+	if (!(getSource() instanceof JavaSpace)) 
 	    throw new InvalidObjectException("source is not a JavaSpace");
     }