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;
hsDevicePort = new HashSet<Integer>();
hsCallbackPort = new HashSet<Integer>();
hmCallbackPort = new HashMap<Integer, Integer[]>();
+ hmAdditionalPort = new HashMap<Integer, Integer>();
iNumOfObjects = 0;
iNumOfHosts = 0;
bVerbose = _bVerbose;
}
+ /**
+ * 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>
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) {
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>
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
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))) {