Applying changes for 3rd benchmark (wildcard addresses) in IoTMaster
authorrtrimana <rtrimana@uci.edu>
Wed, 4 Jan 2017 19:32:40 +0000 (11:32 -0800)
committerrtrimana <rtrimana@uci.edu>
Wed, 4 Jan 2017 19:32:40 +0000 (11:32 -0800)
iotjava/iotruntime/master/CommunicationHandler.java
iotjava/iotruntime/master/IoTMaster.java

index 6f9c67a..def3e77 100644 (file)
@@ -69,6 +69,7 @@ public final class CommunicationHandler {
        private Set<Integer> hsDevicePort;
        private Set<Integer> hsCallbackPort;
        private Map<Integer, Integer[]> hmCallbackPort;
+       private Map<Integer, Integer> hmAdditionalPort;
        private int iNumOfObjects;
        private int iNumOfHosts;
        private boolean bVerbose;
@@ -99,6 +100,7 @@ public final class CommunicationHandler {
                hsDevicePort = new HashSet<Integer>();
                hsCallbackPort = new HashSet<Integer>();
                hmCallbackPort = new HashMap<Integer, Integer[]>();
+               hmAdditionalPort = new HashMap<Integer, Integer>();
                iNumOfObjects = 0;
                iNumOfHosts = 0;
                bVerbose = _bVerbose;
@@ -254,6 +256,30 @@ public final class CommunicationHandler {
 
        }
 
+       /**
+        * Method addAdditionalPort()
+        * <p>
+        * Add a new port for new connections for any objects in the program.
+        * This newly generated port number will be recorded.
+        *
+        * @return  int         One new port
+        */
+       public int addAdditionalPort(String sAObject) {
+
+               hmActiveObj.put(sAObject, iNumOfObjects);
+
+               int iAdditionalPort = 0;
+               do {
+                       iAdditionalPort = random.nextInt(INT_MAX_PORT - INT_MIN_PORT + 1) + INT_MIN_PORT;
+                       // Check port existence in HashMap
+               } while (portIsAvailable(iAdditionalPort) == false);
+               hmAdditionalPort.put(iNumOfObjects, iAdditionalPort);
+
+               iNumOfObjects++;
+
+               return iAdditionalPort;
+       }
+
        /**
         * Method portIsAvailable()
         * <p>
@@ -272,6 +298,8 @@ public final class CommunicationHandler {
                        return false;
                } else if (hmRMIStubPort.containsValue(iPortNumber) == true) {
                        return false;
+               } else if (hmAdditionalPort.containsValue(iPortNumber) == true) {
+                       return false;
                } else if (hsDevicePort.contains(iPortNumber) == true) {
                        return false;
                } else if (hsCallbackPort.contains(iPortNumber) == true) {
@@ -367,6 +395,19 @@ public final class CommunicationHandler {
                return hmComPort.get(hmActiveObj.get(sAObject));
        }
 
+       /**
+        * Method getAdditionalPort()
+        * <p>
+        * User finds a port number using Object name
+        *
+        * @param   sAObject  String active object name
+        * @return  Integer
+        */
+       public Integer getAdditionalPort(String sAObject) {
+
+               return hmAdditionalPort.get(hmActiveObj.get(sAObject));
+       }
+
        /**
         * Method getRMIRegPort()
         * <p>
index 34f181a..e35d775 100644 (file)
@@ -368,9 +368,14 @@ public class IoTMaster {
                                commHan.addPortConnection(strIoTSlaveObjectHostAdd, strDeviceAddress);
                        }
                        // Send address one by one
-                       Message msgGetIoTSetObj = new MessageGetDeviceObject(IoTCommCode.GET_DEVICE_IOTSET_OBJECT,
-                               strDeviceAddress, commHan.getComPort(strDeviceAddress), iDestDeviceDriverPort,
-                               bSrcPortWildCard, bDstPortWildCard);
+                       Message msgGetIoTSetObj = null;
+                       if (bDstPortWildCard) {
+                               String strUniqueDev = strDeviceAddress + ":" + iRow;
+                               msgGetIoTSetObj = new MessageGetDeviceObject(IoTCommCode.GET_DEVICE_IOTSET_OBJECT,
+                                       strDeviceAddress, commHan.getAdditionalPort(strUniqueDev), iDestDeviceDriverPort, bSrcPortWildCard, bDstPortWildCard);
+                       } else
+                               msgGetIoTSetObj = new MessageGetDeviceObject(IoTCommCode.GET_DEVICE_IOTSET_OBJECT,
+                                       strDeviceAddress, commHan.getComPort(strDeviceAddress), iDestDeviceDriverPort, bSrcPortWildCard, bDstPortWildCard);
                        commMasterToSlave(msgGetIoTSetObj, "Get IoTSet objects!", inStream, outStream);
                }
                // Reinitialize IoTSet on device object
@@ -597,6 +602,15 @@ public class IoTMaster {
                        if (commHan.getComPort(strDeviceAddress) == null) {
                                commHan.addPortConnection(strIoTSlaveObjectHostAdd, strDeviceAddress);
                        }
+                       boolean bDstPortWildCard = false;
+                       // Recognize this and allocate different ports for it
+                       if (arrFieldValues.length > 3) {
+                               bDstPortWildCard = (boolean) arrFieldValues[4];
+                               if (bDstPortWildCard) { // This needs a unique source port
+                                       String strUniqueDev = strDeviceAddress + ":" + iRow;
+                                       commHan.addAdditionalPort(strUniqueDev);
+                               }
+                       }
                        // Send routing policy to router for device drivers and devices
                        // ROUTING POLICY: RMI communication - RMI registry and stub ports
                        if((iDestDeviceDriverPort == -1) && (!strProtocol.equals(STR_NO_PROTOCOL))) {