river-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter_firmst...@apache.org
Subject svn commit: r1468119 [2/15] - in /river/jtsk/skunk/qa_refactor/trunk: qa/src/com/sun/jini/qa/harness/ qa/src/com/sun/jini/test/impl/mahalo/ qa/src/com/sun/jini/test/resources/ qa/src/com/sun/jini/test/share/ qa/src/com/sun/jini/test/spec/javaspace/conf...
Date Mon, 15 Apr 2013 15:26:46 GMT
Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/txnmanager/CommitThread.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/txnmanager/CommitThread.java?rev=1468119&r1=1468118&r2=1468119&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/txnmanager/CommitThread.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/txnmanager/CommitThread.java Mon Apr 15 15:26:44 2013
@@ -1,50 +1,51 @@
-/*
- * 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.test.spec.txnmanager;
-import net.jini.core.transaction.*;
-import java.rmi.RemoteException;
-
-
-class CommitThread extends Thread {
-    long timeOut;
-    Transaction tr;
-
-    public CommitThread(Transaction tr) {
-        this.tr = tr;
-    }
-
-    public CommitThread(Transaction tr, long timeOut) {
-        this(tr);
-
-        if (timeOut < 0) {
-            throw new IllegalArgumentException("timeout must be non-negative");
-        }
-        this.timeOut = timeOut;
-    }
-
-    public void run() {
-        try {
-            if (timeOut > 0) {
-                tr.commit(timeOut);
-            } else {
-                tr.commit();
-            }
-        } catch (TransactionException bte) {
-        } catch (RemoteException re) {}
-    }
-}
+/*
+ * 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.test.spec.txnmanager;
+import net.jini.core.transaction.*;
+import java.rmi.RemoteException;
+
+
+class CommitThread extends Thread {
+    final long timeOut;
+    final Transaction tr;
+
+    public CommitThread(Transaction tr) {
+        this.tr = tr;
+        timeOut = 0;
+    }
+
+    public CommitThread(Transaction tr, long timeOut) {
+        this.tr = tr;
+
+        if (timeOut < 0) {
+            throw new IllegalArgumentException("timeout must be non-negative");
+        }
+        this.timeOut = timeOut;
+    }
+
+    public void run() {
+        try {
+            if (timeOut > 0) {
+                tr.commit(timeOut);
+            } else {
+                tr.commit();
+            }
+        } catch (TransactionException bte) {
+        } catch (RemoteException re) {}
+    }
+}

Modified: river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/collection/WeakTable.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/collection/WeakTable.java?rev=1468119&r1=1468118&r2=1468119&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/collection/WeakTable.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/collection/WeakTable.java Mon Apr 15 15:26:44 2013
@@ -1,187 +1,192 @@
-/*
- * 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.collection;
-
-import java.io.PrintStream;
-import java.lang.ref.Reference;
-import java.lang.ref.ReferenceQueue;
-import java.lang.ref.WeakReference;
-import java.util.HashMap;
-
-/**
- * This class is designed to allow weakly held keys to weakly held
- * objects.  For example, it can be used for smart proxy objects that
- * maintain equality for references to the same remote server.  If a
- * single VM twice invokes a remote method that returns a proxy for the
- * same JavaSpaces server, the references returned by that method 
- * should be the same.  This allows <code>==</code> tests to work for 
- * proxies to remote servers the same as they would for direct references 
- * to remote servers, which also maintain this property.
- * <p>
- * Here is an example that uses this class to ensure that exactly one
- * copy of a <code>java.io.Resolvable</code> object exists in each
- * VM:
- * <pre>
- *  private WeakTable knownProxies;
- *
- *  public Object readResolve() {
- *      // deferred creation means this table is not allocated on the server
- *      if (knownProxies == null)
- *          knownProxies = new WeakTable();
- *      return knownProxies.getOrAdd(remoteServer, this);
- *  }
- * </pre>
- *
- * @author Sun Microsystems, Inc.
- *
- */
-public class WeakTable {
-    /** The map of known objects.  */
-    private HashMap		table = new HashMap();
-
-    /** The queue of cleared SpaceProxy objects. */
-    private ReferenceQueue	refQueue = new ReferenceQueue();
-
-    /** Print debug messages to this stream if not <code>null</code>. */
-    private static PrintStream		DEBUG = null;
-
-    /** Object to call back when keys are collected */
-    private KeyGCHandler handler = null;
-
-    /**
-     * Create a new WeakTable object to maintain the maps.
-     */
-    public WeakTable() {
-	if (DEBUG != null)
-	    DEBUG.println("Creating WeakTable");
-
-	table = new HashMap();
-	refQueue = new ReferenceQueue();
-    }
-
-    /**
-     * Create a new WeakTable object to maintain the maps that calls
-     * back the designated object when keys are collected.
-     */
-    public WeakTable(KeyGCHandler handler) {
-	this();
-	this.handler = handler;
-    }
-
-    /**
-     * Return the object that this key maps to.  If it currently maps to
-     * no object, set it to map to the given object.  Return either the
-     * existing entry or the new one, whichever is used.
-     */
-    public synchronized Object getOrAdd(Object key, Object proxy) {
-	Object existing = get(key);
-
-	if (existing != null) {
-	    if (DEBUG != null)
-		DEBUG.println("WeakTable.getOrAdd: found " + existing);
-	    return existing;
-	} else {
-	    if (DEBUG != null)
-		DEBUG.println("WeakTable.getOrAdd: adding " + proxy);
-	    table.put(new WeakKeyReference(key, refQueue),
-			     new WeakReference(proxy, refQueue));
-	    return proxy;
-	}
-    }
-
-    /**
-     * Return the value associated with given key, or <code>null</code>
-     * if no value can be found.
-     */
-    public synchronized Object get(Object key) {
-	removeBlanks();
-	WeakKeyReference keyRef = new WeakKeyReference(key);
-	WeakReference ref = (WeakReference) table.get(keyRef);
-	Object existing = (ref == null ? null : ref.get());
-	if (DEBUG != null) {
-	    DEBUG.println("WeakTable.get:ref = " + ref
-			       + ", existing = " + existing);
-	}
-
-	return existing;
-    }
-
-    /**
-     * Remove the object that the given key maps to.  If found return
-     * the object, otherwise return null.
-     */
-    public synchronized Object remove(Object key) {
-	removeBlanks();
-	WeakKeyReference keyRef = new WeakKeyReference(key);
-	WeakReference ref = (WeakReference) table.remove(keyRef);
-	if (ref == null) return null;
-	return ref.get();
-    }
-    
-    /**
-     * Remove any blank entries from the table.  This can be invoked
-     * by a reaping thread if you like.
-     */
-    /*
-     * We only clear table entries when the key shows up in the queue,
-     * since that is much more efficient.  Since the key is usually the
-     * remote reference, and since the remote reference is usually
-     * referenced only from the proxy, the key reference should be
-     * cleared around the same time as the proxy reference.  If not,
-     * then all the hangs around unnecessarily is this table entry,
-     * which is small.  This tradeoff seems worth the significant
-     * efficiency of using the HashMap in the intended way -- efficient
-     * key access.
-     */
-    public synchronized void removeBlanks() {
-	if (DEBUG != null)
-	    DEBUG.println("WeakTable.removeBlanks: starting");
-	Reference ref;
-	while ((ref = refQueue.poll()) != null) {
-	    if (ref instanceof WeakKeyReference) {
-		final WeakReference valref = (WeakReference)table.remove(ref);
-		if (valref != null && handler != null && valref.get() != null) 
-		    handler.keyGC(valref.get());
-
-		if (DEBUG != null) {
-		    boolean removed = (valref != null);		    
-		    DEBUG.print("WeakTable.removeBlanks: key=" + ref);
-		    DEBUG.println(", " + (removed ? "" : "!") + "removed, "
-				  + table.size() + " remain");
-		}
-	    } else {
-		if (DEBUG != null)
-		    DEBUG.println("WeakTable.removeBlanks: value=" + ref);
-	    }
-	}
-	if (DEBUG != null)
-	    DEBUG.println("WeakTable.removeBlanks: finished");
-    }
-
-    /**
-     * Handler for clients that need to know when a key is removed
-     * from the table because it has been collected.
-     */
-    public static interface KeyGCHandler {
-	/** Called by WeakTable when it notices that a key has been
-	 *   collected and the value still exists. 
-	 *   @param value The value associated with the collected key
-	 */
-	public void keyGC(Object value);
-    }
-}
+/*
+ * 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.collection;
+
+import java.io.PrintStream;
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.WeakReference;
+import java.util.HashMap;
+
+/**
+ * This class is designed to allow weakly held keys to weakly held
+ * objects.  For example, it can be used for smart proxy objects that
+ * maintain equality for references to the same remote server.  If a
+ * single VM twice invokes a remote method that returns a proxy for the
+ * same JavaSpaces server, the references returned by that method 
+ * should be the same.  This allows <code>==</code> tests to work for 
+ * proxies to remote servers the same as they would for direct references 
+ * to remote servers, which also maintain this property.
+ * <p>
+ * Here is an example that uses this class to ensure that exactly one
+ * copy of a <code>java.io.Resolvable</code> object exists in each
+ * VM:
+ * <pre>
+ *  private WeakTable knownProxies;
+ *
+ *  public Object readResolve() {
+ *      // deferred creation means this table is not allocated on the server
+ *      if (knownProxies == null)
+ *          knownProxies = new WeakTable();
+ *      return knownProxies.getOrAdd(remoteServer, this);
+ *  }
+ * </pre>
+ *
+ * @author Sun Microsystems, Inc.
+ *
+ */
+public class WeakTable {
+    /** The map of known objects.  */
+    private final HashMap table;
+
+    /** The queue of cleared SpaceProxy objects. */
+    private final ReferenceQueue refQueue;
+
+    /** Print debug messages to this stream if not <code>null</code>. */
+    private static PrintStream		DEBUG = null;
+
+    /** Object to call back when keys are collected */
+    private final KeyGCHandler handler;
+
+    /**
+     * Create a new WeakTable object to maintain the maps.
+     */
+    public WeakTable() {
+	if (DEBUG != null)
+	    DEBUG.println("Creating WeakTable");
+
+	table = new HashMap();
+	refQueue = new ReferenceQueue();
+        handler = null;
+    }
+
+    /**
+     * Create a new WeakTable object to maintain the maps that calls
+     * back the designated object when keys are collected.
+     */
+    public WeakTable(KeyGCHandler handler) {
+        if (DEBUG != null)
+	    DEBUG.println("Creating WeakTable");
+
+	table = new HashMap();
+	refQueue = new ReferenceQueue();
+	this.handler = handler;
+    }
+
+    /**
+     * Return the object that this key maps to.  If it currently maps to
+     * no object, set it to map to the given object.  Return either the
+     * existing entry or the new one, whichever is used.
+     */
+    public synchronized Object getOrAdd(Object key, Object proxy) {
+	Object existing = get(key);
+
+	if (existing != null) {
+	    if (DEBUG != null)
+		DEBUG.println("WeakTable.getOrAdd: found " + existing);
+	    return existing;
+	} else {
+	    if (DEBUG != null)
+		DEBUG.println("WeakTable.getOrAdd: adding " + proxy);
+	    table.put(new WeakKeyReference(key, refQueue),
+			     new WeakReference(proxy, refQueue));
+	    return proxy;
+	}
+    }
+
+    /**
+     * Return the value associated with given key, or <code>null</code>
+     * if no value can be found.
+     */
+    public synchronized Object get(Object key) {
+	removeBlanks();
+	WeakKeyReference keyRef = new WeakKeyReference(key);
+	WeakReference ref = (WeakReference) table.get(keyRef);
+	Object existing = (ref == null ? null : ref.get());
+	if (DEBUG != null) {
+	    DEBUG.println("WeakTable.get:ref = " + ref
+			       + ", existing = " + existing);
+	}
+
+	return existing;
+    }
+
+    /**
+     * Remove the object that the given key maps to.  If found return
+     * the object, otherwise return null.
+     */
+    public synchronized Object remove(Object key) {
+	removeBlanks();
+	WeakKeyReference keyRef = new WeakKeyReference(key);
+	WeakReference ref = (WeakReference) table.remove(keyRef);
+	if (ref == null) return null;
+	return ref.get();
+    }
+    
+    /**
+     * Remove any blank entries from the table.  This can be invoked
+     * by a reaping thread if you like.
+     */
+    /*
+     * We only clear table entries when the key shows up in the queue,
+     * since that is much more efficient.  Since the key is usually the
+     * remote reference, and since the remote reference is usually
+     * referenced only from the proxy, the key reference should be
+     * cleared around the same time as the proxy reference.  If not,
+     * then all the hangs around unnecessarily is this table entry,
+     * which is small.  This tradeoff seems worth the significant
+     * efficiency of using the HashMap in the intended way -- efficient
+     * key access.
+     */
+    public synchronized void removeBlanks() {
+	if (DEBUG != null)
+	    DEBUG.println("WeakTable.removeBlanks: starting");
+	Reference ref;
+	while ((ref = refQueue.poll()) != null) {
+	    if (ref instanceof WeakKeyReference) {
+		final WeakReference valref = (WeakReference)table.remove(ref);
+		if (valref != null && handler != null && valref.get() != null) 
+		    handler.keyGC(valref.get());
+
+		if (DEBUG != null) {
+		    boolean removed = (valref != null);		    
+		    DEBUG.print("WeakTable.removeBlanks: key=" + ref);
+		    DEBUG.println(", " + (removed ? "" : "!") + "removed, "
+				  + table.size() + " remain");
+		}
+	    } else {
+		if (DEBUG != null)
+		    DEBUG.println("WeakTable.removeBlanks: value=" + ref);
+	    }
+	}
+	if (DEBUG != null)
+	    DEBUG.println("WeakTable.removeBlanks: finished");
+    }
+
+    /**
+     * Handler for clients that need to know when a key is removed
+     * from the table because it has been collected.
+     */
+    public static interface KeyGCHandler {
+	/** Called by WeakTable when it notices that a key has been
+	 *   collected and the value still exists. 
+	 *   @param value The value associated with the collected key
+	 */
+	public void keyGC(Object value);
+    }
+}

Modified: river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/mahalo/AbortJob.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/mahalo/AbortJob.java?rev=1468119&r1=1468118&r2=1468119&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/mahalo/AbortJob.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/mahalo/AbortJob.java Mon Apr 15 15:26:44 2013
@@ -1,291 +1,293 @@
-/*
- * 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.mahalo;
-
-import com.sun.jini.mahalo.log.ClientLog;
-import com.sun.jini.thread.TaskManager;
-import com.sun.jini.thread.WakeupManager;
-
-import java.rmi.activation.ActivateFailedException;
-import java.rmi.RemoteException;
-import java.rmi.NoSuchObjectException;
-import java.rmi.MarshalException;
-import java.rmi.UnknownHostException;
-import java.rmi.ConnectIOException;
-import java.rmi.AccessException;
-import java.rmi.ConnectException;
- 
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import net.jini.core.transaction.Transaction;
-import net.jini.core.transaction.TransactionException;
-import net.jini.core.transaction.server.ServerTransaction;
-import net.jini.core.transaction.server.TransactionConstants;
-import net.jini.core.transaction.server.TransactionParticipant;
-
-/**
- * An implementation of a <code>com.sun.jini.mahalo.Job</code> which
- * interacts with a set of
- * <code>net.jini.core.transaction.server.TransactionParticipant</code>s
- * to inform them to roll back changes associated with a given
- * <code>net.jini.core.transaction.Transaction</code>.
- *
- * @author Sun Microsystems, Inc.
- *
- * @see com.sun.jini.mahalo.Job
- * @see com.sun.jini.mahalo.ParticipantTask
- * @see net.jini.core.transaction.Transaction
- * @see net.jini.core.transaction.server.TransactionParticipant
- *
- */
-public class AbortJob extends Job implements TransactionConstants {
-    ServerTransaction tr;
-    ClientLog log;
-    ParticipantHandle[] handles;
-    int maxtries = 5;
-    static final Logger logger = TxnManagerImpl.participantLogger;
-    
-    /**
-     * Constructs an <code>AbortJob</code>
-     *
-     *
-     * @param tr The <code>Transaction</code> whose participants
-     *           will be instructed to roll-back.
-     *
-     * @param pool The <code>TaskManager</code> which provides the
-     *             threads used for interacting with participants.
-     *
-     * @param log  The <code>ClientLog</code> used for recording
-     *             recovery data.
-     *
-     * @param handles The array of participants which will be contacted
-     *                and informed to roll-back.
-     *
-     * @see com.sun.jini.thread.TaskManager
-     * @see com.sun.jini.mahalo.log.ClientLog
-     * @see net.jini.core.transaction.server.TransactionParticipant
-     */
-    public AbortJob(Transaction tr, TaskManager pool,
-		      WakeupManager wm, ClientLog log,
-		      ParticipantHandle[] handles) {
-	super(pool, wm);
-
-	if (log == null)
-	    throw new IllegalArgumentException("AbortJob: AbortJob: " +
-							"log is null");
-
-	this.log = log;
-
-        if (!(tr instanceof ServerTransaction))
-            throw new IllegalArgumentException("PrepareJob: PrepareJob: " +
-                                        "must be a ServerTransaction");
- 
-        this.tr =  (ServerTransaction) tr;
- 
-        if (handles == null)
-            throw new IllegalArgumentException("PrepareJob: PrepareJob: " +
-                                        "must have participants");
- 
-        if (handles.length == 0)
-            throw new IllegalArgumentException("PrepareJob: PrepareJob: " +
-                                        "must have participants");
- 
-        this.handles = handles;
-    }
-
-    /**
-     * Creates the <code>TaskManager.Task</code>s necessary to
-     * inform participants to roll-back.
-     */
-    TaskManager.Task[] createTasks() {
-	TaskManager.Task[] tmp = new TaskManager.Task[handles.length];
-
-	for (int i = 0; i < handles.length; i++) {
-	    tmp[i] = 
-	        new ParticipantTask(getPool(), getMgr(), this, handles[i]);
-	}
-
-	return tmp;
-    }
-
-    /**
-     * The work to be performed by each <code>TaskManager.Task</code>
-     * is provided by the <code>Job</code> that creates it.
-     * The work performed by a task belonging to the AbortJob
-     * contacts a participant, instructs it to roll-back and
-     * log appropriately.
-     *
-     * @param who The task performing the work
-     *
-     * @param param A parameter, of the task's choosing, useful
-     *              in performing work.
-     *
-     * @see com.sun.jini.mahalo.Job
-     * @see com.sun.jini.thread.TaskManager.Task
-     */
-    Object doWork(TaskManager.Task who, Object param) {
-        ParticipantHandle handle = (ParticipantHandle)param;
-        TransactionParticipant par = null;
- 
-        //check if a vote already exists because it was
-        //recovered from the log. In this situation,
-        //we do not need to log this info since it
-        //exists in the log which was used for recovery...
-
-        if (logger.isLoggable(Level.FINEST)) {
-            logger.log(Level.FINEST,
-                "AbortJob:doWork aborting handle: {0}", handle);
-	}
-	int vote = 0;
- 
-        vote = handle.getPrepState();
- 
-        switch (vote) {
-            case NOTCHANGED:
-            case ABORTED:
-                return Integer.valueOf(ABORTED);
-        }
- 
-        //Instruct the TransactionParticipant to roll back
-        //after unpacking it and checking against the
-        //max retry threshold.
- 
-        if (par == null)
-            par = handle.getPreParedParticipant();
- 
-        //If you have exhausted the max retry threshold
-        //stop, so that no further attempts are made.
- 
-	try {
-            if (attempt(who) > maxtries) {
-                return Integer.valueOf(ABORTED);
-            }
-	} catch (JobException je) {
-	    return null;
-	}
-
- 
- 
-        //At this point, if participant is null, there
-        //must be an error unpacking, so retry later
-        if (par == null)
-            return null;
- 
- 
-        //Here we actually need to instruct the participant to
-        //roll back.  Note the RemoteException causes a
-        //retry. Here we only log info for the cases
-        //where a final outcome is available.
-	//
-	//Note: handle UnknownHostException and
-	//      NoSuchObjectException (activation problem)
- 
-        Object response = null;
- 
-        try {
-            par.abort(tr.mgr, tr.id);
-            response = Integer.valueOf(ABORTED);
-        } catch (TransactionException bte) {
-            //The participant doesn't have record of the
-            //transaction, so it must have already rolled
-            //back.
-            response = Integer.valueOf(ABORTED);
-        } catch (NoSuchObjectException nsoe) {
-            //No definition for object in VM, so stop
-            //and consider committed.
-            response = Integer.valueOf(ABORTED);
-        } catch (ConnectException ce) {
-            //failure setting up connection, so give
-            //participant more time by retrying
-        } catch (UnknownHostException uhe) {
-            //could not resolve host for participant, so
-            //stop and consider committed
-            response = Integer.valueOf(ABORTED);
-        } catch (ConnectIOException cioe) {
-            //multiplexed connection or cached
-            //connection problem, give participant more time
-        } catch (MarshalException me) {
-            //cannot send parameters, so stop and consider done
-            response = Integer.valueOf(ABORTED);
-        } catch (AccessException ae) {
-            //Access error on registry or rmid consider done
-            response = Integer.valueOf(ABORTED);
-        } catch (ActivateFailedException afe) {
-            //Activatable Ref Stub couldn't activate
-            //participant, so stop and consider done
-            response = Integer.valueOf(ABORTED);
-        } catch (RemoteException re) {
-            //Something happened with the network, so
-            //retry at a later time.
-        } catch (RuntimeException rte) {
-            //Something happened with the participant, so
-            //stop retrying
-	    response = Integer.valueOf(ABORTED);
-        }
- 
-        if (response != null) {
-	    handle.setPrepState(ABORTED);
-            try {
-                log.write( new ParticipantAbortRecord(handle));
-            } catch (com.sun.jini.mahalo.log.LogException le) {
-                //the full package name used to disambiguate
-                //the LogException
-            }
-
-	    return response;
-        }
- 
-        return null;
-    }
-
-    /**
-     * Gathers partial results submitted by tasks and produces
-     * a single outcome.
-     *
-     * @see com.sun.jini.mahalo.Job
-     */
-    Object computeResult() throws JobException {
-	try {
-	    if (!isCompleted(0))
-	        throw new ResultNotReadyException("Cannot compute result " +
-					"since there are jobs pending");
-	} catch (JobNotStartedException jnse) {
-	    throw new ResultNotReadyException("Cannot compute result since" +
-					   " jobs were not created");
-	}
-
-	int tmp = 0;
-	int count = 0;
-
-	checkresults:
-	for (int i = 0; i < results.length; i++) {
-	    tmp = ((Integer)results[i]).intValue();
-
-	    if (tmp == ABORTED)
-		count++;
-	}
-
-        if (logger.isLoggable(Level.FINEST)) {
-            logger.log(Level.FINEST,
-                "AbortJob:computeResult {0} participants ABORTED", 
-		Integer.valueOf(count));
-	}
-
-	return Integer.valueOf(ABORTED);
-    }
-}
+/*
+ * 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.mahalo;
+
+import com.sun.jini.mahalo.log.ClientLog;
+import com.sun.jini.thread.TaskManager;
+import com.sun.jini.thread.WakeupManager;
+
+import java.rmi.activation.ActivateFailedException;
+import java.rmi.RemoteException;
+import java.rmi.NoSuchObjectException;
+import java.rmi.MarshalException;
+import java.rmi.UnknownHostException;
+import java.rmi.ConnectIOException;
+import java.rmi.AccessException;
+import java.rmi.ConnectException;
+import java.util.Iterator;
+ 
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import net.jini.core.transaction.Transaction;
+import net.jini.core.transaction.TransactionException;
+import net.jini.core.transaction.server.ServerTransaction;
+import net.jini.core.transaction.server.TransactionConstants;
+import net.jini.core.transaction.server.TransactionParticipant;
+
+/**
+ * An implementation of a <code>com.sun.jini.mahalo.Job</code> which
+ * interacts with a set of
+ * <code>net.jini.core.transaction.server.TransactionParticipant</code>s
+ * to inform them to roll back changes associated with a given
+ * <code>net.jini.core.transaction.Transaction</code>.
+ *
+ * @author Sun Microsystems, Inc.
+ *
+ * @see com.sun.jini.mahalo.Job
+ * @see com.sun.jini.mahalo.ParticipantTask
+ * @see net.jini.core.transaction.Transaction
+ * @see net.jini.core.transaction.server.TransactionParticipant
+ *
+ */
+class AbortJob extends Job implements TransactionConstants {
+    final ServerTransaction tr;
+    final ClientLog log;
+    final ParticipantHandle[] handles;
+    final int maxtries = 5;
+    static final Logger logger = TxnManagerImpl.participantLogger;
+    
+    /**
+     * Constructs an <code>AbortJob</code>
+     *
+     *
+     * @param tr The <code>Transaction</code> whose participants
+     *           will be instructed to roll-back.
+     *
+     * @param pool The <code>TaskManager</code> which provides the
+     *             threads used for interacting with participants.
+     *
+     * @param log  The <code>ClientLog</code> used for recording
+     *             recovery data.
+     *
+     * @param handles The array of participants which will be contacted
+     *                and informed to roll-back.
+     *
+     * @see com.sun.jini.thread.TaskManager
+     * @see com.sun.jini.mahalo.log.ClientLog
+     * @see net.jini.core.transaction.server.TransactionParticipant
+     */
+    public AbortJob(Transaction tr, TaskManager pool,
+		      WakeupManager wm, ClientLog log,
+		      ParticipantHandle[] handles) {
+	super(pool, wm);
+
+	if (log == null)
+	    throw new IllegalArgumentException("AbortJob: AbortJob: " +
+							"log is null");
+
+	this.log = log;
+
+        if (!(tr instanceof ServerTransaction))
+            throw new IllegalArgumentException("PrepareJob: PrepareJob: " +
+                                        "must be a ServerTransaction");
+ 
+        this.tr =  (ServerTransaction) tr;
+ 
+        if (handles == null)
+            throw new IllegalArgumentException("PrepareJob: PrepareJob: " +
+                                        "must have participants");
+ 
+        if (handles.length == 0)
+            throw new IllegalArgumentException("PrepareJob: PrepareJob: " +
+                                        "must have participants");
+ 
+        this.handles = handles;
+    }
+
+    /**
+     * Creates the <code>TaskManager.Task</code>s necessary to
+     * inform participants to roll-back.
+     */
+    TaskManager.Task[] createTasks() {
+	TaskManager.Task[] tmp = new TaskManager.Task[handles.length];
+
+	for (int i = 0; i < handles.length; i++) {
+	    tmp[i] = 
+	        new ParticipantTask(getPool(), getMgr(), this, handles[i]);
+	}
+
+	return tmp;
+    }
+
+    /**
+     * The work to be performed by each <code>TaskManager.Task</code>
+     * is provided by the <code>Job</code> that creates it.
+     * The work performed by a task belonging to the AbortJob
+     * contacts a participant, instructs it to roll-back and
+     * log appropriately.
+     *
+     * @param who The task performing the work
+     *
+     * @param param A parameter, of the task's choosing, useful
+     *              in performing work.
+     *
+     * @see com.sun.jini.mahalo.Job
+     * @see com.sun.jini.thread.TaskManager.Task
+     */
+    Object doWork(TaskManager.Task who, Object param) {
+        ParticipantHandle handle = (ParticipantHandle)param;
+        TransactionParticipant par = null;
+ 
+        //check if a vote already exists because it was
+        //recovered from the log. In this situation,
+        //we do not need to log this info since it
+        //exists in the log which was used for recovery...
+
+        if (logger.isLoggable(Level.FINEST)) {
+            logger.log(Level.FINEST,
+                "AbortJob:doWork aborting handle: {0}", handle);
+	}
+	int vote = 0;
+ 
+        vote = handle.getPrepState();
+ 
+        switch (vote) {
+            case NOTCHANGED:
+            case ABORTED:
+                return Integer.valueOf(ABORTED);
+        }
+ 
+        //Instruct the TransactionParticipant to roll back
+        //after unpacking it and checking against the
+        //max retry threshold.
+ 
+        if (par == null)
+            par = handle.getPreParedParticipant();
+ 
+        //If you have exhausted the max retry threshold
+        //stop, so that no further attempts are made.
+ 
+	try {
+            if (attempt(who) > maxtries) {
+                return Integer.valueOf(ABORTED);
+            }
+	} catch (JobException je) {
+	    return null;
+	}
+
+ 
+ 
+        //At this point, if participant is null, there
+        //must be an error unpacking, so retry later
+        if (par == null)
+            return null;
+ 
+ 
+        //Here we actually need to instruct the participant to
+        //roll back.  Note the RemoteException causes a
+        //retry. Here we only log info for the cases
+        //where a final outcome is available.
+	//
+	//Note: handle UnknownHostException and
+	//      NoSuchObjectException (activation problem)
+ 
+        Object response = null;
+ 
+        try {
+            par.abort(tr.mgr, tr.id);
+            response = Integer.valueOf(ABORTED);
+        } catch (TransactionException bte) {
+            //The participant doesn't have record of the
+            //transaction, so it must have already rolled
+            //back.
+            response = Integer.valueOf(ABORTED);
+        } catch (NoSuchObjectException nsoe) {
+            //No definition for object in VM, so stop
+            //and consider committed.
+            response = Integer.valueOf(ABORTED);
+        } catch (ConnectException ce) {
+            //failure setting up connection, so give
+            //participant more time by retrying
+        } catch (UnknownHostException uhe) {
+            //could not resolve host for participant, so
+            //stop and consider committed
+            response = Integer.valueOf(ABORTED);
+        } catch (ConnectIOException cioe) {
+            //multiplexed connection or cached
+            //connection problem, give participant more time
+        } catch (MarshalException me) {
+            //cannot send parameters, so stop and consider done
+            response = Integer.valueOf(ABORTED);
+        } catch (AccessException ae) {
+            //Access error on registry or rmid consider done
+            response = Integer.valueOf(ABORTED);
+        } catch (ActivateFailedException afe) {
+            //Activatable Ref Stub couldn't activate
+            //participant, so stop and consider done
+            response = Integer.valueOf(ABORTED);
+        } catch (RemoteException re) {
+            //Something happened with the network, so
+            //retry at a later time.
+        } catch (RuntimeException rte) {
+            //Something happened with the participant, so
+            //stop retrying
+	    response = Integer.valueOf(ABORTED);
+        }
+ 
+        if (response != null) {
+	    handle.setPrepState(ABORTED);
+            try {
+                log.write( new ParticipantAbortRecord(handle));
+            } catch (com.sun.jini.mahalo.log.LogException le) {
+                //the full package name used to disambiguate
+                //the LogException
+            }
+
+	    return response;
+        }
+ 
+        return null;
+    }
+
+    /**
+     * Gathers partial results submitted by tasks and produces
+     * a single outcome.
+     *
+     * @see com.sun.jini.mahalo.Job
+     */
+    Object computeResult() throws JobException {
+	try {
+	    if (!isCompleted(0))
+	        throw new ResultNotReadyException("Cannot compute result " +
+					"since there are jobs pending");
+	} catch (JobNotStartedException jnse) {
+	    throw new ResultNotReadyException("Cannot compute result since" +
+					   " jobs were not created");
+	}
+
+	int tmp = 0;
+	int count = 0;
+
+        Iterator i = results.values().iterator();
+        while (i.hasNext()){
+            Object res = i.next();
+            if (res instanceof Integer){
+                tmp = ((Integer)res).intValue();
+                if (tmp == ABORTED) count++;
+            }
+        }
+
+        if (logger.isLoggable(Level.FINEST)) {
+            logger.log(Level.FINEST,
+                "AbortJob:computeResult {0} participants ABORTED", 
+		Integer.valueOf(count));
+	}
+
+	return Integer.valueOf(ABORTED);
+    }
+}

Modified: river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/mahalo/AbortRecord.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/mahalo/AbortRecord.java?rev=1468119&r1=1468118&r2=1468119&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/mahalo/AbortRecord.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/mahalo/AbortRecord.java Mon Apr 15 15:26:44 2013
@@ -1,94 +1,94 @@
-/*
- * 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.mahalo;
-
-import com.sun.jini.mahalo.log.CannotRecoverException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * An <code>AbortRecord</code> represents the logged state of
- * a <code>Transaction</code> which has changed to the ABORTED
- * state.
- *
- * @author Sun Microsystems, Inc.
- *
- */
-class AbortRecord implements TxnLogRecord  {
-    /**
-     * @serial
-     */
-    private ParticipantHandle[] parts;
-
-    static final long serialVersionUID = -8121722031382234695L;
-
-    static final Logger logger = TxnManagerImpl.participantLogger;
-
-    /**
-     * Constructs an <code>AbortRecord</code> which  represents a
-     * <code>Transaction</code> which has moved to the ABORTED state.
-     *
-     * @param parts The array of participants joined in the transaction
-     *
-     * @see net.jini.core.transaction.Transaction
-     * @see net.jini.core.transaction.server.TransactionParticipant
-     * @see net.jini.core.transaction.server.TransactionConstants
-     */
-    AbortRecord(ParticipantHandle[] parts) {
-        if (parts == null)
-            throw new IllegalArgumentException("AbortRecord: must specify " +
-                                                "a non-null parts array");
-	this.parts = parts;
-    }
-
-    /**
-     * Recovers the state encapsulated the <code>AbortRecord</code> to
-     * the caller.
-     *
-     * @param tmt  The <code>TxnManagerTransaction</code> to which
-     *             state is recovered.
-     *
-     * @see com.sun.jini.mahalo.TxnManagerTransaction
-     */
-    public void recover(TxnManagerTransaction tmt)
-	throws CannotRecoverException
-    {
-        try {
-            for (int i = 0; i< parts.length; i++) {
-                tmt.add(parts[i]);
-            }
-	    tmt.modifyTxnState(ABORTED);
-        } catch (InternalManagerException ime) {
-            throw new CannotRecoverException("AbortRecord: recover: " +
-                                                        ime.getMessage());
-        }
-
-	if (logger.isLoggable(Level.FINEST)) {
-            logger.log(Level.FINEST, "AbortJob:recover recovered");
-        }    
-    }
-
-    /**
-     * Retrieves the set of <code>TransactionParticipant</code>s associated
-     * with the recovered <code>Transaction</code>.
-     *
-     */
-    ParticipantHandle[] getParts() {
-        return parts;
-    }
-}
+/*
+ * 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.mahalo;
+
+import com.sun.jini.mahalo.log.CannotRecoverException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * An <code>AbortRecord</code> represents the logged state of
+ * a <code>Transaction</code> which has changed to the ABORTED
+ * state.
+ *
+ * @author Sun Microsystems, Inc.
+ *
+ */
+class AbortRecord implements TxnLogRecord  {
+    /**
+     * @serial
+     */
+    private final ParticipantHandle[] parts;
+
+    static final long serialVersionUID = -8121722031382234695L;
+
+    static final Logger logger = TxnManagerImpl.participantLogger;
+
+    /**
+     * Constructs an <code>AbortRecord</code> which  represents a
+     * <code>Transaction</code> which has moved to the ABORTED state.
+     *
+     * @param parts The array of participants joined in the transaction
+     *
+     * @see net.jini.core.transaction.Transaction
+     * @see net.jini.core.transaction.server.TransactionParticipant
+     * @see net.jini.core.transaction.server.TransactionConstants
+     */
+    AbortRecord(ParticipantHandle[] parts) {
+        if (parts == null)
+            throw new IllegalArgumentException("AbortRecord: must specify " +
+                                                "a non-null parts array");
+	this.parts = parts;
+    }
+
+    /**
+     * Recovers the state encapsulated the <code>AbortRecord</code> to
+     * the caller.
+     *
+     * @param tmt  The <code>TxnManagerTransaction</code> to which
+     *             state is recovered.
+     *
+     * @see com.sun.jini.mahalo.TxnManagerTransaction
+     */
+    public void recover(TxnManagerTransaction tmt)
+	throws CannotRecoverException
+    {
+        try {
+            for (int i = 0; i< parts.length; i++) {
+                tmt.add(parts[i]);
+            }
+	    tmt.modifyTxnState(ABORTED);
+        } catch (InternalManagerException ime) {
+            throw new CannotRecoverException("AbortRecord: recover: " +
+                                                        ime.getMessage());
+        }
+
+	if (logger.isLoggable(Level.FINEST)) {
+            logger.log(Level.FINEST, "AbortJob:recover recovered");
+        }    
+    }
+
+    /**
+     * Retrieves the set of <code>TransactionParticipant</code>s associated
+     * with the recovered <code>Transaction</code>.
+     *
+     */
+    ParticipantHandle[] getParts() {
+        return parts;
+    }
+}

Modified: river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/mahalo/CommitJob.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/mahalo/CommitJob.java?rev=1468119&r1=1468118&r2=1468119&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/mahalo/CommitJob.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/mahalo/CommitJob.java Mon Apr 15 15:26:44 2013
@@ -1,285 +1,284 @@
-/*
- * 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.mahalo;
-
-import com.sun.jini.mahalo.log.ClientLog;
-import com.sun.jini.thread.TaskManager;
-import com.sun.jini.thread.WakeupManager;
-
-import java.rmi.activation.ActivateFailedException;
-import java.rmi.RemoteException;
-import java.rmi.NoSuchObjectException;
-import java.rmi.MarshalException;
-import java.rmi.UnknownHostException;
-import java.rmi.ConnectIOException;
-import java.rmi.AccessException;
-import java.rmi.ConnectException;
-
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import net.jini.core.transaction.Transaction;
-import net.jini.core.transaction.TransactionException;
-import net.jini.core.transaction.server.ServerTransaction;
-import net.jini.core.transaction.server.TransactionConstants;
-import net.jini.core.transaction.server.TransactionParticipant;
-
-/**
- * An implementation of a <code>Job</code> which interacts with
- * a set of <code>TransactionParticipant</code>s to inform them
- * to roll forward changes associated with a given <code>Transaction</code>.
- *
- * @author Sun Microsystems, Inc.
- *
- * @see com.sun.jini.mahalo.Job
- * @see com.sun.jini.mahalo.ParticipantTask
- * @see net.jini.core.transaction.Transaction
- * @see net.jini.core.transaction.server.TransactionParticipant
- */
-public class CommitJob extends Job implements TransactionConstants {
-    ServerTransaction tr;
-    ClientLog log;
-    ParticipantHandle[] handles;
-    int maxtries = Integer.MAX_VALUE;
-    static final Logger logger = TxnManagerImpl.participantLogger;
-
-    /**
-     * Constructs an <code>CommitJob</code>
-     *
-     *
-     * @param tr The <code>Transaction</code> whose participants
-     *           will be instructed to roll-forward.
-     *
-     * @param pool The <code>TaskManager</code> which provides the
-     *             threads used for interacting with participants.
-     *
-     * @param log  The <code>ClientLog</code> used for recording
-     *             recovery data.
-     *
-     * @param handles The array of participants which will be contacted
-     *                and informed to roll-forward.
-     *
-     * @see com.sun.jini.thread.TaskManager
-     * @see com.sun.jini.mahalo.log.ClientLog
-     * @see net.jini.core.transaction.server.TransactionParticipant
-     */
-    public CommitJob(Transaction tr, TaskManager pool,
-		      WakeupManager wm, ClientLog log,
-		      ParticipantHandle[] handles) {
-	super(pool, wm);
-
-	if (log == null)
-	    throw new IllegalArgumentException("CommitJob: CommitJob: " +
-							"log is null");
-
-	this.log = log;
-
-        if (!(tr instanceof ServerTransaction))
-            throw new IllegalArgumentException("PrepareJob: PrepareJob: " +
-                                        "must be a ServerTransaction");
- 
-        this.tr =  (ServerTransaction) tr;
- 
-        if (handles == null)
-            throw new IllegalArgumentException("PrepareJob: PrepareJob: " +
-                                        "must have participants");
- 
-        if (handles.length == 0)
-            throw new IllegalArgumentException("PrepareJob: PrepareJob: " +
-                                        "must have participants");
- 
-        this.handles = handles;
-    }
-
-
-    /**
-     * The work to be performed by each <code>TaskManager.Task</code>
-     * is provided by the <code>Job</code> that creates it.
-     * The work performed by a task belonging to the CommitJob
-     * contacts a participant, instructs it to roll-forward and
-     * log appropriately.
-     *
-     * @param who The task performing the work
-     *
-     * @param param A parameter, of the task's choosing, useful
-     *              in performing work.
-     *
-     * @see com.sun.jini.mahalo.Job
-     * @see com.sun.jini.thread.TaskManager.Task
-     */
-    Object doWork(TaskManager.Task who, Object param) {
-        ParticipantHandle handle = (ParticipantHandle)param;
-        TransactionParticipant par = null;
-
-        //Check to see if participant has state associated
-	//with it on account of being recovered from a log
-
-        if (logger.isLoggable(Level.FINEST)) {
-            logger.log(Level.FINEST,
-                "CommitJob:doWork committing handle: {0}", handle);
-	}
-
-        int vote = handle.getPrepState();
- 
-        switch (vote) {
-	    case COMMITTED:
-            case NOTCHANGED:
-            case ABORTED:
-                return Integer.valueOf(vote);
-        }
-
-        //Instruct the TransactionParticipant to roll forward
-        //after unpacking it and checking against the
-        //max retry threshold.
-
-        if (par == null)
-            par = handle.getPreParedParticipant();
- 
-        //If you have exhausted the max retry threshold
-        //stop, so that no further attempts are made.
- 
-	try {
-            if (attempt(who) >= maxtries) {
-                return Integer.valueOf(COMMITTED);
-            }
-	} catch (JobException je) {
-	    return null;
-	}
- 
-        //At this point, if participant is null, there
-        //must be an error unpacking, so retry later
-        if (par == null)
-            return null;
- 
- 
-        //Here we actually need to instruct the participant to
-        //roll forward.  Note the RemoteException causes a
-        //retry. Here we only log info for the cases
-        //where a final outcome is available.
- 
-        Object response = null;
- 
-        try {
-            par.commit(tr.mgr, tr.id);
-            response = Integer.valueOf(COMMITTED);
-        } catch (TransactionException bte) {
-            //The participant doesn't have record of the
-            //transaction, so it must have already rolled
-            //forward.
-            response = Integer.valueOf(COMMITTED);
-	} catch (NoSuchObjectException nsoe) {
-	    //No definition for object in VM, so stop
-	    //and consider committed.
-	    response = Integer.valueOf(COMMITTED);
-	} catch (ConnectException ce) {
-	    //failure setting up connection, so give
-	    //participant more time by retrying
-	} catch (UnknownHostException uhe) {
-	    //could not resolve host for participant, so
-	    //stop and consider committed
-	    response = Integer.valueOf(COMMITTED);
-	} catch (ConnectIOException cioe) {
-	    //multiplexed connection or cached 
-	    //connection problem, give participant more time
-	} catch (MarshalException me) {
-	    //cannot send parameters, so stop and consider done
-	    response = Integer.valueOf(COMMITTED);
-	} catch (AccessException ae) {
-	    //Access error on registry or rmid consider done
-	    response = Integer.valueOf(COMMITTED);
-	} catch (ActivateFailedException afe) {
-	    //Activatable Ref Stub couldn't activate
-	    //participant, so stop and consider done
-	    response = Integer.valueOf(COMMITTED);
-        } catch (RemoteException re) {
-            //Something happened with the network, so
-            //return null to retry at a later time.
-        } catch (RuntimeException rte) {
-            //Something happened with the participant, so
-            //stop and consider done
-	    response = Integer.valueOf(COMMITTED);
-        }
- 
- 
-        if (response != null) {
-	    handle.setPrepState(COMMITTED);
-            try {
-                log.write( new ParticipantCommitRecord(handle));
-            } catch (com.sun.jini.mahalo.log.LogException le) {
-                //the full package name used to disambiguate
-                //the LogException
-            }
-
-	    return response;
-        }
- 
-        return null;
-    }
-
-
-    /**
-     * Creates the <code>TaskManager.Task</code>s necessary to
-     * inform participants to roll-back.
-     */
-    TaskManager.Task[] createTasks() {
-	TaskManager.Task[] tmp = new TaskManager.Task[handles.length];
-
-	for (int i = 0; i < handles.length; i++) {
-	    tmp[i] = 
-	        new ParticipantTask(getPool(), getMgr(), this, handles[i]);
-	}
-
-	return tmp;
-    }
-
-
-    /**
-     * Gathers partial results submitted by tasks and produces
-     * a single outcome.
-     *
-     * @see com.sun.jini.mahalo.Job
-     */
-    Object computeResult() throws JobException {
-	try {
-	    if (!isCompleted(0))
-	        throw new ResultNotReadyException("Cannot compute result " +
-					"since there are jobs pending");
-	} catch (JobNotStartedException jnse) {
-	    throw new ResultNotReadyException("Cannot compute result since" +
-					   " jobs were not created");
-	}
-
-	int tmp = 0;
-	int count = 0;
-
-	checkresults:
-	for (int i = 0; i < results.length; i++) {
-	    tmp = ((Integer)results[i]).intValue();
-
-	    if (tmp == COMMITTED)
-		count++;
-	}
-
-        if (logger.isLoggable(Level.FINEST)) {
-            logger.log(Level.FINEST,
-                "CommitJob:computeResult {0} participants COMMITTED", 
-		Integer.valueOf(count));
-	}
-
-	return Integer.valueOf(COMMITTED);
-    }
-}
+/*
+ * 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.mahalo;
+
+import com.sun.jini.mahalo.log.ClientLog;
+import com.sun.jini.thread.TaskManager;
+import com.sun.jini.thread.WakeupManager;
+
+import java.rmi.activation.ActivateFailedException;
+import java.rmi.RemoteException;
+import java.rmi.NoSuchObjectException;
+import java.rmi.MarshalException;
+import java.rmi.UnknownHostException;
+import java.rmi.ConnectIOException;
+import java.rmi.AccessException;
+import java.rmi.ConnectException;
+import java.util.Iterator;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import net.jini.core.transaction.Transaction;
+import net.jini.core.transaction.TransactionException;
+import net.jini.core.transaction.server.ServerTransaction;
+import net.jini.core.transaction.server.TransactionConstants;
+import net.jini.core.transaction.server.TransactionParticipant;
+
+/**
+ * An implementation of a <code>Job</code> which interacts with
+ * a set of <code>TransactionParticipant</code>s to inform them
+ * to roll forward changes associated with a given <code>Transaction</code>.
+ *
+ * @author Sun Microsystems, Inc.
+ *
+ * @see com.sun.jini.mahalo.Job
+ * @see com.sun.jini.mahalo.ParticipantTask
+ * @see net.jini.core.transaction.Transaction
+ * @see net.jini.core.transaction.server.TransactionParticipant
+ */
+class CommitJob extends Job implements TransactionConstants {
+    final ServerTransaction tr;
+    final ClientLog log;
+    final ParticipantHandle[] handles;
+    final int maxtries = Integer.MAX_VALUE;
+    static final Logger logger = TxnManagerImpl.participantLogger;
+
+    /**
+     * Constructs an <code>CommitJob</code>
+     *
+     *
+     * @param tr The <code>Transaction</code> whose participants
+     *           will be instructed to roll-forward.
+     *
+     * @param pool The <code>TaskManager</code> which provides the
+     *             threads used for interacting with participants.
+     *
+     * @param log  The <code>ClientLog</code> used for recording
+     *             recovery data.
+     *
+     * @param handles The array of participants which will be contacted
+     *                and informed to roll-forward.
+     *
+     * @see com.sun.jini.thread.TaskManager
+     * @see com.sun.jini.mahalo.log.ClientLog
+     * @see net.jini.core.transaction.server.TransactionParticipant
+     */
+    public CommitJob(Transaction tr, TaskManager pool,
+		      WakeupManager wm, ClientLog log,
+		      ParticipantHandle[] handles) {
+	super(pool, wm);
+
+	if (log == null)
+	    throw new IllegalArgumentException("CommitJob: CommitJob: " +
+							"log is null");
+
+	this.log = log;
+
+        if (!(tr instanceof ServerTransaction))
+            throw new IllegalArgumentException("PrepareJob: PrepareJob: " +
+                                        "must be a ServerTransaction");
+ 
+        this.tr =  (ServerTransaction) tr;
+ 
+        if (handles == null)
+            throw new IllegalArgumentException("PrepareJob: PrepareJob: " +
+                                        "must have participants");
+ 
+        if (handles.length == 0)
+            throw new IllegalArgumentException("PrepareJob: PrepareJob: " +
+                                        "must have participants");
+ 
+        this.handles = handles;
+    }
+
+
+    /**
+     * The work to be performed by each <code>TaskManager.Task</code>
+     * is provided by the <code>Job</code> that creates it.
+     * The work performed by a task belonging to the CommitJob
+     * contacts a participant, instructs it to roll-forward and
+     * log appropriately.
+     *
+     * @param who The task performing the work
+     *
+     * @param param A parameter, of the task's choosing, useful
+     *              in performing work.
+     *
+     * @see com.sun.jini.mahalo.Job
+     * @see com.sun.jini.thread.TaskManager.Task
+     */
+    Object doWork(TaskManager.Task who, Object param) {
+        ParticipantHandle handle = (ParticipantHandle)param;
+        TransactionParticipant par = null;
+
+        //Check to see if participant has state associated
+	//with it on account of being recovered from a log
+
+        if (logger.isLoggable(Level.FINEST)) {
+            logger.log(Level.FINEST,
+                "CommitJob:doWork committing handle: {0}", handle);
+	}
+
+        int vote = handle.getPrepState();
+ 
+        switch (vote) {
+	    case COMMITTED:
+            case NOTCHANGED:
+            case ABORTED:
+                return Integer.valueOf(vote);
+        }
+
+        //Instruct the TransactionParticipant to roll forward
+        //after unpacking it and checking against the
+        //max retry threshold.
+
+        if (par == null)
+            par = handle.getPreParedParticipant();
+ 
+        //If you have exhausted the max retry threshold
+        //stop, so that no further attempts are made.
+ 
+	try {
+            if (attempt(who) >= maxtries) {
+                return Integer.valueOf(COMMITTED);
+            }
+	} catch (JobException je) {
+	    return null;
+	}
+ 
+        //At this point, if participant is null, there
+        //must be an error unpacking, so retry later
+        if (par == null)
+            return null;
+ 
+ 
+        //Here we actually need to instruct the participant to
+        //roll forward.  Note the RemoteException causes a
+        //retry. Here we only log info for the cases
+        //where a final outcome is available.
+ 
+        Object response = null;
+ 
+        try {
+            par.commit(tr.mgr, tr.id);
+            response = Integer.valueOf(COMMITTED);
+        } catch (TransactionException bte) {
+            //The participant doesn't have record of the
+            //transaction, so it must have already rolled
+            //forward.
+            response = Integer.valueOf(COMMITTED);
+	} catch (NoSuchObjectException nsoe) {
+	    //No definition for object in VM, so stop
+	    //and consider committed.
+	    response = Integer.valueOf(COMMITTED);
+	} catch (ConnectException ce) {
+	    //failure setting up connection, so give
+	    //participant more time by retrying
+	} catch (UnknownHostException uhe) {
+	    //could not resolve host for participant, so
+	    //stop and consider committed
+	    response = Integer.valueOf(COMMITTED);
+	} catch (ConnectIOException cioe) {
+	    //multiplexed connection or cached 
+	    //connection problem, give participant more time
+	} catch (MarshalException me) {
+	    //cannot send parameters, so stop and consider done
+	    response = Integer.valueOf(COMMITTED);
+	} catch (AccessException ae) {
+	    //Access error on registry or rmid consider done
+	    response = Integer.valueOf(COMMITTED);
+	} catch (ActivateFailedException afe) {
+	    //Activatable Ref Stub couldn't activate
+	    //participant, so stop and consider done
+	    response = Integer.valueOf(COMMITTED);
+        } catch (RemoteException re) {
+            //Something happened with the network, so
+            //return null to retry at a later time.
+        } catch (RuntimeException rte) {
+            //Something happened with the participant, so
+            //stop and consider done
+	    response = Integer.valueOf(COMMITTED);
+        }
+ 
+ 
+        if (response != null) {
+	    handle.setPrepState(COMMITTED);
+            try {
+                log.write( new ParticipantCommitRecord(handle));
+            } catch (com.sun.jini.mahalo.log.LogException le) {
+                //the full package name used to disambiguate
+                //the LogException
+            }
+
+	    return response;
+        }
+ 
+        return null;
+    }
+
+
+    /**
+     * Creates the <code>TaskManager.Task</code>s necessary to
+     * inform participants to roll-back.
+     */
+    TaskManager.Task[] createTasks() {
+	TaskManager.Task[] tmp = new TaskManager.Task[handles.length];
+
+	for (int i = 0; i < handles.length; i++) {
+	    tmp[i] = 
+	        new ParticipantTask(getPool(), getMgr(), this, handles[i]);
+	}
+
+	return tmp;
+    }
+
+
+    /**
+     * Gathers partial results submitted by tasks and produces
+     * a single outcome.
+     *
+     * @see com.sun.jini.mahalo.Job
+     */
+    Object computeResult() throws JobException {
+	try {
+	    if (!isCompleted(0))
+	        throw new ResultNotReadyException("Cannot compute result " +
+					"since there are jobs pending");
+	} catch (JobNotStartedException jnse) {
+	    throw new ResultNotReadyException("Cannot compute result since" +
+					   " jobs were not created");
+	}
+
+	int tmp = 0;
+	int count = 0;
+
+        Iterator i = results.values().iterator();
+        while (i.hasNext()){
+            tmp = ((Integer)i.next()).intValue();
+            if (tmp == COMMITTED) count++;
+        }
+
+        if (logger.isLoggable(Level.FINEST)) {
+            logger.log(Level.FINEST,
+                "CommitJob:computeResult {0} participants COMMITTED", 
+		Integer.valueOf(count));
+	}
+
+	return Integer.valueOf(COMMITTED);
+    }
+}

Modified: river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/mahalo/CommitRecord.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/mahalo/CommitRecord.java?rev=1468119&r1=1468118&r2=1468119&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/mahalo/CommitRecord.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/mahalo/CommitRecord.java Mon Apr 15 15:26:44 2013
@@ -1,108 +1,108 @@
-/*
- * 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.mahalo;
-
-import com.sun.jini.mahalo.log.CannotRecoverException;
-import net.jini.core.transaction.server.TransactionParticipant;
-
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * A <code>CommitRecord</code> represents the logged state of
- * a <code>Transaction</code> which has moved to the COMMITTED
- * state.
- *
- * @author Sun Microsystems, Inc.
- *
- */
-class CommitRecord implements TxnLogRecord {
-    static final long serialVersionUID = 5706802011705258126L;
-
-    static final Logger logger = TxnManagerImpl.participantLogger;
-
-    /**
-     * @serial
-     */
-    ParticipantHandle[] parts; //Note: Use an array of ParticipantHandles;
-			       //      We want a list of things.  By using
-			       //      an array, we can use the type system
-			       //      to guarantee that each thing is a
-			       //      ParticipantHandle rather than checking
-			       //      explicitly.	
-
-    /**
-     * Constructs an <code>CommitRecord</code> which  represents a
-     * <code>Transaction</code> which has moved to the COMMITTED state.
-     *
-     * @param parts The array of participants joined in the transaction
-     *
-     * @see net.jini.core.transaction.Transaction
-     * @see net.jini.core.transaction.server.TransactionParticipant
-     * @see net.jini.core.transaction.server.TransactionConstants
-     */
-    CommitRecord(ParticipantHandle parts[]) {
-	//Note: the state is implied in the
-	//      class name
-
-	if (parts == null)
-	    throw new IllegalArgumentException("CommitRecord: must specify " +
-		    			        "a non-null parts array");
-
-	this.parts = parts;
-    }
-
-    
-    /**
-     * Retrieves the set of <code>TransactionParticipant</code>s associated 
-     * with the recovered <code>Transaction</code>.
-     *
-     */
-    ParticipantHandle[] getParts() {
-	return parts;
-    }
-
-
-    /**
-     * Recovers the state encapsulated the <code>CommitRecord</code> to
-     * the caller.
-     *
-     * @param tmt  The <code>TxnManagerTransaction</code> to which
-     *             state is recovered.
-     *
-     * @see com.sun.jini.mahalo.TxnManagerTransaction
-     */
-    public void recover(TxnManagerTransaction tmt)
-	throws CannotRecoverException
-    {
-	try {
-	    for (int i = 0; i< parts.length; i++) {
-	        tmt.add(parts[i]);
-	    }
-	    tmt.modifyTxnState(VOTING);
-	} catch (InternalManagerException ime) {
-	    throw new CannotRecoverException("CommitRecord: recover: " +
-							ime.getMessage());
-	}
-
-	if (logger.isLoggable(Level.FINEST)) {
-            logger.log(Level.FINEST, "CommitRecord:recover recovered");
-        }    
-    }
-
-}
+/*
+ * 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.mahalo;
+
+import com.sun.jini.mahalo.log.CannotRecoverException;
+import net.jini.core.transaction.server.TransactionParticipant;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A <code>CommitRecord</code> represents the logged state of
+ * a <code>Transaction</code> which has moved to the COMMITTED
+ * state.
+ *
+ * @author Sun Microsystems, Inc.
+ *
+ */
+class CommitRecord implements TxnLogRecord {
+    static final long serialVersionUID = 5706802011705258126L;
+
+    static final Logger logger = TxnManagerImpl.participantLogger;
+
+    /**
+     * @serial
+     */
+    final ParticipantHandle[] parts; //Note: Use an array of ParticipantHandles;
+			       //      We want a list of things.  By using
+			       //      an array, we can use the type system
+			       //      to guarantee that each thing is a
+			       //      ParticipantHandle rather than checking
+			       //      explicitly.	
+
+    /**
+     * Constructs an <code>CommitRecord</code> which  represents a
+     * <code>Transaction</code> which has moved to the COMMITTED state.
+     *
+     * @param parts The array of participants joined in the transaction
+     *
+     * @see net.jini.core.transaction.Transaction
+     * @see net.jini.core.transaction.server.TransactionParticipant
+     * @see net.jini.core.transaction.server.TransactionConstants
+     */
+    CommitRecord(ParticipantHandle parts[]) {
+	//Note: the state is implied in the
+	//      class name
+
+	if (parts == null)
+	    throw new IllegalArgumentException("CommitRecord: must specify " +
+		    			        "a non-null parts array");
+
+	this.parts = parts;
+    }
+
+    
+    /**
+     * Retrieves the set of <code>TransactionParticipant</code>s associated 
+     * with the recovered <code>Transaction</code>.
+     *
+     */
+    ParticipantHandle[] getParts() {
+	return parts;
+    }
+
+
+    /**
+     * Recovers the state encapsulated the <code>CommitRecord</code> to
+     * the caller.
+     *
+     * @param tmt  The <code>TxnManagerTransaction</code> to which
+     *             state is recovered.
+     *
+     * @see com.sun.jini.mahalo.TxnManagerTransaction
+     */
+    public void recover(TxnManagerTransaction tmt)
+	throws CannotRecoverException
+    {
+	try {
+	    for (int i = 0; i< parts.length; i++) {
+	        tmt.add(parts[i]);
+	    }
+	    tmt.modifyTxnState(VOTING);
+	} catch (InternalManagerException ime) {
+	    throw new CannotRecoverException("CommitRecord: recover: " +
+							ime.getMessage());
+	}
+
+	if (logger.isLoggable(Level.FINEST)) {
+            logger.log(Level.FINEST, "CommitRecord:recover recovered");
+        }    
+    }
+
+}



Mime
View raw message