Cleaning up code for runtime, installer, RMI, compiler for the Java side
[iot2.git] / iotjava / iotruntime / master / CommunicationHandler.java
index 15db69022eeaf98d0c04adcac6f2d1c8847ea8c0..6445c093e10cfae506f38385e703dd43335c930a 100644 (file)
@@ -11,14 +11,14 @@ import java.util.Set;
 /** Class CommunicationHandler is a class that maintains
  *  a data structure that preserves a collection of host name,
  *  port numbers, and objects that are running
- *  +-----------------+----+--------+------------------+--------------+----------------+
- *  | HOST-ADDRESS    | ...|IN-PORT | RMIREGISTRY-PORT | RMISTUB-PORT | ACTIVE OBJECTS |
- *  +-----------------+----+--------+------------------+--------------+----------------+
- *  | XXX.XXX.XXX.XXX |    | XXXXX  | XXXXX            | XXXXX        | XXXXXXXXXXXXXX |
- *  |                 |    | XXXXX  | XXXXX            | XXXXX        | XXXXXXXXXXXXXX |
- *  |                 |    | XXXXX  | XXXXX            | XXXXX        | XXXXXXXXXXXXXX |
- *  |                 | ...| ...    | ...              | ...          | ...            |
- *  +-----------------+----+--------+------------------+--------------+----------------+
+ *  +-----------------+----+--------+------------------+--------------+----+----------------+
+ *  | HOST-ADDRESS    | ...|IN-PORT | RMIREGISTRY-PORT | RMISTUB-PORT | ...| ACTIVE OBJECTS |
+ *  +-----------------+----+--------+------------------+--------------+----+----------------+
+ *  | XXX.XXX.XXX.XXX |    | XXXXX  | XXXXX            | XXXXX        |    | XXXXXXXXXXXXXX |
+ *  |                 |    | XXXXX  | XXXXX            | XXXXX        |    | XXXXXXXXXXXXXX |
+ *  |                 |    | XXXXX  | XXXXX            | XXXXX        |    | XXXXXXXXXXXXXX |
+ *  |                 | ...| ...    | ...              | ...          | ...| ...            |
+ *  +-----------------+----+--------+------------------+--------------+----+----------------+
  *  In this case we use ACTIVE OBJECTS names as the key
  *  So ACTIVE OBJECTS maps to numbers and these numbers map to each other
  *  entry in hashmaps (HostAddress can be repetitive)
@@ -26,19 +26,6 @@ import java.util.Set;
  *                      ProximitySensorPS1 - 1
  *                      TempSensorTS1      - 2
  *                      ...
- *       IN-PORT / RMIREGISTRY-PORT / RMISTUB-PORT / HOST-ADDRESS: 0 - XXXXX
- *                                                                 1 - XXXXX
- *                                                                 2 - XXXXX
- *  +-------------+
- *  | DEVICE-PORT |
- *  +-------------+
- *  | XXXXX       |
- *  | XXXXX       |
- *  | XXXXX       |
- *  | ...         |
- *  +-------------+
- *  We add a Set structure to handle all the other ports that are used by devices
- *  when communicating with their respective drivers
  *
  * @author      Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
  * @version     1.0
@@ -79,7 +66,7 @@ public final class CommunicationHandler {
        private final int INT_MIN_PORT = 10000;
 
        /**
-        * Empty constructor
+        * Constructor
         */
        public CommunicationHandler(boolean _bVerbose) {
 
@@ -102,6 +89,33 @@ public final class CommunicationHandler {
                bVerbose = _bVerbose;
                RuntimeOutput.print("CommunicationHandler: Creating a new CommunicationHandler object!", bVerbose);
        }
+       
+       /**
+        * Method clearCommunicationHandler()
+        * <p>
+        * Clear the data structure
+        *
+        * @return  void
+        */
+       public void clearCommunicationHandler() {
+
+               listActiveControllerObj.clear();
+               listFieldObjectID.clear();
+               listObjCrtInfo.clear();
+               listArrFieldValues.clear();
+               listArrFieldClasses.clear();
+               hmActiveObj.clear();
+               hmHostAdd.clear();
+               hmHostList.clear();
+               hmComPort.clear();
+               hmRMIRegPort.clear();
+               hmRMIStubPort.clear();
+               hsDevicePort.clear();
+               hmAdditionalPort.clear();
+               iNumOfObjects = 0;
+               iNumOfHosts = 0;
+               RuntimeOutput.print("CommunicationHandler: Clearing CommunicationHandler object's data structure!", bVerbose);
+    }
 
        /**
         * Method addPortConnection()
@@ -136,21 +150,21 @@ public final class CommunicationHandler {
                int iComPort = 0;
                do {
                        iComPort = random.nextInt(INT_MAX_PORT - INT_MIN_PORT + 1) + INT_MIN_PORT;
-                       // Check port existence in HashMap
+               // Check port existence in HashMap
                } while (portIsAvailable(iComPort) == false);
                hmComPort.put(iNumOfObjects, iComPort);
 
                int iRMIRegPort = 0;
                do {
                        iRMIRegPort = random.nextInt(INT_MAX_PORT - INT_MIN_PORT + 1) + INT_MIN_PORT;
-                       // Check port existence in HashMap
+               // Check port existence in HashMap
                } while (portIsAvailable(iRMIRegPort) == false);
                hmRMIRegPort.put(iNumOfObjects, iRMIRegPort);
 
                int iRMIStubPort = 0;
                do {
                        iRMIStubPort = random.nextInt(INT_MAX_PORT - INT_MIN_PORT + 1) + INT_MIN_PORT;
-                       // Check port existence in HashMap
+               // Check port existence in HashMap
                } while (portIsAvailable(iRMIStubPort) == false);
                hmRMIStubPort.put(iNumOfObjects, iRMIStubPort);
 
@@ -194,7 +208,6 @@ public final class CommunicationHandler {
        public void addDevicePort(int iDevPort) {
 
                hsDevicePort.add(iDevPort);
-
        }
 
        /**
@@ -212,7 +225,7 @@ public final class CommunicationHandler {
                int iAdditionalPort = 0;
                do {
                        iAdditionalPort = random.nextInt(INT_MAX_PORT - INT_MIN_PORT + 1) + INT_MIN_PORT;
-                       // Check port existence in HashMap
+               // Check port existence in HashMap
                } while (portIsAvailable(iAdditionalPort) == false);
                hmAdditionalPort.put(iNumOfObjects, iAdditionalPort);