1 package iotruntime.master;
7 /** Class CRuntimeInstrumenterMaster helps instrument C++ code.
8 * This class basically reads a C++ config file that has information
9 * about fields of IoTSet and IoTRelation.
11 * @author Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
15 public class CRuntimeInstrumenterMaster {
18 * CRuntimeInstrumenterMaster class constants
20 private static final String STR_IOT_SET_TYPE = "IoTSet";
21 private static final String STR_IOT_RELATION_TYPE = "IoTRelation";
22 private static final String STR_FIELD_NUMBER = "FIELD_NUMBER";
23 private static final String STR_FIELD = "FIELD_";
24 private static final String STR_FIELD_CLASS = "FIELD_CLASS_";
25 // For IoTRelation second object class
26 private static final String STR_FIELD_CLASS_REL = "FIELD_CLASS_REL_";
27 private static final String STR_FIELD_TYPE = "FIELD_TYPE_";
28 private static final String STR_CONFIG_EXTENSION = ".config";
29 private static final String STR_CONFIG_FILE_PATH = "mysql/";
32 * CRuntimeInstrumenterMaster class properties
34 private HashMap<String,Object> hmObj;
35 private String strObjectID;
36 private boolean bVerbose;
37 private String strObjectConfigFile;
42 public CRuntimeInstrumenterMaster(String strConfigFile, String strObjID, boolean _bVerbose) {
44 hmObj = new HashMap<String,Object>();
45 strObjectID = strObjID;
47 strObjectConfigFile = strConfigFile;
52 * A method to parse information from a config file
54 * @param strCfgFileName Config file name
55 * @param strCfgField Config file field name
58 private String parseConfigFile(String strCfgFileName, String strCfgField) {
59 // Parse configuration file
60 Properties prop = new Properties();
61 File file = new File(strCfgFileName);
62 FileInputStream fis = null;
64 fis = new FileInputStream(file);
67 } catch (IOException ex) {
68 System.out.println("CRuntimeInstrumenterMaster: Error reading config file: " + strCfgFileName +
69 ". Please make sure it contains field information!");
72 System.out.println("CRuntimeInstrumenterMaster: Reading " + strCfgField +
73 " from config file: " + strCfgFileName + " with value: " +
74 prop.getProperty(strCfgField, null));
75 // NULL is returned if the property isn't found
76 return prop.getProperty(strCfgField, null);
81 * A method to parse field information
85 private void getFieldInfo() {
87 // Parse the config file and look for field information
88 String strFieldNum = parseConfigFile(strObjectConfigFile, STR_FIELD_NUMBER);
90 if (strFieldNum != null)
91 iNumOfField = Integer.parseInt(strFieldNum);
93 throw new Error("CRuntimeInstrumenterMaster: Number of fields information not found!");
94 for (int iFieldCounter=0; iFieldCounter<iNumOfField; iFieldCounter++) {
95 String strFieldKey = STR_FIELD + iFieldCounter; // Start from 0
96 String strFieldClassKey = STR_FIELD_CLASS + iFieldCounter;
97 String strFieldTypeKey = STR_FIELD_TYPE + iFieldCounter;
98 String strField = parseConfigFile(strObjectConfigFile, strFieldKey);
99 String strFieldClass = parseConfigFile(strObjectConfigFile, strFieldClassKey);
100 String strFieldType = parseConfigFile(strObjectConfigFile, strFieldTypeKey);
101 // Check if this is a Set class, then process it
102 if (strFieldType.equals(STR_IOT_SET_TYPE)) {
103 RuntimeOutput.print("CRuntimeInstrumenterMaster: IoTSet is detected!", bVerbose);
104 SetInstrumenter setInstrument = new
105 SetInstrumenter(strFieldClass, STR_CONFIG_FILE_PATH + strField + STR_CONFIG_EXTENSION, strObjectID, bVerbose);
106 hmObj.put(strField, setInstrument);
107 // Check if this is a Relation class, then process it
108 } else if (strFieldType.equals(STR_IOT_RELATION_TYPE)) {
109 RuntimeOutput.print("CRuntimeInstrumenterMaster: IoTRelation is detected!", bVerbose);
110 String strFieldClassRelKey = STR_FIELD_CLASS_REL + iFieldCounter;
111 String strFieldClassRel = parseConfigFile(strObjectConfigFile, strFieldClassRelKey);
112 RelationInstrumenter relInstrument = new
113 RelationInstrumenter(strFieldClass, strFieldClassRel, STR_CONFIG_FILE_PATH + strField + STR_CONFIG_EXTENSION, bVerbose);
114 hmObj.put(strField, relInstrument);
116 throw new Error("CRuntimeInstrumenterMaster: " + strFieldType + " not recognized!");
122 * A method that returns HashMap hmObj
124 * @return HashMap<String,Object>
126 public HashMap<String,Object> getFieldObjects() {