List of usage examples for org.apache.commons.math3.distribution ExponentialDistribution ExponentialDistribution
public ExponentialDistribution(double mean)
From source file:LamportBasicVersion.java
public static void main(String[] args) throws FileNotFoundException, IOException, InterruptedException { totalMessageCount = 0;// w ww. j a va 2 s .co m //For parsing the file and storing the information String line; String configurationFile = "configuration.txt"; int lineCountInFile = 0; myProcessId = Integer.parseInt(args[0]); FileReader fileReader = new FileReader(configurationFile); BufferedReader bufferedReader = new BufferedReader(fileReader); while ((line = bufferedReader.readLine()) != null) { if ((!(line.startsWith("#"))) && (!(line.isEmpty()))) { lineCountInFile = lineCountInFile + 1; String[] splitLine = line.split(" "); switch (lineCountInFile) { case 1: numberOfProcesses = Integer.parseInt(splitLine[0]); interRequestDelay = Integer.parseInt(splitLine[1]); csExecutionTime = Integer.parseInt(splitLine[2]); maxNumberOfRequest = Integer.parseInt(splitLine[3]); machineNames = new String[Integer.parseInt(splitLine[0])]; portNumbers = new int[Integer.parseInt(splitLine[0])]; break; default: machineNames[lineCountInFile - 2] = splitLine[1]; portNumbers[lineCountInFile - 2] = Integer.parseInt(splitLine[2]); break; } } } conditionArray = new int[numberOfProcesses]; finishFlagArray = new int[numberOfProcesses]; //Initializing vector class VectorClass.initialize(numberOfProcesses); //Fill the arrays with zero false value for (int o = 0; o < numberOfProcesses; o++) { conditionArray[o] = 0; finishFlagArray[o] = 0; } // Write output to file filename = filename + Integer.toString(myProcessId) + ".out"; file = new File(filename); file.createNewFile(); writer = new FileWriter(file); // Write clocks to file filenameClock = filenameClock + Integer.toString(myProcessId) + ".out"; fileClock = new File(filenameClock); fileClock.createNewFile(); //writerClock = new FileWriter(fileClock); fw = new FileWriter(fileClock); bw = new BufferedWriter(fw); // // Expo mean insert csExecutionExpoDelay = new ExponentialDistribution(csExecutionTime); interRequestExpoDelay = new ExponentialDistribution(interRequestDelay); // System.out.println("********************************************************"); System.out.println("My process id : " + myProcessId); System.out.println("Number of processes : " + numberOfProcesses); System.out.println("Inter-request delay : " + interRequestDelay); System.out.println("Critical section execution time : " + csExecutionTime); System.out.println("Maximum number of request : " + maxNumberOfRequest); System.out.println( "My process name : " + machineNames[myProcessId] + " My port number : " + portNumbers[myProcessId]); for (int i = 0; i < numberOfProcesses; i++) { System.out.println("Process name : " + machineNames[i] + " Port number : " + portNumbers[i]); } System.out.println("********************************************************"); //For hosting server localhost SctpServerChannel sctpServerChannel = SctpServerChannel.open(); InetSocketAddress serverAddr = new InetSocketAddress(portNumbers[myProcessId]); sctpServerChannel.bind(serverAddr); System.out.println("********************************************************"); System.out.println("Local server hosted"); System.out.println("********************************************************"); //For creating neighbor SCTP channels Thread.sleep(30000); socketAddress = new SocketAddress[numberOfProcesses]; sctpChannel = new SctpChannel[numberOfProcesses]; System.out.println("********************************************************"); System.out.println("Neighbor channels created"); System.out.println("********************************************************"); //Thread spanned for generating critical section request new Thread(new LamportBasicVersion()).start(); //while loop to receive all the requests and other messages while (true) { try (SctpChannel sctpChannelFromClient = sctpServerChannel.accept()) { mutex.acquire(); byteBufferFromNeighbor.clear(); String receiveMessage; MessageInfo messageInfoFromNeighbor = sctpChannelFromClient.receive(byteBufferFromNeighbor, null, null); //System.out.println("Raw Message : " + messageInfoFromNeighbor); receiveMessage = byteToString(byteBufferFromNeighbor, messageInfoFromNeighbor); //write to file start writer.write("Received Message : " + receiveMessage); writer.write("\n"); writer.flush(); //write to file end System.out.println("Received Message : " + receiveMessage); if (receiveMessage.contains("Request")) { String[] parseMessage = receiveMessage.split("-"); lamportClock = Math.max(lamportClock, Integer.parseInt(parseMessage[3])) + 1; //vector clock update String[] stringNumericalTimestamp = parseMessage[4].split(","); int[] numericalTimestamp = new int[stringNumericalTimestamp.length]; for (int d = 0; d < stringNumericalTimestamp.length; d++) { numericalTimestamp[d] = Integer.parseInt(stringNumericalTimestamp[d]); } VectorClass.update(myProcessId, numericalTimestamp); // int requestMade = Integer.parseInt(parseMessage[3] + parseMessage[1]); queue.add(requestMade); //Send reply messages to that process for entering CS lamportClock++; //vector clock construction int[] vector = VectorClass.increment(myProcessId); String vectorClockConstruction = ""; for (int g = 0; g < vector.length; g++) { if (g == 0) { vectorClockConstruction = vectorClockConstruction + Integer.toString(vector[g]); } else { vectorClockConstruction = vectorClockConstruction + "," + Integer.toString(vector[g]); } } // for (int k = 0; k < numberOfProcesses; k++) { if (k == Integer.parseInt(parseMessage[1])) { try { byteBufferToNeighbor.clear(); initializeChannels(); sctpChannel[k].connect(socketAddress[k]); String sendMessage = "Reply from Process-" + myProcessId + "-" + Integer.toString(requestMade) + "-" + lamportClock + "-" + vectorClockConstruction; System.out.println("Message sent is : " + sendMessage); //write to file start writer.write("Message sent is : " + sendMessage); writer.write("\n"); writer.flush(); //write to file end MessageInfo messageInfoToNeighbor = MessageInfo.createOutgoing(null, 0); byteBufferToNeighbor.put(sendMessage.getBytes()); byteBufferToNeighbor.flip(); sctpChannel[k].send(byteBufferToNeighbor, messageInfoToNeighbor); totalMessageCount++; sctpChannel[k].close(); } catch (IOException ex) { Logger.getLogger(LamportBasicVersion.class.getName()).log(Level.SEVERE, null, ex); } } } } else if (receiveMessage.contains("Reply")) { conditionArray[myProcessId] = 1; String[] parseMessage = receiveMessage.split("-"); lamportClock = Math.max(lamportClock, Integer.parseInt(parseMessage[3])) + 1; //vector clock update String[] stringNumericalTimestamp = parseMessage[4].split(","); int[] numericalTimestamp = new int[stringNumericalTimestamp.length]; for (int d = 0; d < stringNumericalTimestamp.length; d++) { numericalTimestamp[d] = Integer.parseInt(stringNumericalTimestamp[d]); } VectorClass.update(myProcessId, numericalTimestamp); // conditionArray[Integer.parseInt(parseMessage[1])] = 1; int count = 0; for (int v = 0; v < numberOfProcesses; v++) { if (conditionArray[v] == 1) { count = count + 1; } } if (count == numberOfProcesses) { L1ConditionFlag = 1; System.out.println("Inside L1"); blockingQueue.put("L1"); //Clearing condition array after receiving all REPLY for (int z = 0; z < numberOfProcesses; z++) { conditionArray[z] = 0; } if (L2ConditionFlag == 0 && outstandingRequest == 1) { Integer[] queueArray = new Integer[queue.size()]; queue.toArray(queueArray); Arrays.sort(queueArray); if (queueArray[0] == currentRequestBeingServed) { System.out.println("Inside L2"); L2ConditionFlag = 1; blockingQueue.put("L2"); } } } } else if (receiveMessage.contains("Release")) { int present = 0; int delete = 0; String[] parseMessage = receiveMessage.split("-"); lamportClock = Math.max(lamportClock, Integer.parseInt(parseMessage[3])) + 1; //vector clock update String[] stringNumericalTimestamp = parseMessage[4].split(","); int[] numericalTimestamp = new int[stringNumericalTimestamp.length]; for (int d = 0; d < stringNumericalTimestamp.length; d++) { numericalTimestamp[d] = Integer.parseInt(stringNumericalTimestamp[d]); } VectorClass.update(myProcessId, numericalTimestamp); // if (queue.size() != 0) { Integer[] queueArray = new Integer[queue.size()]; queue.toArray(queueArray); Arrays.sort(queueArray); for (int a = 0; a < queueArray.length; a++) { if (queueArray[a] == Integer.parseInt(parseMessage[2])) { present = 1; delete = a; } } if (present == 1) { for (int s = 0; s <= delete; s++) { queue.remove(); } } } if (L2ConditionFlag == 0 && outstandingRequest == 1) { if (queue.size() != 0) { Integer[] queueArray1 = new Integer[queue.size()]; queue.toArray(queueArray1); Arrays.sort(queueArray1); if (currentRequestBeingServed == queueArray1[0]) { L2ConditionFlag = 1; System.out.println("Inside L2"); blockingQueue.put("L2"); } } } } else if (receiveMessage.contains("Finish")) { String[] parseMessage = receiveMessage.split("-"); lamportClock = Math.max(lamportClock, Integer.parseInt(parseMessage[3])) + 1; //vector clock update String[] stringNumericalTimestamp = parseMessage[4].split(","); int[] numericalTimestamp = new int[stringNumericalTimestamp.length]; for (int d = 0; d < stringNumericalTimestamp.length; d++) { numericalTimestamp[d] = Integer.parseInt(stringNumericalTimestamp[d]); } VectorClass.update(myProcessId, numericalTimestamp); // finishFlagArray[Integer.parseInt(parseMessage[1])] = 1; int count = 0; for (int v = 0; v < numberOfProcesses; v++) { if (finishFlagArray[v] == 1) { count = count + 1; } } if (count == numberOfProcesses) { break; } } //logic for other messages //Print the queue to check System.out.println("********************************************************"); for (Object item : queue) { System.out.print(item); System.out.print("\t"); } System.out.println("********************************************************"); } mutex.release(); } }
From source file:RoucairolCarvahloBasicVersion.java
public static void main(String[] args) throws FileNotFoundException, IOException, InterruptedException { //For parsing the file and storing the information String line;/* w w w. j av a 2 s .co m*/ String configurationFile = "configuration.txt"; int lineCountInFile = 0; myProcessId = Integer.parseInt(args[0]); FileReader fileReader = new FileReader(configurationFile); BufferedReader bufferedReader = new BufferedReader(fileReader); while ((line = bufferedReader.readLine()) != null) { if ((!(line.startsWith("#"))) && (!(line.isEmpty()))) { lineCountInFile = lineCountInFile + 1; String[] splitLine = line.split(" "); switch (lineCountInFile) { case 1: numberOfProcesses = Integer.parseInt(splitLine[0]); interRequestDelay = Integer.parseInt(splitLine[1]); csExecutionTime = Integer.parseInt(splitLine[2]); maxNumberOfRequest = Integer.parseInt(splitLine[3]); machineNames = new String[Integer.parseInt(splitLine[0])]; portNumbers = new int[Integer.parseInt(splitLine[0])]; break; default: machineNames[lineCountInFile - 2] = splitLine[1]; portNumbers[lineCountInFile - 2] = Integer.parseInt(splitLine[2]); break; } } } //Initializing finish array finishFlagArray = new int[numberOfProcesses]; //Initializing vector class VectorClass.initialize(numberOfProcesses); //Fill the arrays with zero false value for (int o = 0; o < numberOfProcesses; o++) { finishFlagArray[o] = 0; } //Initializing key array and inserting values keyArray = new int[numberOfProcesses]; for (int q = 0; q < numberOfProcesses; q++) { if (q >= myProcessId) { keyArray[q] = 1; } } filename = filename + Integer.toString(myProcessId) + ".out"; file = new File(filename); file.createNewFile(); writer = new FileWriter(file); // Write clocks to file filenameClock = filenameClock + Integer.toString(myProcessId) + ".out"; fileClock = new File(filenameClock); fileClock.createNewFile(); //writerClock = new FileWriter(fileClock); fw = new FileWriter(fileClock); bw = new BufferedWriter(fw); // // Expo mean insert csExecutionExpoDelay = new ExponentialDistribution(csExecutionTime); interRequestExpoDelay = new ExponentialDistribution(interRequestDelay); // System.out.println("********************************************************"); System.out.println("My process id : " + myProcessId); System.out.println("Number of processes : " + numberOfProcesses); System.out.println("Inter-request delay : " + interRequestDelay); System.out.println("Critical section execution time : " + csExecutionTime); System.out.println("Maximum number of request : " + maxNumberOfRequest); System.out.println( "My process name : " + machineNames[myProcessId] + " My port number : " + portNumbers[myProcessId]); for (int i = 0; i < numberOfProcesses; i++) { System.out.println("Process name : " + machineNames[i] + " Port number : " + portNumbers[i]); } System.out.println("********************************************************"); for (int q = 0; q < numberOfProcesses; q++) { System.out.println("KeyArray" + q + " - " + keyArray[q]); } System.out.println("********************************************************"); //For hosting server localhost SctpServerChannel sctpServerChannel = SctpServerChannel.open(); InetSocketAddress serverAddr = new InetSocketAddress(portNumbers[myProcessId]); sctpServerChannel.bind(serverAddr); System.out.println("********************************************************"); System.out.println("Local server hosted"); System.out.println("********************************************************"); //For creating neighbor SCTP channels Thread.sleep(30000); socketAddress = new SocketAddress[numberOfProcesses]; sctpChannel = new SctpChannel[numberOfProcesses]; System.out.println("********************************************************"); System.out.println("Neighbor channels created"); System.out.println("********************************************************"); //Thread spanned for generating critical section request new Thread(new RoucairolCarvahloBasicVersion()).start(); while (true) { try (SctpChannel sctpChannelFromClient = sctpServerChannel.accept()) { mutex.acquire(); byteBufferFromNeighbor.clear(); String receiveMessage; MessageInfo messageInfoFromNeighbor = sctpChannelFromClient.receive(byteBufferFromNeighbor, null, null); //System.out.println("Raw Message : " + messageInfoFromNeighbor); receiveMessage = byteToString(byteBufferFromNeighbor, messageInfoFromNeighbor); System.out.println("Received Message : " + receiveMessage); if (receiveMessage.contains("Request")) { String[] parseMessage = receiveMessage.split("-"); lamportClock = Math.max(lamportClock, Integer.parseInt(parseMessage[3])) + 1; //vector clock update String[] stringNumericalTimestamp = parseMessage[4].split(","); int[] numericalTimestamp = new int[stringNumericalTimestamp.length]; for (int d = 0; d < stringNumericalTimestamp.length; d++) { numericalTimestamp[d] = Integer.parseInt(stringNumericalTimestamp[d]); } VectorClass.update(myProcessId, numericalTimestamp); // int requestMade = Integer.parseInt(parseMessage[3] + parseMessage[1]); if (outstandingRequest == 1) { if (requestMade < currentRequestBeingServed) { lamportClock++; //Newly inserted for vector timesatmp int[] vector = VectorClass.increment(myProcessId); String vectorClockConstruction = ""; for (int g = 0; g < vector.length; g++) { if (g == 0) { vectorClockConstruction = vectorClockConstruction + Integer.toString(vector[g]); } else { vectorClockConstruction = vectorClockConstruction + "," + Integer.toString(vector[g]); } } // keyArray[Integer.parseInt(parseMessage[1])] = 0; try { byteBufferToNeighbor.clear(); initializeChannels(); sctpChannel[Integer.parseInt(parseMessage[1])] .connect(socketAddress[Integer.parseInt(parseMessage[1])]); String sendMessage = "Key from Process-" + myProcessId + "-" + requestMade + "-" + lamportClock + "-" + vectorClockConstruction; System.out.println("Message sent is : " + sendMessage); MessageInfo messageInfoToNeighbor = MessageInfo.createOutgoing(null, 0); byteBufferToNeighbor.put(sendMessage.getBytes()); byteBufferToNeighbor.flip(); sctpChannel[Integer.parseInt(parseMessage[1])].send(byteBufferToNeighbor, messageInfoToNeighbor); totalMessageCount++; sctpChannel[Integer.parseInt(parseMessage[1])].close(); } catch (IOException ex) { Logger.getLogger(RoucairolCarvahloBasicVersion.class.getName()).log(Level.SEVERE, null, ex); } //Include block for reverse request lamportClock++; //Newly inserted for vector timesatmp int[] vector1 = VectorClass.increment(myProcessId); String vectorClockConstruction1 = ""; for (int g = 0; g < vector1.length; g++) { if (g == 0) { vectorClockConstruction1 = vectorClockConstruction1 + Integer.toString(vector1[g]); } else { vectorClockConstruction1 = vectorClockConstruction1 + "," + Integer.toString(vector1[g]); } } // try { byteBufferToNeighbor.clear(); initializeChannels(); sctpChannel[Integer.parseInt(parseMessage[1])] .connect(socketAddress[Integer.parseInt(parseMessage[1])]); String sendMessage = "ReverseSend from Process-" + myProcessId + "-" + currentRequestBeingServed + "-" + lamportClock + "-" + vectorClockConstruction1; System.out.println("Message sent is : " + sendMessage); MessageInfo messageInfoToNeighbor = MessageInfo.createOutgoing(null, 0); byteBufferToNeighbor.put(sendMessage.getBytes()); byteBufferToNeighbor.flip(); sctpChannel[Integer.parseInt(parseMessage[1])].send(byteBufferToNeighbor, messageInfoToNeighbor); totalMessageCount++; sctpChannel[Integer.parseInt(parseMessage[1])].close(); } catch (IOException ex) { Logger.getLogger(RoucairolCarvahloBasicVersion.class.getName()).log(Level.SEVERE, null, ex); } } else if (requestMade == currentRequestBeingServed) { if (Integer.parseInt(parseMessage[1]) < myProcessId) { lamportClock++; //Newly inserted for vector timesatmp int[] vector = VectorClass.increment(myProcessId); String vectorClockConstruction = ""; for (int g = 0; g < vector.length; g++) { if (g == 0) { vectorClockConstruction = vectorClockConstruction + Integer.toString(vector[g]); } else { vectorClockConstruction = vectorClockConstruction + "," + Integer.toString(vector[g]); } } // keyArray[Integer.parseInt(parseMessage[1])] = 0; try { byteBufferToNeighbor.clear(); initializeChannels(); sctpChannel[Integer.parseInt(parseMessage[1])] .connect(socketAddress[Integer.parseInt(parseMessage[1])]); String sendMessage = "Key from Process-" + myProcessId + "-" + requestMade + "-" + lamportClock + "-" + vectorClockConstruction; System.out.println("Message sent is : " + sendMessage); MessageInfo messageInfoToNeighbor = MessageInfo.createOutgoing(null, 0); byteBufferToNeighbor.put(sendMessage.getBytes()); byteBufferToNeighbor.flip(); sctpChannel[Integer.parseInt(parseMessage[1])].send(byteBufferToNeighbor, messageInfoToNeighbor); totalMessageCount++; sctpChannel[Integer.parseInt(parseMessage[1])].close(); } catch (IOException ex) { Logger.getLogger(RoucairolCarvahloBasicVersion.class.getName()) .log(Level.SEVERE, null, ex); } //Include block for reverse request lamportClock++; //Newly inserted for vector timesatmp int[] vector1 = VectorClass.increment(myProcessId); String vectorClockConstruction1 = ""; for (int g = 0; g < vector1.length; g++) { if (g == 0) { vectorClockConstruction1 = vectorClockConstruction1 + Integer.toString(vector1[g]); } else { vectorClockConstruction1 = vectorClockConstruction1 + "," + Integer.toString(vector1[g]); } } // try { byteBufferToNeighbor.clear(); initializeChannels(); sctpChannel[Integer.parseInt(parseMessage[1])] .connect(socketAddress[Integer.parseInt(parseMessage[1])]); String sendMessage = "ReverseSend from Process-" + myProcessId + "-" + currentRequestBeingServed + "-" + lamportClock + "-" + vectorClockConstruction1; System.out.println("Message sent is : " + sendMessage); MessageInfo messageInfoToNeighbor = MessageInfo.createOutgoing(null, 0); byteBufferToNeighbor.put(sendMessage.getBytes()); byteBufferToNeighbor.flip(); sctpChannel[Integer.parseInt(parseMessage[1])].send(byteBufferToNeighbor, messageInfoToNeighbor); totalMessageCount++; sctpChannel[Integer.parseInt(parseMessage[1])].close(); } catch (IOException ex) { Logger.getLogger(RoucairolCarvahloBasicVersion.class.getName()) .log(Level.SEVERE, null, ex); } } else if (myProcessId < Integer.parseInt(parseMessage[1])) { queue.add(requestMade); } } else if (requestMade > currentRequestBeingServed) { queue.add(requestMade); } } else if (outstandingRequest == 0) { lamportClock++; //Newly inserted for vector timesatmp int[] vector = VectorClass.increment(myProcessId); String vectorClockConstruction = ""; for (int g = 0; g < vector.length; g++) { if (g == 0) { vectorClockConstruction = vectorClockConstruction + Integer.toString(vector[g]); } else { vectorClockConstruction = vectorClockConstruction + "," + Integer.toString(vector[g]); } } // keyArray[Integer.parseInt(parseMessage[1])] = 0; try { byteBufferToNeighbor.clear(); initializeChannels(); sctpChannel[Integer.parseInt(parseMessage[1])] .connect(socketAddress[Integer.parseInt(parseMessage[1])]); String sendMessage = "Key from Process-" + myProcessId + "-" + requestMade + "-" + lamportClock + "-" + vectorClockConstruction; System.out.println("Message sent is : " + sendMessage); MessageInfo messageInfoToNeighbor = MessageInfo.createOutgoing(null, 0); byteBufferToNeighbor.put(sendMessage.getBytes()); byteBufferToNeighbor.flip(); sctpChannel[Integer.parseInt(parseMessage[1])].send(byteBufferToNeighbor, messageInfoToNeighbor); totalMessageCount++; sctpChannel[Integer.parseInt(parseMessage[1])].close(); } catch (IOException ex) { Logger.getLogger(RoucairolCarvahloBasicVersion.class.getName()).log(Level.SEVERE, null, ex); } } } else if (receiveMessage.contains("Key")) { //receive check condition execute critical section block String[] parseMessage = receiveMessage.split("-"); lamportClock = Math.max(lamportClock, Integer.parseInt(parseMessage[3])) + 1; //vector clock update String[] stringNumericalTimestamp = parseMessage[4].split(","); int[] numericalTimestamp = new int[stringNumericalTimestamp.length]; for (int d = 0; d < stringNumericalTimestamp.length; d++) { numericalTimestamp[d] = Integer.parseInt(stringNumericalTimestamp[d]); } VectorClass.update(myProcessId, numericalTimestamp); // keyArray[Integer.parseInt(parseMessage[1])] = 1; int countOnes = 0; for (int y = 0; y < numberOfProcesses; y++) { if (keyArray[y] == 1) { countOnes = countOnes + 1; } } if (countOnes == numberOfProcesses) { outstandingRequest = 0; currentRequestBeingServed = 0; enterCriticalSectionExecution(); timestamp2 = new Timestamp(System.currentTimeMillis()); csExit(); } } else if (receiveMessage.contains("ReverseSend")) { String[] parseMessage = receiveMessage.split("-"); lamportClock = Math.max(lamportClock, Integer.parseInt(parseMessage[3])) + 1; //vector clock update String[] stringNumericalTimestamp = parseMessage[4].split(","); int[] numericalTimestamp = new int[stringNumericalTimestamp.length]; for (int d = 0; d < stringNumericalTimestamp.length; d++) { numericalTimestamp[d] = Integer.parseInt(stringNumericalTimestamp[d]); } VectorClass.update(myProcessId, numericalTimestamp); // int requestMade = Integer.parseInt(parseMessage[2]); if (outstandingRequest == 1) { if (requestMade < currentRequestBeingServed) { lamportClock++; //Newly inserted for vector timesatmp int[] vector = VectorClass.increment(myProcessId); String vectorClockConstruction = ""; for (int g = 0; g < vector.length; g++) { if (g == 0) { vectorClockConstruction = vectorClockConstruction + Integer.toString(vector[g]); } else { vectorClockConstruction = vectorClockConstruction + "," + Integer.toString(vector[g]); } } // keyArray[Integer.parseInt(parseMessage[1])] = 0; try { byteBufferToNeighbor.clear(); initializeChannels(); sctpChannel[Integer.parseInt(parseMessage[1])] .connect(socketAddress[Integer.parseInt(parseMessage[1])]); String sendMessage = "Key from Process-" + myProcessId + "-" + requestMade + "-" + lamportClock + "-" + vectorClockConstruction; System.out.println("Message sent is : " + sendMessage); MessageInfo messageInfoToNeighbor = MessageInfo.createOutgoing(null, 0); byteBufferToNeighbor.put(sendMessage.getBytes()); byteBufferToNeighbor.flip(); sctpChannel[Integer.parseInt(parseMessage[1])].send(byteBufferToNeighbor, messageInfoToNeighbor); totalMessageCount++; sctpChannel[Integer.parseInt(parseMessage[1])].close(); } catch (IOException ex) { Logger.getLogger(RoucairolCarvahloBasicVersion.class.getName()).log(Level.SEVERE, null, ex); } //Include block for reverse request lamportClock++; //Newly inserted for vector timesatmp int[] vector1 = VectorClass.increment(myProcessId); String vectorClockConstruction1 = ""; for (int g = 0; g < vector1.length; g++) { if (g == 0) { vectorClockConstruction1 = vectorClockConstruction1 + Integer.toString(vector1[g]); } else { vectorClockConstruction1 = vectorClockConstruction1 + "," + Integer.toString(vector1[g]); } } // try { byteBufferToNeighbor.clear(); initializeChannels(); sctpChannel[Integer.parseInt(parseMessage[1])] .connect(socketAddress[Integer.parseInt(parseMessage[1])]); String sendMessage = "ReverseSend from Process-" + myProcessId + "-" + currentRequestBeingServed + "-" + lamportClock + "-" + vectorClockConstruction1; System.out.println("Message sent is : " + sendMessage); MessageInfo messageInfoToNeighbor = MessageInfo.createOutgoing(null, 0); byteBufferToNeighbor.put(sendMessage.getBytes()); byteBufferToNeighbor.flip(); sctpChannel[Integer.parseInt(parseMessage[1])].send(byteBufferToNeighbor, messageInfoToNeighbor); totalMessageCount++; sctpChannel[Integer.parseInt(parseMessage[1])].close(); } catch (IOException ex) { Logger.getLogger(RoucairolCarvahloBasicVersion.class.getName()).log(Level.SEVERE, null, ex); } } else if (requestMade == currentRequestBeingServed) { if (Integer.parseInt(parseMessage[1]) < myProcessId) { lamportClock++; //Newly inserted for vector timesatmp int[] vector = VectorClass.increment(myProcessId); String vectorClockConstruction = ""; for (int g = 0; g < vector.length; g++) { if (g == 0) { vectorClockConstruction = vectorClockConstruction + Integer.toString(vector[g]); } else { vectorClockConstruction = vectorClockConstruction + "," + Integer.toString(vector[g]); } } // keyArray[Integer.parseInt(parseMessage[1])] = 0; try { byteBufferToNeighbor.clear(); initializeChannels(); sctpChannel[Integer.parseInt(parseMessage[1])] .connect(socketAddress[Integer.parseInt(parseMessage[1])]); String sendMessage = "Key from Process-" + myProcessId + "-" + requestMade + "-" + lamportClock + "-" + vectorClockConstruction; System.out.println("Message sent is : " + sendMessage); MessageInfo messageInfoToNeighbor = MessageInfo.createOutgoing(null, 0); byteBufferToNeighbor.put(sendMessage.getBytes()); byteBufferToNeighbor.flip(); sctpChannel[Integer.parseInt(parseMessage[1])].send(byteBufferToNeighbor, messageInfoToNeighbor); totalMessageCount++; sctpChannel[Integer.parseInt(parseMessage[1])].close(); } catch (IOException ex) { Logger.getLogger(RoucairolCarvahloBasicVersion.class.getName()) .log(Level.SEVERE, null, ex); } //Include block for reverse request lamportClock++; //Newly inserted for vector timesatmp int[] vector1 = VectorClass.increment(myProcessId); String vectorClockConstruction1 = ""; for (int g = 0; g < vector1.length; g++) { if (g == 0) { vectorClockConstruction1 = vectorClockConstruction1 + Integer.toString(vector1[g]); } else { vectorClockConstruction1 = vectorClockConstruction1 + "," + Integer.toString(vector1[g]); } } // try { byteBufferToNeighbor.clear(); initializeChannels(); sctpChannel[Integer.parseInt(parseMessage[1])] .connect(socketAddress[Integer.parseInt(parseMessage[1])]); String sendMessage = "ReverseSend from Process-" + myProcessId + "-" + currentRequestBeingServed + "-" + lamportClock + "-" + vectorClockConstruction1; System.out.println("Message sent is : " + sendMessage); MessageInfo messageInfoToNeighbor = MessageInfo.createOutgoing(null, 0); byteBufferToNeighbor.put(sendMessage.getBytes()); byteBufferToNeighbor.flip(); sctpChannel[Integer.parseInt(parseMessage[1])].send(byteBufferToNeighbor, messageInfoToNeighbor); totalMessageCount++; sctpChannel[Integer.parseInt(parseMessage[1])].close(); } catch (IOException ex) { Logger.getLogger(RoucairolCarvahloBasicVersion.class.getName()) .log(Level.SEVERE, null, ex); } } else if (myProcessId < Integer.parseInt(parseMessage[1])) { queue.add(requestMade); } } else if (requestMade > currentRequestBeingServed) { queue.add(requestMade); } } else if (outstandingRequest == 0) { lamportClock++; //Newly inserted for vector timesatmp int[] vector = VectorClass.increment(myProcessId); String vectorClockConstruction = ""; for (int g = 0; g < vector.length; g++) { if (g == 0) { vectorClockConstruction = vectorClockConstruction + Integer.toString(vector[g]); } else { vectorClockConstruction = vectorClockConstruction + "," + Integer.toString(vector[g]); } } // keyArray[Integer.parseInt(parseMessage[1])] = 0; try { byteBufferToNeighbor.clear(); initializeChannels(); sctpChannel[Integer.parseInt(parseMessage[1])] .connect(socketAddress[Integer.parseInt(parseMessage[1])]); String sendMessage = "Key from Process-" + myProcessId + "-" + requestMade + "-" + lamportClock + "-" + vectorClockConstruction; System.out.println("Message sent is : " + sendMessage); MessageInfo messageInfoToNeighbor = MessageInfo.createOutgoing(null, 0); byteBufferToNeighbor.put(sendMessage.getBytes()); byteBufferToNeighbor.flip(); sctpChannel[Integer.parseInt(parseMessage[1])].send(byteBufferToNeighbor, messageInfoToNeighbor); totalMessageCount++; sctpChannel[Integer.parseInt(parseMessage[1])].close(); } catch (IOException ex) { Logger.getLogger(RoucairolCarvahloBasicVersion.class.getName()).log(Level.SEVERE, null, ex); } } } else if (receiveMessage.contains("Finish")) { String[] parseMessage = receiveMessage.split("-"); lamportClock = Math.max(lamportClock, Integer.parseInt(parseMessage[3])) + 1; //vector clock update String[] stringNumericalTimestamp = parseMessage[4].split(","); int[] numericalTimestamp = new int[stringNumericalTimestamp.length]; for (int d = 0; d < stringNumericalTimestamp.length; d++) { numericalTimestamp[d] = Integer.parseInt(stringNumericalTimestamp[d]); } VectorClass.update(myProcessId, numericalTimestamp); // finishFlagArray[Integer.parseInt(parseMessage[1])] = 1; int count = 0; for (int v = 0; v < numberOfProcesses; v++) { if (finishFlagArray[v] == 1) { count = count + 1; } } if (count == numberOfProcesses) { break; } } } mutex.release(); } }
From source file:controller.DistributionController.java
public static void exponential(double media, double extra, int size) { numerosGerados.clear();/*from www.jav a 2s . c om*/ ExponentialDistribution ex = new ExponentialDistribution(media); for (int i = 0; i < size; i++) { numerosGerados.add(extra + ex.sample()); } }
From source file:TestBestOfFamilyBatching.java
public static MimacExperiment createBaseExperiment() { MimacExperiment e = new MimacExperiment(); e.setScenario(DataSet.FAB4r);//from w w w . j a va 2s . c o m DblStream arrivals1 = new DblDistribution(new ExponentialDistribution(1440d / 4.5)); DblStream arrivals2 = new DblDistribution(new ExponentialDistribution(1440d / 10.5)); e.setInterArrivalTimes(new DblStream[] { arrivals1, arrivals2 }); e.setDueDateFactors(new DblUniformRange(2.0, 5.0)); e.setJobWeights(new IntUniformRange(1, 10)); e.setSimulationLength(6 * 365 * 24 * 60); ExtendedJobStatCollector stats = new ExtendedJobStatCollector(); stats.setInitialPeriod(1 * 365 * 24 * 60); e.addShopListener(stats); e.setEnableLookAhead(false); e.setMaxJobsInSystem(3 * 250); // // PR<Machine, Job> pr = new FBFO(); // pr.setTieBreaker(new FSFO<Machine>()); // e.setSequencingRule(pr); // // e.setBatchingRule(new GreedyBatching()); return e; }
From source file:jasima.core.random.continuous.DblExp.java
/** * Sets the mean of the exponential distribution. * /*from w w w. j a va 2s . c o m*/ * @param mean * The exponential distribution's mean. This value has to be * {@code >0}. * @throws NotStrictlyPositiveException * If the supplied mean value was not positive. */ public void setMean(double mean) throws NotStrictlyPositiveException { dist = new ExponentialDistribution(mean); setDistribution(dist); }
From source file:de.uniwuerzburg.info3.ofcprobe.vswitch.trafficgen.IATGen.java
/** * Constructor// ww w .j a v a2 s. c o m * * @param distribution Distribution as String * @param para1 Parameter 1 * @param para2 Parameter 2 (only needed when applicable) */ public IATGen(String distribution, double para1, double para2) { logger.trace("Distribution selected: {} with Parameters {} & {}", distribution, para1, para2); switch (distribution) { case "ChiSquared": this.distri = new ChiSquaredDistribution(para1); break; case "Exponential": this.distri = new ExponentialDistribution(para1); break; case "Gamma": this.distri = new GammaDistribution(para1, para2); break; case "Poisson": this.intDistri = new PoissonDistribution(para1, para2); break; default: this.distri = new NormalDistribution(para1, para2); break; } }
From source file:jasima.core.util.converter.DblDistributionFactory.java
@Override public DblStream stringToStream(ArgListTokenizer tk) { TypeToStringConverter doubleConv = TypeToStringConverter.lookupConverter(Double.class); assert doubleConv != null; String prefix = tk.currTokenText(); tk.assureTokenTypes(tk.nextTokenNoWhitespace(), TokenType.PARENS_OPEN); ArrayList<Double> values = new ArrayList<Double>(); // there has to be at least one value Double v1 = doubleConv.fromString(tk, Double.class, prefix, this.getClass().getClassLoader(), Util.DEF_CLASS_SEARCH_PATH); values.add(v1);/*from w w w . jav a2 s .c o m*/ tk.assureTokenTypes(tk.nextTokenNoWhitespace(), TokenType.PARENS_CLOSE); return new DblDistribution(new ExponentialDistribution(v1.doubleValue())); }
From source file:TestMIMAC.java
public MimacExperiment createExperiment() { MimacExperiment e = new MimacExperiment(); e.setInitialSeed(-6437543093816807328l); e.setScenario(DataSet.FAB4r);/*from w w w . j a v a2 s.com*/ DblStream arrivals1 = new DblDistribution(new ExponentialDistribution(1440d / 4.5)); DblStream arrivals2 = new DblDistribution(new ExponentialDistribution(1440d / 10.5)); e.setInterArrivalTimes(new DblStream[] { arrivals1, arrivals2 }); e.setDueDateFactors(new DblUniformRange(2.0, 5.0)); e.setJobWeights(new IntUniformRange(1, 10)); e.setSimulationLength(6 * 365 * 24 * 60); e.setMaxJobsInSystem(3 * 250); e.setEnableLookAhead(false); ExtendedJobStatCollector stats = new ExtendedJobStatCollector(); stats.setInitialPeriod(365 * 24 * 60); e.addShopListener(stats); ATCS atcs = new ATCS(0.01, 0.5); atcs.setTieBreaker(new TieBreakerFASFS()); e.setSequencingRule(atcs); e.setBatchForming(new HighestJobBatchingMBS(0.75)); return e; }
From source file:jasima.shopSim.util.modelDef.streams.DblExponentialDef.java
@Override public DblStream createStream() { return new DblDistribution(new ExponentialDistribution(getMean())); }
From source file:jasima.shopSim.models.mimac.MimacExperiment.java
@Override protected void configureShop() { // configure model from file getScenario().getShopDef().getShopConfigurator().configureMdl(shop); super.configureShop(); // create job sources DblStream[] iats = getInterArrivalTimes(); if (iats != null && shop.routes.length != iats.length) { throw new RuntimeException("Number of routes (" + shop.routes.length + ") and inter-arrival streams (" + iats.length + ") doesn't match."); }/*from ww w . j ava 2s.c o m*/ // create job sources for each route, i.e., product for (int i = 0; i < shop.routes.length; i++) { DynamicJobSource s = new DynamicJobSource(); s.setRoute(shop.routes[i]); ArrivalsStationary arrivals = new ArrivalsStationary(); arrivals.setArrivalAtTimeZero(isArrivalAtTimeZero()); if (iats != null && iats[i] != null) { arrivals.setInterArrivalTimes(iats[i]); } else { arrivals.setInterArrivalTimes( new DblDistribution(new ExponentialDistribution(getScenario().defaultIats[i]))); } s.setArrivalProcess(arrivals); if (getDueDateFactors() != null) s.setDueDateFactors(getDueDateFactors()); if (getJobWeights() != null) s.setJobWeights(getJobWeights()); shop.addJobSource(s); } }