| 1 | package tmcsim.client; |
|---|
| 2 | |
|---|
| 3 | import java.rmi.Naming; |
|---|
| 4 | import java.rmi.RemoteException; |
|---|
| 5 | import java.rmi.server.UnicastRemoteObject; |
|---|
| 6 | import javax.swing.table.DefaultTableModel; |
|---|
| 7 | import tmcsim.client.cadclientgui.enums.CADDataEnums; |
|---|
| 8 | import tmcsim.common.SimulationException; |
|---|
| 9 | import tmcsim.interfaces.CADClientInterface; |
|---|
| 10 | import tmcsim.interfaces.CoordinatorInterface; |
|---|
| 11 | |
|---|
| 12 | /** |
|---|
| 13 | * Test Driver for getCadDataTable(CADDataEnums.TABLE.UNIT_STATUS); |
|---|
| 14 | * Usage: Start the CADServer, Sim Mgr, and CADClient. Be Unit Status window is visible. |
|---|
| 15 | * Start this program and observe CADClient output window. |
|---|
| 16 | * @author jdalbey |
|---|
| 17 | */ |
|---|
| 18 | public class CadDataTableTest extends UnicastRemoteObject implements |
|---|
| 19 | CADClientInterface { |
|---|
| 20 | |
|---|
| 21 | private CoordinatorInterface theCoorInt; |
|---|
| 22 | /** reference to itself to be used for disconnecting from CADSimulator */ |
|---|
| 23 | private CADClientInterface myself = this; |
|---|
| 24 | private int kIterationLimit = 500; |
|---|
| 25 | public static void main(String[] args) throws SimulationException, RemoteException |
|---|
| 26 | { |
|---|
| 27 | String host = "127.0.0.1"; |
|---|
| 28 | if (args.length > 0) |
|---|
| 29 | { |
|---|
| 30 | host = args[0]; //192.168.251.116 for production machine |
|---|
| 31 | } |
|---|
| 32 | CadDataTableTest app = new CadDataTableTest(); |
|---|
| 33 | app.start(host); |
|---|
| 34 | System.exit(0); |
|---|
| 35 | } |
|---|
| 36 | public CadDataTableTest() throws RemoteException { } |
|---|
| 37 | |
|---|
| 38 | public void start(String hostname) throws SimulationException, RemoteException { |
|---|
| 39 | String coorIntURL = ""; |
|---|
| 40 | |
|---|
| 41 | try { |
|---|
| 42 | coorIntURL = "rmi://" + hostname + ":" + "4446" |
|---|
| 43 | + "/coordinator"; |
|---|
| 44 | theCoorInt = (CoordinatorInterface) Naming.lookup(coorIntURL); |
|---|
| 45 | theCoorInt.registerForCallback(this); |
|---|
| 46 | } catch (Exception e) { |
|---|
| 47 | throw new SimulationException(SimulationException.CAD_SIM_CONNECT,"127.0.0.1", |
|---|
| 48 | e); |
|---|
| 49 | } |
|---|
| 50 | try |
|---|
| 51 | { |
|---|
| 52 | // Call the Coordinator |
|---|
| 53 | DefaultTableModel mdl = theCoorInt.getCadDataTable(CADDataEnums.TABLE.UNIT_STATUS); |
|---|
| 54 | // Loop many times to simulate many clients accessing the CAD Data at once |
|---|
| 55 | System.out.println("Starting CAD Data Table test for "+kIterationLimit+" iterations."); |
|---|
| 56 | for (int count = 0; count < kIterationLimit; count++) |
|---|
| 57 | { |
|---|
| 58 | mdl = theCoorInt.getCadDataTable(CADDataEnums.TABLE.UNIT_STATUS); |
|---|
| 59 | try |
|---|
| 60 | { |
|---|
| 61 | Thread.sleep(100); // pause briefly between accesses |
|---|
| 62 | } |
|---|
| 63 | catch(InterruptedException e) |
|---|
| 64 | { ; } |
|---|
| 65 | } |
|---|
| 66 | } catch (RemoteException ex) |
|---|
| 67 | { |
|---|
| 68 | System.out.println("RemoteException in CADClientTest.java"); |
|---|
| 69 | System.out.println(ex.getMessage()); |
|---|
| 70 | } |
|---|
| 71 | System.out.println("Test Completed."); |
|---|
| 72 | ensureProperShutdown(); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | @Override |
|---|
| 76 | public void refresh() throws RemoteException { |
|---|
| 77 | throw new UnsupportedOperationException("Not supported yet."); |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | public void ensureProperShutdown() |
|---|
| 81 | { |
|---|
| 82 | Runtime.getRuntime().addShutdownHook(new Thread() |
|---|
| 83 | { |
|---|
| 84 | public void run() |
|---|
| 85 | { |
|---|
| 86 | try |
|---|
| 87 | { |
|---|
| 88 | theCoorInt.unregisterForCallback(myself); |
|---|
| 89 | } catch (RemoteException e) |
|---|
| 90 | { |
|---|
| 91 | e.printStackTrace(); |
|---|
| 92 | } |
|---|
| 93 | } |
|---|
| 94 | }); |
|---|
| 95 | } |
|---|
| 96 | } |
|---|