Index: /trunk/src/tmcsim/client/cadclientgui/data/CADDataSpike.java
===================================================================
--- /trunk/src/tmcsim/client/cadclientgui/data/CADDataSpike.java	(revision 476)
+++ /trunk/src/tmcsim/client/cadclientgui/data/CADDataSpike.java	(revision 476)
@@ -0,0 +1,37 @@
+
+import java.util.Vector;
+import javax.swing.table.DefaultTableModel;
+import tmcsim.client.cadclientgui.data.Unit;
+/** Spike to try to fix the concurrency error that shows up intermittently
+ *  as noted in ticket #87.
+ * @author jdalbey
+ */
+class CADDataSpike
+{
+    DefaultTableModel unitStatusTableModel;
+    Vector<String> unitStatusHeaders;
+    Vector<Unit> units;
+    /**
+     * Accessor to the Unit Status table model 
+     *
+     * @return DefaultTableModel for UnitStatus
+     */
+    public DefaultTableModel tableForUnitStatus()
+    {
+        Vector<Object> toUnitTableVector = new Vector<Object>();
+
+        // build a new unit table 
+        for (Unit unit: units)
+        {
+            toUnitTableVector.add(unit.toVector());
+        }
+        // Exception occurred here: http://pastebin.com/fvifM5i8
+        // Probably a distributed object concurrency problem.
+        // Assign the unit status table from the newly created vector
+        unitStatusTableModel
+                .setDataVector(toUnitTableVector, unitStatusHeaders);
+        // return a reference to the updated table
+        return unitStatusTableModel;
+    }
+
+}
Index: /trunk/src/tmcsim/client/CadDataTableTest.java
===================================================================
--- /trunk/src/tmcsim/client/CadDataTableTest.java	(revision 476)
+++ /trunk/src/tmcsim/client/CadDataTableTest.java	(revision 476)
@@ -0,0 +1,96 @@
+package tmcsim.client;
+
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
+import javax.swing.table.DefaultTableModel;
+import tmcsim.client.cadclientgui.enums.CADDataEnums;
+import tmcsim.common.SimulationException;
+import tmcsim.interfaces.CADClientInterface;
+import tmcsim.interfaces.CoordinatorInterface;
+
+/**
+ * Test Driver for getCadDataTable(CADDataEnums.TABLE.UNIT_STATUS);
+ * Usage: Start the CADServer, Sim Mgr, and CADClient. Be Unit Status window is visible.
+ *        Start this program and observe CADClient output window.
+ * @author jdalbey
+ */
+public class CadDataTableTest extends UnicastRemoteObject implements
+        CADClientInterface {
+
+    private CoordinatorInterface theCoorInt;
+    /** reference to itself to be used for disconnecting from CADSimulator   */
+    private CADClientInterface myself = this;
+    private int kIterationLimit = 500;
+    public static void main(String[] args) throws SimulationException, RemoteException
+    {
+        String host = "127.0.0.1";
+        if (args.length > 0)
+        {
+            host = args[0]; //192.168.251.116 for production machine
+        }
+        CadDataTableTest app = new CadDataTableTest();
+        app.start(host);
+        System.exit(0);
+    }
+    public CadDataTableTest() throws RemoteException { }
+    
+    public void start(String hostname) throws SimulationException, RemoteException {
+        String coorIntURL = "";
+
+        try {
+            coorIntURL = "rmi://" + hostname + ":" + "4446"
+                    + "/coordinator";
+            theCoorInt = (CoordinatorInterface) Naming.lookup(coorIntURL);
+            theCoorInt.registerForCallback(this);
+        } catch (Exception e) {
+            throw new SimulationException(SimulationException.CAD_SIM_CONNECT,"127.0.0.1",
+                    e);
+        }
+        try
+        {
+            // Call the Coordinator
+            DefaultTableModel mdl = theCoorInt.getCadDataTable(CADDataEnums.TABLE.UNIT_STATUS);
+            // Loop many times to simulate many clients accessing the CAD Data at once
+            System.out.println("Starting CAD Data Table test for "+kIterationLimit+" iterations.");
+            for (int count = 0; count < kIterationLimit; count++)
+            {
+                mdl = theCoorInt.getCadDataTable(CADDataEnums.TABLE.UNIT_STATUS);
+                try
+                {
+                    Thread.sleep(100); // pause briefly between accesses
+                }
+                catch(InterruptedException e)
+                { ; } 
+            }
+        } catch (RemoteException ex)
+        {
+            System.out.println("RemoteException in CADClientTest.java");
+            System.out.println(ex.getMessage());
+        }
+        System.out.println("Test Completed.");
+        ensureProperShutdown();        
+    }
+
+    @Override
+    public void refresh() throws RemoteException {
+        throw new UnsupportedOperationException("Not supported yet."); 
+    }
+
+    public void ensureProperShutdown()
+    {
+        Runtime.getRuntime().addShutdownHook(new Thread()
+        {
+            public void run()
+            {
+                try
+                {
+                    theCoorInt.unregisterForCallback(myself);
+                } catch (RemoteException e)
+                {
+                    e.printStackTrace();
+                }
+            }
+        });
+    }   
+}
Index: /trunk/test/tmcsim/client/cadclientgui/data/CADDataTest.java
===================================================================
--- /trunk/test/tmcsim/client/cadclientgui/data/CADDataTest.java	(revision 476)
+++ /trunk/test/tmcsim/client/cadclientgui/data/CADDataTest.java	(revision 476)
@@ -0,0 +1,80 @@
+
+package tmcsim.client.cadclientgui.data;
+
+import java.util.Vector;
+import javax.swing.table.DefaultTableModel;
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author jdalbey
+ */
+public class CADDataTest extends TestCase {
+    private Vector<Unit> units;
+    private Unit alpha;
+    public CADDataTest(String testName) {
+        super(testName);
+    }
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        units = new Vector<Unit>();
+        alpha = new Unit("1");
+        units.add(alpha);
+    }
+    
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    /**
+     * Test of clearData method, of class CADData.
+     */
+    public void testClearData() {
+        System.out.println("clearData");
+        CADData instance = new CADData();
+        instance.setUnitsFromXML(units);
+        assertEquals(alpha,instance.getUnit("1"));
+        instance.clearData();
+        assertFalse(instance.checkForValidId(1));
+    }
+
+    /**
+     * Test of setUnitsFromXML method, of class CADData.
+     */
+    public void testSetUnitsFromXML() {
+        System.out.println("setUnitsFromXML");
+        CADData instance = new CADData();
+        instance.setUnitsFromXML(units);
+        assertEquals(alpha,instance.getUnit("1"));
+    }
+
+
+    /**
+     * Test of tableForUnitStatus method, of class CADData.
+     */
+    public void testTableForUnitStatus() {
+        System.out.println("tableForUnitStatus");
+        CADData instance = new CADData();
+        instance.setUnitsFromXML(units);
+        DefaultTableModel result = instance.tableForUnitStatus();
+        assertEquals(1, result.getRowCount());
+    }
+
+    /**
+     * Test of unitAvailable method, of class CADData.
+     */
+    public void testUnitAvailable() {
+        System.out.println("unitAvailable");
+        String unitNum = "1";
+        CADData instance = new CADData();
+        instance.setUnitsFromXML(units);
+        instance.addIncident(new Incident(1,"Desc", 10L));
+        instance.unitAssignedToIncident(unitNum, 1, true);
+        instance.unitAvailable(unitNum);
+        assertEquals("10-98",instance.getUnit("1").getStatus());
+    }
+    
+}
Index: /trunk/test/tmcsim/client/cadclientgui/data/CADDataConcurrencyTest.java
===================================================================
--- /trunk/test/tmcsim/client/cadclientgui/data/CADDataConcurrencyTest.java	(revision 476)
+++ /trunk/test/tmcsim/client/cadclientgui/data/CADDataConcurrencyTest.java	(revision 476)
@@ -0,0 +1,84 @@
+
+package tmcsim.client.cadclientgui.data;
+
+import java.util.ArrayList;
+import java.util.Vector;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.swing.table.DefaultTableModel;
+import junit.framework.TestCase;
+import static junit.framework.TestCase.assertTrue;
+
+/**
+ * Test of CADData tableForUnitStatus()
+ * @author jdalbey
+ */
+public class CADDataConcurrencyTest extends TestCase {
+    private Vector<Unit> units;
+    private Unit alpha;
+    public CADDataConcurrencyTest(String testName) {
+        super(testName);
+    }
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        units = new Vector<Unit>();
+        alpha = new Unit("14-1");
+        units.add(alpha);
+        units.add(new Unit("14-2"));
+        units.add(new Unit("14-3"));
+        units.add(new Unit("14-4"));
+        units.add(new Unit("14-5"));
+    }
+    
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        System.out.println("Tearing down");
+        try
+        {
+            Thread.sleep(100);
+        }
+        catch(InterruptedException e)
+        { ; }        
+    }
+
+ 
+    public void testThreads()
+    {
+        System.out.println("Testing tableForUnitStatus()");
+        CADData caddata = new CADData();
+        caddata.setUnitsFromXML(units); // add 5 units
+        caddata.addIncident(new Incident(101,"Desc", 10L));
+        String unitNum = "14-1";
+        caddata.unitAssignedToIncident(unitNum, 101, true);
+        caddata.unitAvailable(unitNum);
+        Threadserve ts1=new Threadserve(caddata, "A");
+        Threadserve ts2=new Threadserve(caddata, "B");
+        Threadserve ts3=new Threadserve(caddata, "C");
+        DefaultTableModel m = caddata.tableForUnitStatus();
+        assertEquals("main Incorrect Row Count:",5,m.getRowCount());
+    }
+
+    class Threadserve implements Runnable
+    {
+        private CADData caddata;
+        private String id;
+        private Thread th;
+        Threadserve(CADData caddata, String id)
+        {
+            this.caddata = caddata;
+            this.id = id;
+            th=new Thread(this);
+            th.start();
+        }
+        public void run()
+        {       
+          //System.out.println("Start "+ id);
+          DefaultTableModel m = caddata.tableForUnitStatus();
+          int loopLimit = m.getRowCount();
+          assertEquals(id + " Incorrect Row Count:"+loopLimit,5,loopLimit);
+        }
+    }    
+}
Index: /trunk/test/tmcsim/client/cadclientgui/data/ThreadDemo.java
===================================================================
--- /trunk/test/tmcsim/client/cadclientgui/data/ThreadDemo.java	(revision 476)
+++ /trunk/test/tmcsim/client/cadclientgui/data/ThreadDemo.java	(revision 476)
@@ -0,0 +1,76 @@
+
+package tmcsim.client.cadclientgui.data;
+
+import java.util.ArrayList;
+import java.util.Vector;
+import javax.swing.table.DefaultTableModel;
+
+
+/**
+ * A simple demo of how to use threads and "synchronized"
+ *
+ * @author jdalbey
+ */
+public class ThreadDemo
+{
+    static ArrayList<Integer> numbers;
+
+    public static void main(String args[])
+    {
+        System.out.println("Testing threads");
+        PrintFunctor pf=new PrintFunctor();
+        Threadserve ts1=new Threadserve(pf,12,"A");
+        Threadserve ts2=new Threadserve(pf,8,"B");
+        Threadserve ts3=new Threadserve(pf,6,"C");
+    }
+
+static class Threadserve implements Runnable
+{
+        int max;
+        String id;
+        PrintFunctor pf;
+        Thread th;
+        Threadserve(PrintFunctor printer,int x, String id)
+        {
+            this.max = x;
+            this.id = id;
+            pf = printer;
+            th=new Thread(this);
+            th.start();
+        }
+        public void run()
+        {       
+            pf.countdown(max,id);
+        }
+}    
+static class PrintFunctor
+{
+    public PrintFunctor()
+    {
+    }
+    synchronized 
+    void countdown(int max, String id)
+    {
+        numbers = new ArrayList<Integer>();
+        for (int num=0; num <100; num++)
+        {
+            numbers.add(num);
+        }
+        System.out.println("Start" + id);
+        for(int idx=max; idx>0; idx--)
+        {
+            try
+            {
+                // when halfway, pause
+                if(idx==max/2) Thread.sleep(100);
+            }
+            catch(InterruptedException e)
+            { ; }
+            System.out.println(id + ": " + idx + "," + numbers.get(idx));
+        }
+        System.out.println();
+        numbers.clear();
+        System.out.println("Done countdown." + id);
+    }
+}
+}
