Cleaning up code for runtime, installer, RMI, compiler for the Java side
[iot2.git] / iotjava / iotruntime / slave / IoTSlave.java
index 0b6401dfb451b720dc93ea1353ce889e3aa2b3df..061de08ff4f2b18530490f8dce557ca2ef0fe391 100644 (file)
@@ -47,7 +47,7 @@ import net.lingala.zip4j.core.ZipFile;
  * @version     1.0
  * @since       2016-06-16
  */
-public class IoTSlave {
+public final class IoTSlave {
 
        /**
         * IoTSlave class properties
@@ -148,10 +148,10 @@ public class IoTSlave {
                        FileInputStream fis = new FileInputStream(file);
                        prop.load(fis);
                } catch (IOException ex) {
-                       System.out.println("IoTMaster: Error reading config file: " + strCfgFileName);
+                       RuntimeOutput.print("IoTMaster: Error reading config file: " + strCfgFileName, BOOL_VERBOSE);
                        ex.printStackTrace();
                }
-               System.out.println("IoTMaster: Extracting information from config file: " + strCfgFileName);
+               RuntimeOutput.print("IoTMaster: Extracting information from config file: " + strCfgFileName, BOOL_VERBOSE);
                // Initialize constants from config file
                STR_JAR_FILE_PATH = prop.getProperty("JAR_FILE_PATH");
                STR_OBJ_CLS_PFX = prop.getProperty("OBJECT_CLASS_PREFIX");
@@ -165,13 +165,13 @@ public class IoTSlave {
                        CAPAB_BASED_RMI = true;
                }
 
-               System.out.println("JAR_FILE_PATH=" + STR_JAR_FILE_PATH);
-               System.out.println("OBJECT_CLASS_PREFIX=" + STR_OBJ_CLS_PFX);
-               System.out.println("INTERFACE_PREFIX=" + STR_INTERFACE_PFX);
-               System.out.println("SKEL_CLASS_SUFFIX=" + SKEL_CLASS_SUFFIX);
-               System.out.println("STUB_CLASS_SUFFIX=" + STUB_CLASS_SUFFIX);
-               System.out.println("CAPAB_BASED_RMI=" + CAPAB_BASED_RMI);
-               System.out.println("IoTMaster: Information extracted successfully!");
+               RuntimeOutput.print("JAR_FILE_PATH=" + STR_JAR_FILE_PATH, BOOL_VERBOSE);
+               RuntimeOutput.print("OBJECT_CLASS_PREFIX=" + STR_OBJ_CLS_PFX, BOOL_VERBOSE);
+               RuntimeOutput.print("INTERFACE_PREFIX=" + STR_INTERFACE_PFX, BOOL_VERBOSE);
+               RuntimeOutput.print("SKEL_CLASS_SUFFIX=" + SKEL_CLASS_SUFFIX, BOOL_VERBOSE);
+               RuntimeOutput.print("STUB_CLASS_SUFFIX=" + STUB_CLASS_SUFFIX, BOOL_VERBOSE);
+               RuntimeOutput.print("CAPAB_BASED_RMI=" + CAPAB_BASED_RMI, BOOL_VERBOSE);
+               RuntimeOutput.print("IoTMaster: Information extracted successfully!", BOOL_VERBOSE);
        }
 
        /**
@@ -207,18 +207,6 @@ public class IoTSlave {
        private void createCapabBasedRMIJava(MessageCreateObject sMessage) throws 
                ClassNotFoundException, NoSuchMethodException, UnknownHostException {
 
-               // TODO: DEBUG
-               System.out.println("\n\nDEBUG: Create capab based RMI here!");
-               System.out.println("DEBUG: sMessage host address: " + sMessage.getHostAddress());
-               System.out.println("DEBUG: sMessage object class: " + sMessage.getObjectClass());
-               System.out.println("DEBUG: sMessage object name: " + sMessage.getObjectName());
-               System.out.println("DEBUG: sMessage interface name: " + sMessage.getObjectInterfaceName());
-               System.out.println("DEBUG: sMessage reg port: " + sMessage.getRMIRegPort());
-               System.out.println("DEBUG: sMessage stub port: " + sMessage.getRMIStubPort());
-               System.out.println("DEBUG: sMessage object fields: " + Arrays.toString(sMessage.getObjectFields()));
-               System.out.println("DEBUG: sMessage object fields: " + Arrays.toString(sMessage.getObjectFldCls()));
-               System.out.println("\n\n");
-
                // Instantiate the skeleton and put in the object
                String strObjSkelName = STR_OBJ_CLS_PFX + "." + sMessage.getObjectClass() +
                                                                        "." + sMessage.getObjectInterfaceName() + SKEL_CLASS_SUFFIX;
@@ -255,9 +243,6 @@ public class IoTSlave {
                        RemoteException, AlreadyBoundException, IllegalAccessException,
                                InvocationTargetException {
 
-               // TODO: DEBUG
-               System.out.println("\n\nDEBUG: CREATE DRIVER OBJECT!!!\n\n");
-
                // Translating into the actual Message class
                MessageCreateObject sMessage = (MessageCreateObject) sIoTMasterMsg;
                // Instantiate object using reflection
@@ -342,10 +327,6 @@ public class IoTSlave {
                // Translating into the actual Message class
                MessageCreateMainObject sMessage = (MessageCreateMainObject) sIoTMasterMsg;
 
-               // TODO: DEBUG
-               System.out.println("\n\nDEBUG: CREATE MAIN OBJECT!!!");
-               System.out.println("DEBUG: sMessage object name: " + sMessage.getObjectName());
-
                // Getting controller class
                File file = new File(STR_JAR_FILE_PATH + sMessage.getObjectName() + STR_JAR_FILE_EXT);
                RuntimeOutput.print("IoTSlave: DEBUG print path: " + STR_JAR_FILE_PATH +
@@ -374,10 +355,6 @@ public class IoTSlave {
                // Translating into the actual Message class
                MessageCreateSetRelation sMessage = (MessageCreateSetRelation) sIoTMasterMsg;
 
-               // TODO: DEBUG
-               System.out.println("\n\nDEBUG: CREATE NEW IOT SET!!!");
-               System.out.println("DEBUG: sMessage object field name: " + sMessage.getObjectFieldName());
-
                // Initialize field name
                strFieldName = sMessage.getObjectFieldName();
                RuntimeOutput.print("IoTSlave: Setting up field " + strFieldName, BOOL_VERBOSE);
@@ -401,10 +378,6 @@ public class IoTSlave {
                // Translating into the actual Message class
                MessageCreateSetRelation sMessage = (MessageCreateSetRelation) sIoTMasterMsg;
 
-               // TODO: DEBUG
-               System.out.println("\n\nDEBUG: CREATE NEW IOT RELATION!!!");
-               System.out.println("DEBUG: sMessage object field name: " + sMessage.getObjectFieldName());
-
                // Initialize field name
                strFieldName = sMessage.getObjectFieldName();
                RuntimeOutput.print("IoTSlave: Setting up field " + strFieldName, BOOL_VERBOSE);
@@ -461,16 +434,6 @@ public class IoTSlave {
 
                // Translating into the actual Message class
                MessageGetObject sMessage = (MessageGetObject) sIoTMasterMsg;
-
-               System.out.println("DEBUG: sMessage host address: " + sMessage.getHostAddress());
-               System.out.println("DEBUG: sMessage object class: " + sMessage.getObjectClass());
-               System.out.println("DEBUG: sMessage object name: " + sMessage.getObjectName());
-               System.out.println("DEBUG: sMessage interface name: " + sMessage.getObjectInterfaceName());
-               System.out.println("DEBUG: sMessage reg port: " + sMessage.getRMIRegPort());
-               System.out.println("DEBUG: sMessage stub port: " + sMessage.getRMIStubPort());
-               System.out.println("DEBUG: sMessage callback ports: " + Arrays.toString(sMessage.getRMICallbackPorts()));
-               System.out.println("\n\n");
-
                Object stubObjConv = null;
                String strObjectName = sMessage.getObjectName();
                String strObjClassInterfaceName = STR_OBJ_CLS_PFX + "." + STR_INTERFACE_PFX + "." +
@@ -510,10 +473,6 @@ public class IoTSlave {
        private void getIoTSetObject() throws IOException,
                ClassNotFoundException, RemoteException, NotBoundException, NoSuchMethodException,
                InstantiationException, IllegalAccessException, InvocationTargetException {
-
-               // TODO: DEBUG
-               System.out.println("\n\nDEBUG: GET IOT SET OBJECT!!!");
-
                Object objRegistry = null;
                if (CAPAB_BASED_RMI)
                        objRegistry = getObjectFromStub();
@@ -535,10 +494,6 @@ public class IoTSlave {
        private void getIoTRelationFirstObject() throws IOException,
                ClassNotFoundException, RemoteException, NotBoundException, NoSuchMethodException,
                InstantiationException, IllegalAccessException, InvocationTargetException {
-
-               // TODO: DEBUG
-               System.out.println("\n\nDEBUG: GET IOT RELATION FIRST OBJECT!!!");
-
                Object objRegistry = null;
                if (CAPAB_BASED_RMI)
                        objRegistry = getObjectFromStub();
@@ -560,10 +515,6 @@ public class IoTSlave {
        private void getIoTRelationSecondObject() throws IOException,
                ClassNotFoundException, RemoteException, NotBoundException, NoSuchMethodException,
                InstantiationException, IllegalAccessException, InvocationTargetException {
-
-               // TODO: DEBUG
-               System.out.println("\n\nDEBUG: GET IOT RELATION SECOND OBJECT!!!");
-
                Object objRegistry = null;
                if (CAPAB_BASED_RMI)
                        objRegistry = getObjectFromStub();
@@ -591,11 +542,6 @@ public class IoTSlave {
 
                // Reinitialize IoTSet field after getting all the objects
                iotsetObject = new IoTSet<Object>(isetObject.values());
-
-               // TODO: DEBUG
-               System.out.println("\n\nDEBUG: REINITIALIZE IOT SET FIELD!!!");
-               System.out.println("DEBUG: Field name: " + strFieldName + "\n\n");
-
                // Private fields need getDeclaredField(), while public fields use getField()
                Field fld = clsMain.getDeclaredField(strFieldName);
                boolean bAccess = fld.isAccessible();
@@ -620,11 +566,6 @@ public class IoTSlave {
 
                // Reinitialize IoTSet field after getting all the objects
                iotrelObject = new IoTRelation<Object,Object>(irelObject.relationMap(), irelObject.size());
-
-               // TODO: DEBUG
-               System.out.println("\n\nDEBUG: REINITIALIZE IOT RELATION FIELD!!!");
-               System.out.println("DEBUG: Field name: " + strFieldName + "\n\n");
-
                // Private fields need getDeclaredField(), while public fields use getField()
                Field fld = clsMain.getDeclaredField(strFieldName);
                boolean bAccess = fld.isAccessible();
@@ -650,15 +591,6 @@ public class IoTSlave {
 
                // Translating into the actual Message class
                MessageGetDeviceObject sMessage = (MessageGetDeviceObject) sIoTMasterMsg;
-
-               // TODO: DEBUG
-               System.out.println("\n\nDEBUG: GET DEVICE IOT SET OBJECT!!!");
-               System.out.println("DEBUG: sMessage host address: " + sMessage.getHostAddress());
-               System.out.println("DEBUG: sMessage source port: " + sMessage.getSourceDeviceDriverPort());
-               System.out.println("DEBUG: sMessage destination port: " + sMessage.getDestinationDeviceDriverPort());
-               System.out.println("DEBUG: sMessage source wild card: " + sMessage.isSourcePortWildCard());
-               System.out.println("DEBUG: sMessage desination wild card: " + sMessage.isDestinationPortWildCard() + "\n\n");
-
                // Get IoTSet objects for IP address set on device driver/controller
                IoTDeviceAddress objDeviceAddress = new IoTDeviceAddress(sMessage.getHostAddress(),
                        sMessage.getSourceDeviceDriverPort(),
@@ -686,11 +618,6 @@ public class IoTSlave {
 
                // Translating into the actual Message class
                MessageGetSimpleDeviceObject sMessage = (MessageGetSimpleDeviceObject) sIoTMasterMsg;
-
-               // TODO: DEBUG
-               System.out.println("\n\nDEBUG: GET ZIGBEE DEVICE IOT SET OBJECT!!!");
-               System.out.println("DEBUG: sMessage host address: " + sMessage.getHostAddress() + "\n\n");
-
                // Get IoTSet objects for IP address set on device driver/controller
                IoTZigbeeAddress objZBDevAddress = new IoTZigbeeAddress(sMessage.getHostAddress());
                RuntimeOutput.print("IoTSlave: Device address transferred: " + sMessage.getHostAddress(), BOOL_VERBOSE);
@@ -713,11 +640,6 @@ public class IoTSlave {
 
                // Translating into the actual Message class
                MessageGetSimpleDeviceObject sMessage = (MessageGetSimpleDeviceObject) sIoTMasterMsg;
-
-               // TODO: DEBUG
-               System.out.println("\n\nDEBUG: GET ADD IOT SET OBJECT!!!");
-               System.out.println("DEBUG: sMessage host address: " + sMessage.getHostAddress() + "\n\n");
-
                // Get IoTSet objects for IP address set on device driver/controller
                IoTAddress objAddress = new IoTAddress(sMessage.getHostAddress());
                RuntimeOutput.print("IoTSlave: Address transferred: " + sMessage.getHostAddress(), BOOL_VERBOSE);
@@ -736,9 +658,6 @@ public class IoTSlave {
         */
        private void invokeInitMethod() throws IOException {
 
-               // TODO: DEBUG
-               System.out.println("\n\nDEBUG: INVOKE INIT METHOD!!!\n\n");
-
                new Thread() {
                        public void run() {
                                try {
@@ -858,8 +777,6 @@ public class IoTSlave {
                        inStream.close();
                        socket.close();
                        RuntimeOutput.print("IoTSlave: Closing!", BOOL_VERBOSE);
-                       // We have to continuously loop because we are preserving our stubs and skeletons
-                       //while(true) { }
 
                } catch (IOException               |
                                 ClassNotFoundException    |