X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=iotjava%2Fiotruntime%2Fmaster%2FCommunicationHandler.java;h=6445c093e10cfae506f38385e703dd43335c930a;hb=7e8c0cabb7057ad561adbb8b6cc2a0fd5c41bbf4;hp=5d257722772b03d9480bb67df92e36967755b6b0;hpb=f7ff6050110f71874879912c9b1f6a01745d2d76;p=iot2.git diff --git a/iotjava/iotruntime/master/CommunicationHandler.java b/iotjava/iotruntime/master/CommunicationHandler.java index 5d25772..6445c09 100644 --- a/iotjava/iotruntime/master/CommunicationHandler.java +++ b/iotjava/iotruntime/master/CommunicationHandler.java @@ -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 * @version 1.0 @@ -67,19 +54,11 @@ public final class CommunicationHandler { private Map hmRMIRegPort; private Map hmRMIStubPort; private Set hsDevicePort; - private Set hsAllPorts; private Map hmAdditionalPort; private int iNumOfObjects; private int iNumOfHosts; private boolean bVerbose; - // TODO: THIS IS HACKING FOR IOTSEC - // Replace random - private int comPortCount = 10000; - private int rmiRegCount = 20000; - private int rmiStubCount = 30000; - private int additionalCount = 40000; - /** * CommunicationHandler class constants */ @@ -87,7 +66,7 @@ public final class CommunicationHandler { private final int INT_MIN_PORT = 10000; /** - * Empty constructor + * Constructor */ public CommunicationHandler(boolean _bVerbose) { @@ -104,7 +83,6 @@ public final class CommunicationHandler { hmRMIRegPort = new HashMap(); hmRMIStubPort = new HashMap(); hsDevicePort = new HashSet(); - hsAllPorts = new HashSet(); hmAdditionalPort = new HashMap(); iNumOfObjects = 0; iNumOfHosts = 0; @@ -172,33 +150,23 @@ public final class CommunicationHandler { int iComPort = 0; do { iComPort = random.nextInt(INT_MAX_PORT - INT_MIN_PORT + 1) + INT_MIN_PORT; - //System.out.println("DEBUG: Assigning comPort: " + comPortCount); - //iComPort = comPortCount++; - // Check port existence in HashMap + // Check port existence in HashMap } while (portIsAvailable(iComPort) == false); hmComPort.put(iNumOfObjects, iComPort); - // hsAllPorts tracks all the existing and used port numbers - hsAllPorts.add(iComPort); int iRMIRegPort = 0; do { iRMIRegPort = random.nextInt(INT_MAX_PORT - INT_MIN_PORT + 1) + INT_MIN_PORT; - //System.out.println("DEBUG: Assigning regPort: " + rmiRegCount); - //iRMIRegPort = rmiRegCount++; - // Check port existence in HashMap + // Check port existence in HashMap } while (portIsAvailable(iRMIRegPort) == false); hmRMIRegPort.put(iNumOfObjects, iRMIRegPort); - hsAllPorts.add(iRMIRegPort); int iRMIStubPort = 0; do { iRMIStubPort = random.nextInt(INT_MAX_PORT - INT_MIN_PORT + 1) + INT_MIN_PORT; - //System.out.println("DEBUG: Assigning stubPort: " + rmiStubCount); - //iRMIStubPort = rmiStubCount++; - // Check port existence in HashMap + // Check port existence in HashMap } while (portIsAvailable(iRMIStubPort) == false); hmRMIStubPort.put(iNumOfObjects, iRMIStubPort); - hsAllPorts.add(iRMIStubPort); iNumOfObjects++; } @@ -240,8 +208,6 @@ public final class CommunicationHandler { public void addDevicePort(int iDevPort) { hsDevicePort.add(iDevPort); - // Track this port number - hsAllPorts.add(iDevPort); } /** @@ -259,13 +225,9 @@ public final class CommunicationHandler { int iAdditionalPort = 0; do { iAdditionalPort = random.nextInt(INT_MAX_PORT - INT_MIN_PORT + 1) + INT_MIN_PORT; - //System.out.println("DEBUG: Assigning additionalPort: " + additionalCount); - //iAdditionalPort = additionalCount++; - // Check port existence in HashMap + // Check port existence in HashMap } while (portIsAvailable(iAdditionalPort) == false); hmAdditionalPort.put(iNumOfObjects, iAdditionalPort); - // Track this port number - hsAllPorts.add(iAdditionalPort); iNumOfObjects++; @@ -297,11 +259,6 @@ public final class CommunicationHandler { } else { return true; } - //if (hsAllPorts.contains(iPortNumber)) { - // return false; - //} else { - // return true; - //} } /**