X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=iotjava%2Fiotruntime%2Fmaster%2FCommunicationHandler.java;h=fd4340828242297ea6e8a5768a92347139488a1e;hb=7cab636b00bf5afcc441c9e4bdd4d6f4f0e2cf95;hp=15db69022eeaf98d0c04adcac6f2d1c8847ea8c0;hpb=b7795a76d57478a23ee40dd8717b005e18891ca1;p=iot2.git diff --git a/iotjava/iotruntime/master/CommunicationHandler.java b/iotjava/iotruntime/master/CommunicationHandler.java index 15db690..fd43408 100644 --- a/iotjava/iotruntime/master/CommunicationHandler.java +++ b/iotjava/iotruntime/master/CommunicationHandler.java @@ -67,6 +67,7 @@ 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; @@ -96,12 +97,40 @@ public final class CommunicationHandler { hmRMIRegPort = new HashMap(); hmRMIStubPort = new HashMap(); hsDevicePort = new HashSet(); + hsAllPorts = new HashSet(); hmAdditionalPort = new HashMap(); iNumOfObjects = 0; iNumOfHosts = 0; bVerbose = _bVerbose; RuntimeOutput.print("CommunicationHandler: Creating a new CommunicationHandler object!", bVerbose); } + + /** + * Method clearCommunicationHandler() + *

+ * 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() @@ -139,6 +168,8 @@ public final class CommunicationHandler { // 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 { @@ -146,6 +177,7 @@ public final class CommunicationHandler { // Check port existence in HashMap } while (portIsAvailable(iRMIRegPort) == false); hmRMIRegPort.put(iNumOfObjects, iRMIRegPort); + hsAllPorts.add(iRMIRegPort); int iRMIStubPort = 0; do { @@ -153,6 +185,7 @@ public final class CommunicationHandler { // Check port existence in HashMap } while (portIsAvailable(iRMIStubPort) == false); hmRMIStubPort.put(iNumOfObjects, iRMIStubPort); + hsAllPorts.add(iRMIStubPort); iNumOfObjects++; } @@ -194,7 +227,8 @@ public final class CommunicationHandler { public void addDevicePort(int iDevPort) { hsDevicePort.add(iDevPort); - + // Track this port number + hsAllPorts.add(iDevPort); } /** @@ -215,6 +249,8 @@ public final class CommunicationHandler { // Check port existence in HashMap } while (portIsAvailable(iAdditionalPort) == false); hmAdditionalPort.put(iNumOfObjects, iAdditionalPort); + // Track this port number + hsAllPorts.add(iAdditionalPort); iNumOfObjects++; @@ -233,7 +269,7 @@ public final class CommunicationHandler { */ public boolean portIsAvailable(int iPortNumber) { - if (hmComPort.containsValue(iPortNumber) == true) { + /*if (hmComPort.containsValue(iPortNumber) == true) { return false; } else if (hmRMIRegPort.containsValue(iPortNumber) == true) { return false; @@ -245,6 +281,11 @@ public final class CommunicationHandler { return false; } else { return true; + }*/ + if (hsAllPorts.contains(iPortNumber)) { + return false; + } else { + return true; } }