Perfecting 4th benchmark; adding needed MySQL config files; maturing Zigbee drivers
[iot2.git] / iotjava / iotruntime / master / IoTMaster.java
index 31f82e91793c8fc401e6992eaf4364b8c90e73e5..1f7e697e43bc418ce97ff9cbf5956def9a94e14f 100644 (file)
@@ -84,6 +84,8 @@ public class IoTMaster {
        private static String STR_ZB_GATEWAY_PORT;
        private static String STR_ZB_IOTMASTER_PORT;
        private static String STR_NUM_CALLBACK_PORTS;
+       private static String STR_JVM_INIT_HEAP_SIZE;
+       private static String STR_JVM_MAX_HEAP_SIZE;
        private static boolean BOOL_VERBOSE;
 
        /**
@@ -156,6 +158,8 @@ public class IoTMaster {
                STR_ZB_GATEWAY_PORT = null;
                STR_ZB_IOTMASTER_PORT = null;
                STR_NUM_CALLBACK_PORTS = null;
+               STR_JVM_INIT_HEAP_SIZE = null;
+               STR_JVM_MAX_HEAP_SIZE = null;
                BOOL_VERBOSE = false;
        }
 
@@ -211,6 +215,8 @@ public class IoTMaster {
                STR_ZB_GATEWAY_PORT = prop.getProperty("ZIGBEE_GATEWAY_PORT");
                STR_ZB_IOTMASTER_PORT = prop.getProperty("ZIGBEE_IOTMASTER_PORT");
                STR_NUM_CALLBACK_PORTS = prop.getProperty("NUMBER_CALLBACK_PORTS");
+               STR_JVM_INIT_HEAP_SIZE = prop.getProperty("JVM_INIT_HEAP_SIZE");
+               STR_JVM_MAX_HEAP_SIZE = prop.getProperty("JVM_MAX_HEAP_SIZE");
                if(prop.getProperty("VERBOSE").equals(STR_YES)) {
                        BOOL_VERBOSE = true;
                }
@@ -231,6 +237,8 @@ public class IoTMaster {
                RuntimeOutput.print("STR_ZB_GATEWAY_PORT=" + STR_ZB_GATEWAY_PORT, BOOL_VERBOSE);
                RuntimeOutput.print("STR_ZB_IOTMASTER_PORT=" + STR_ZB_IOTMASTER_PORT, BOOL_VERBOSE);
                RuntimeOutput.print("STR_NUM_CALLBACK_PORTS=" + STR_NUM_CALLBACK_PORTS, BOOL_VERBOSE);
+               RuntimeOutput.print("STR_JVM_INIT_HEAP_SIZE=" + STR_JVM_INIT_HEAP_SIZE, BOOL_VERBOSE);
+               RuntimeOutput.print("STR_JVM_MAX_HEAP_SIZE=" + STR_JVM_MAX_HEAP_SIZE, BOOL_VERBOSE);
                RuntimeOutput.print("BOOL_VERBOSE=" + BOOL_VERBOSE, BOOL_VERBOSE);
                RuntimeOutput.print("IoTMaster: Information extracted successfully!", BOOL_VERBOSE);
        }
@@ -333,7 +341,7 @@ public class IoTMaster {
         * @params  inStream                  ObjectOutputStream communication
         * @return  void
         */
-       private void instrumentIoTSetDevice(String strFieldIdentifier, String strFieldName, String strIoTSlaveObjectHostAdd,
+       private void instrumentIoTSetDevice(String strFieldIdentifier, String strObjName, String strFieldName, String strIoTSlaveObjectHostAdd,
                ObjectInputStream inStream, ObjectOutputStream outStream) 
                        throws IOException, ClassNotFoundException, InterruptedException {
 
@@ -349,10 +357,13 @@ public class IoTMaster {
                        arrFieldValues = listObject.get(iRow);
                        // Get device address - if 00:00:00:00:00:00 that means it needs the driver object address (self)
                        String strDeviceAddress = null;
+                       String strDeviceAddressKey = null;
                        if (arrFieldValues[0].equals(STR_SELF_MAC_ADD)) {
                                strDeviceAddress = strIoTSlaveObjectHostAdd;
+                               strDeviceAddressKey = strObjName + "-" + strIoTSlaveObjectHostAdd;
                        } else {
                                strDeviceAddress = routerConfig.getIPFromMACAddress((String) arrFieldValues[0]);
+                               strDeviceAddressKey = strObjName + "-" + strDeviceAddress;
                        }
                        int iDestDeviceDriverPort = (int) arrFieldValues[1];
                        String strProtocol = (String) arrFieldValues[2];
@@ -364,18 +375,24 @@ public class IoTMaster {
                                bDstPortWildCard = (boolean) arrFieldValues[4];
                        }
                        // Add the port connection into communication handler - if it's not assigned yet
-                       if (commHan.getComPort(strDeviceAddress) == null) {
-                               commHan.addPortConnection(strIoTSlaveObjectHostAdd, strDeviceAddress);
+                       if (commHan.getComPort(strDeviceAddressKey) == null) {
+                               commHan.addPortConnection(strIoTSlaveObjectHostAdd, strDeviceAddressKey);
                        }
+
+                       // TODO: DEBUG!!!
+                       System.out.println("\n\n DEBUG: InstrumentSetDevice: Object Name: " + strObjName);
+                       System.out.println("DEBUG: InstrumentSetDevice: Port number: " + commHan.getComPort(strDeviceAddressKey));
+                       System.out.println("DEBUG: InstrumentSetDevice: Device address: " + strDeviceAddressKey + "\n\n");
+
                        // Send address one by one
                        Message msgGetIoTSetObj = null;
                        if (bDstPortWildCard) {
-                               String strUniqueDev = strDeviceAddress + ":" + iRow;
+                               String strUniqueDev = strDeviceAddressKey + ":" + 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);
+                                       strDeviceAddress, commHan.getComPort(strDeviceAddressKey), iDestDeviceDriverPort, bSrcPortWildCard, bDstPortWildCard);
                        commMasterToSlave(msgGetIoTSetObj, "Get IoTSet objects!", inStream, outStream);
                }
                // Reinitialize IoTSet on device object
@@ -394,7 +411,7 @@ public class IoTMaster {
         * @params  inStream                  ObjectOutputStream communication
         * @return  void
         */
-       private void instrumentIoTSetZBDevice(Map.Entry<String,Object> map, String strFieldName, String strIoTSlaveObjectHostAdd,
+       private void instrumentIoTSetZBDevice(Map.Entry<String,Object> map, String strObjName, String strFieldName, String strIoTSlaveObjectHostAdd,
                ObjectInputStream inStream, ObjectOutputStream outStream) 
                        throws IOException, ClassNotFoundException, InterruptedException {
 
@@ -405,24 +422,31 @@ public class IoTMaster {
                commMasterToSlave(msgCrtIoTSet, "Create new IoTSet for IoTZigbeeAddress!", inStream, outStream);
                // Prepare ZigbeeConfig
                String strZigbeeGWAddress = routerConfig.getIPFromMACAddress(STR_ZB_GATEWAY_ADDRESS);
+               String strZigbeeGWAddressKey = strObjName + "-" + strZigbeeGWAddress;
                int iZigbeeGWPort = Integer.parseInt(STR_ZB_GATEWAY_PORT);
                int iZigbeeIoTMasterPort = Integer.parseInt(STR_ZB_IOTMASTER_PORT);
                commHan.addDevicePort(iZigbeeIoTMasterPort);
                ZigbeeConfig zbConfig = new ZigbeeConfig(strZigbeeGWAddress, iZigbeeGWPort, iZigbeeIoTMasterPort, 
                        BOOL_VERBOSE);
                // Add the port connection into communication handler - if it's not assigned yet
-               if (commHan.getComPort(strZigbeeGWAddress) == null) {
-                       commHan.addPortConnection(strIoTSlaveObjectHostAdd, strZigbeeGWAddress);
+               if (commHan.getComPort(strZigbeeGWAddressKey) == null) {
+                       commHan.addPortConnection(strIoTSlaveObjectHostAdd, strZigbeeGWAddressKey);
                }               
                int iRows = setInstrumenter.numberOfRows();
                RuntimeOutput.print("IoTMaster: Number of rows for IoTZigbeeAddress: " + iRows, BOOL_VERBOSE);
+
+               // TODO: DEBUG!!!
+               System.out.println("\n\n DEBUG: InstrumentZigbeeDevice: Object Name: " + strObjName);
+               System.out.println("DEBUG: InstrumentZigbeeDevice: Port number: " + commHan.getComPort(strZigbeeGWAddressKey));
+               System.out.println("DEBUG: InstrumentZigbeeDevice: Device address: " + strZigbeeGWAddress + "\n\n");
+
                // Transfer the address
                for(int iRow=0; iRow<iRows; iRow++) {
                        arrFieldValues = setInstrumenter.fieldValues(iRow);
                        // Get device address
                        String strZBDevAddress = (String) arrFieldValues[0];
                        // Send policy to Zigbee gateway - TODO: Need to clear policy first?
-                       zbConfig.setPolicy(strIoTSlaveObjectHostAdd, commHan.getComPort(strZigbeeGWAddress), strZBDevAddress);
+                       zbConfig.setPolicy(strIoTSlaveObjectHostAdd, commHan.getComPort(strZigbeeGWAddressKey), strZBDevAddress);
                        // Send address one by one
                        Message msgGetIoTSetZBObj = new MessageGetSimpleDeviceObject(IoTCommCode.GET_ZB_DEV_IOTSET_OBJECT,
                                strZBDevAddress);
@@ -430,8 +454,7 @@ public class IoTMaster {
                }
                zbConfig.closeConnection();
                // Reinitialize IoTSet on device object
-               commMasterToSlave(new MessageSimple(IoTCommCode.REINITIALIZE_IOTSET_FIELD),
-                                                                                       "Reinitialize IoTSet fields!", inStream, outStream);
+               commMasterToSlave(new MessageSimple(IoTCommCode.REINITIALIZE_IOTSET_FIELD), "Reinitialize IoTSet fields!", inStream, outStream);
        }
 
        
@@ -591,37 +614,44 @@ public class IoTMaster {
                        objAddInitHand.addField(strFieldIdentifier, arrFieldValues);    // Save this for object instantiation
                        // Get device address - if 00:00:00:00:00:00 that means it needs the driver object address (self)
                        String strDeviceAddress = null;
+                       String strDeviceAddressKey = null;
                        if (arrFieldValues[0].equals(STR_SELF_MAC_ADD)) {
                                strDeviceAddress = strIoTSlaveObjectHostAdd;
-                       } else {
+                               strDeviceAddressKey = strObjName + "-" + strIoTSlaveObjectHostAdd;
+                       } else {        // Concatenate object name and IP address to give unique key - for a case where there is one device for multiple drivers
                                strDeviceAddress = routerConfig.getIPFromMACAddress((String) arrFieldValues[0]);
+                               strDeviceAddressKey = strObjName + "-" + strDeviceAddress;
                        }
                        int iDestDeviceDriverPort = (int) arrFieldValues[1];
                        String strProtocol = (String) arrFieldValues[2];
                        // Add the port connection into communication handler - if it's not assigned yet
-                       if (commHan.getComPort(strDeviceAddress) == null) {
-                               commHan.addPortConnection(strIoTSlaveObjectHostAdd, strDeviceAddress);
-                       }
+                       if (commHan.getComPort(strDeviceAddressKey) == null)
+                               commHan.addPortConnection(strIoTSlaveObjectHostAdd, strDeviceAddressKey);
                        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;
+                                       String strUniqueDev = strDeviceAddressKey + ":" + iRow; 
                                        commHan.addAdditionalPort(strUniqueDev);
                                }
                        }
+
+                       // TODO: DEBUG!!!
+                       System.out.println("\n\n DEBUG: InstrumentPolicySetDevice: Object Name: " + strObjName);
+                       System.out.println("DEBUG: InstrumentPolicySetDevice: Port number: " + commHan.getComPort(strDeviceAddressKey));
+                       System.out.println("DEBUG: InstrumentPolicySetDevice: Device address: " + strDeviceAddressKey + "\n\n");
+
+
                        // 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))) {
                                // Port number -1 means that we don't set the policy strictly to port number level
                                // "nopro" = no protocol specified for just TCP or just UDP (can be both used as well)
                                // ROUTING POLICY: Device driver and device
-                               routerConfig.configureRouterMainPolicies(STR_ROUTER_ADD, strIoTSlaveObjectHostAdd, strDeviceAddress,
-                                       strProtocol);
+                               routerConfig.configureRouterMainPolicies(STR_ROUTER_ADD, strIoTSlaveObjectHostAdd, strDeviceAddress, strProtocol);
                                // ROUTING POLICY: Send to the compute node where the device driver is
-                               routerConfig.configureHostMainPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveObjectHostAdd,
-                                       strDeviceAddress, strProtocol);
+                               routerConfig.configureHostMainPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveObjectHostAdd, strDeviceAddress, strProtocol);
                        } else if((iDestDeviceDriverPort == -1) && (strProtocol.equals(STR_NO_PROTOCOL))) {
                                routerConfig.configureRouterMainPolicies(STR_ROUTER_ADD, strIoTSlaveObjectHostAdd, strDeviceAddress);
                                routerConfig.configureHostMainPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveObjectHostAdd, strDeviceAddress);
@@ -629,19 +659,17 @@ public class IoTMaster {
                                // This is a TCP protocol that connects, e.g. a phone to our runtime system
                                // that provides a gateway access (accessed through destination port number)
                                commHan.addDevicePort(iDestDeviceDriverPort);
-                               routerConfig.configureRouterMainPolicies(STR_ROUTER_ADD, strIoTSlaveObjectHostAdd, strDeviceAddress,
-                                       STR_TCP_PROTOCOL, iDestDeviceDriverPort);
-                               routerConfig.configureHostMainPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveObjectHostAdd, strDeviceAddress,
-                                       STR_TCP_PROTOCOL, iDestDeviceDriverPort);
+                               routerConfig.configureRouterMainPolicies(STR_ROUTER_ADD, strIoTSlaveObjectHostAdd, strDeviceAddress, STR_TCP_PROTOCOL, iDestDeviceDriverPort);
+                               routerConfig.configureHostMainPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveObjectHostAdd, strDeviceAddress, STR_TCP_PROTOCOL, iDestDeviceDriverPort);
                                routerConfig.configureRouterHTTPPolicies(STR_ROUTER_ADD, strIoTSlaveObjectHostAdd, strDeviceAddress);
                                routerConfig.configureHostHTTPPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveObjectHostAdd, strDeviceAddress);
                        } else {
                                // Other port numbers...
                                commHan.addDevicePort(iDestDeviceDriverPort);
-                               routerConfig.configureRouterMainPolicies(STR_ROUTER_ADD, strIoTSlaveObjectHostAdd, strDeviceAddress,
-                                       strProtocol, commHan.getComPort(strDeviceAddress), iDestDeviceDriverPort);
-                               routerConfig.configureHostMainPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveObjectHostAdd, strDeviceAddress,
-                                       strProtocol, commHan.getComPort(strDeviceAddress), iDestDeviceDriverPort);
+                               routerConfig.configureRouterMainPolicies(STR_ROUTER_ADD, strIoTSlaveObjectHostAdd, strDeviceAddress, strProtocol, commHan.getComPort(strDeviceAddressKey), 
+                                       iDestDeviceDriverPort);
+                               routerConfig.configureHostMainPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveObjectHostAdd, strDeviceAddress, strProtocol, commHan.getComPort(strDeviceAddressKey), 
+                                       iDestDeviceDriverPort);
                        }
                }
        }
@@ -824,12 +852,12 @@ public class IoTMaster {
                                if(setInstrumenter.getObjTableName().equals(STR_IOT_DEV_ADD_CLS)) { 
                                // Instrument the normal IoTDeviceAddress
                                        synchronized(this) {
-                                               instrumentIoTSetDevice(strFieldIdentifier, strFieldName, strIoTSlaveObjectHostAdd, inStream, outStream);
+                                               instrumentIoTSetDevice(strFieldIdentifier, strObjName, strFieldName, strIoTSlaveObjectHostAdd, inStream, outStream);
                                        }
                                } else if(setInstrumenter.getObjTableName().equals(STR_IOT_ZB_ADD_CLS)) { 
                                // Instrument the IoTZigbeeAddress - special feature for Zigbee device support
                                        synchronized(this) {
-                                               instrumentIoTSetZBDevice(map, strFieldName, strIoTSlaveObjectHostAdd, inStream, outStream);
+                                               instrumentIoTSetZBDevice(map, strObjName, strFieldName, strIoTSlaveObjectHostAdd, inStream, outStream);
                                        }
                                } else if(setInstrumenter.getObjTableName().equals(STR_IOT_ADD_CLS)) { 
                                // Instrument the IoTAddress
@@ -1185,7 +1213,8 @@ public class IoTMaster {
 
                                // Construct ssh command line and create a controller thread for e.g. AcmeProximity
                                String strSSHCommand = STR_SSH_USERNAME + strIoTSlaveControllerHostAdd + " cd " +
-                                       STR_RUNTIME_DIR + " sudo java " + STR_CLS_PATH + " " +
+                                       STR_RUNTIME_DIR + " sudo java " + STR_JVM_INIT_HEAP_SIZE + " " + 
+                                       STR_JVM_MAX_HEAP_SIZE + " " + STR_CLS_PATH + " " +
                                        STR_RMI_PATH + " " + STR_IOT_SLAVE_CLS + " " + strIoTMasterHostAdd + " " +
                                        commHan.getComPort(strObjControllerName) + " " +
                                        commHan.getRMIRegPort(strObjControllerName) + " " +