Skip to content

Commit

Permalink
Creating class CreateAndTrack
Browse files Browse the repository at this point in the history
The Class contains all processes to generate some information about them
  • Loading branch information
Mahdi-jamil committed Sep 27, 2023
1 parent 30636cf commit a429049
Show file tree
Hide file tree
Showing 15 changed files with 174 additions and 111 deletions.
6 changes: 5 additions & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-20">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
36 changes: 36 additions & 0 deletions .m2/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">

<activeProfiles>
<activeProfile>github</activeProfile>
</activeProfiles>

<profiles>
<profile>
<id>github</id>
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
</repository>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/Mahdi-jamil/FCFS-scheduling-algorithm</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>

<servers>
<server>
<id>github</id>
<username>Mahdi-jamil</username>
<password>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</password>
</server>
</servers>
</settings>
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<configuration>
<includes>
<!-- Choose which Test to run by changing test number -->
<include>com.mahdi.test/Test2.java</include>
<include>com.mahdi.test/Test1.java</include>
</includes>
<parallel>classes</parallel>
<threadCount>10</threadCount>
Expand Down
89 changes: 8 additions & 81 deletions src/main/java/com/mahdi/main/MainTest.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package com.mahdi.main;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

import com.mahdi.process.Process;
import com.mahdi.process.CreateAndTrackProcesses;
import com.mahdi.scheduler.FCFSDispatcher;
import com.mahdi.scheduler.ReadyQueue;
import com.mahdi.scheduler.WaitingQueue;
Expand All @@ -18,11 +13,10 @@ public class MainTest {
public static int NUMBER_OF_PROCESSES=0;

private static volatile Boolean terminate=false;

private static float avgWT;
public static float avgWT;

// this function is used by Test Cases
// To run from main just edit line 45 to your File path
// To run from main just edit line 38 to your File path
public static float Main(String[] args) {
try {
main(args);
Expand All @@ -35,93 +29,26 @@ public static float Main(String[] args) {
}

public static void main(String[] args) throws FileNotFoundException {

ReadyQueue readyQueue=new ReadyQueue();
NewState newState=new NewState(readyQueue);
WaitingQueue waitingQueue=new WaitingQueue(readyQueue);
FCFSDispatcher dispatcher=new FCFSDispatcher(readyQueue, waitingQueue);
List<Process> p=new ArrayList<>();

CreateProcesses(args[0],p);


for(Process process:p) {
newState.addToReady(process);
}
CreateAndTrackProcesses tracker=new CreateAndTrackProcesses();

tracker.CreateProcesses(args[0]);

tracker.AddToReady(new NewState(readyQueue));

Thread cpuThread=new Thread(dispatcher);
cpuThread.start();


while (!terminate);
generateReport(p);
System.out.println("AVG Waiting Time "+ getAvgWaitingTime(p));

}

public static void CreateProcesses(String fileName,List<Process> p) throws FileNotFoundException {
File file=new File(fileName);
Scanner in=new Scanner(file);

int count=0;

Process testProcess;
int id;
int at;
LinkedList<Integer> btTest;
LinkedList<Integer> IOTest;

while (in.hasNextLine()) {
String line = in.nextLine();
String[] tokens = line.split(" ");

if (tokens.length < 2) {
continue;
}

id = Integer.parseInt(tokens[0]);
at = Integer.parseInt(tokens[1]);

btTest = new LinkedList<>();
IOTest = new LinkedList<>();

for (int i = 2; i < tokens.length; i++) {
// Parse each token as an integer and add it to the appropriate list
int value = Integer.parseInt(tokens[i]);
if (i % 2 == 0) {
btTest.add(value);
} else {
IOTest.add(value);
}
}
count++;
testProcess = new Process(id, at, btTest, IOTest);
p.add(testProcess);
}
NUMBER_OF_PROCESSES=count;
in.close();
tracker.generateReport();
tracker.getAvgWaitingTime();

}

public static void generateReport(List<Process> p) {
System.out.println("terminated with");
System.out.println("Pid AT BT CT TT WT");
for(Process process:p) {
System.out.println(process.getInfo());
}
}

public static float getAvgWaitingTime(List<Process> p) {
float avg=0;
for (Process process : p) {
avg+=process.getWT();
}
avgWT=avg/p.size();
return avgWT;

}

public static void terminate() {
MainTest.terminate=Boolean.TRUE;
Expand Down
89 changes: 89 additions & 0 deletions src/main/java/com/mahdi/process/CreateAndTrackProcesses.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.mahdi.process;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

import com.mahdi.main.MainTest;
import com.mahdi.main.NewState;

public class CreateAndTrackProcesses {
private List<Process> p=new ArrayList<>();


public List<Process> CreateProcesses(String fileName) throws FileNotFoundException {
File file=new File(fileName);
Scanner in=new Scanner(file);

int count=0;

Process testProcess;
int id;
int at;
LinkedList<Integer> btTest;
LinkedList<Integer> IOTest;

while (in.hasNextLine()) {
String line = in.nextLine();
String[] tokens = line.split(" ");

if (tokens.length < 2) {
continue;
}

id = Integer.parseInt(tokens[0]);
at = Integer.parseInt(tokens[1]);

btTest = new LinkedList<>();
IOTest = new LinkedList<>();

for (int i = 2; i < tokens.length; i++) {
// Parse each token as an integer and add it to the appropriate list
int value = Integer.parseInt(tokens[i]);
if (i % 2 == 0) {
btTest.add(value);
} else {
IOTest.add(value);
}
}
count++;
testProcess = new Process(id, at, btTest, IOTest);
p.add(testProcess);
}
MainTest.NUMBER_OF_PROCESSES=count;
in.close();
return p;

}


public void generateReport() {
System.out.println("terminated with");
System.out.println("Pid AT BT CT TT WT");
for(Process process:p) {
System.out.println(process.getInfo());
}
}


public float getAvgWaitingTime() {
float avg=0;
for (Process process : p) {
avg+=process.getWT();
}
MainTest.avgWT=avg/p.size();
System.out.println("AVG Waiting Time "+ MainTest.avgWT);
return MainTest.avgWT;
}



public void AddToReady(NewState newState) {
for(Process process:p) {
newState.addToReady(process);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#Generated by Maven Integration for Eclipse
#Tue Sep 26 23:41:39 PDT 2023
#Wed Sep 27 07:15:25 PDT 2023
artifactId=process-scheduling
groupId=com.mahdi.scheduling
m2e.projectLocation=C\:\\scheduling_project
m2e.projectName=process-scheduling
version=0.0.1-SNAPSHOT
version=1.0.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mahdi.scheduling</groupId>
<artifactId>process-scheduling</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mahdi.scheduling</groupId>
<artifactId>process-scheduling</artifactId>
<version>1.0.0-SNAPSHOT</version>


<dependencies>
<!--
https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
Expand All @@ -17,6 +17,7 @@
<scope>test</scope>
</dependency>


</dependencies>


Expand All @@ -35,7 +36,7 @@
<configuration>
<includes>
<!-- Choose which Test to run by changing test number -->
<include>com.mahdi.test/Test2.java</include>
<include>com.mahdi.test/Test1.java</include>
</includes>
<parallel>classes</parallel>
<threadCount>10</threadCount>
Expand All @@ -44,8 +45,15 @@

</plugins>
</build>




<distributionManagement>
<repository>
<id>github</id>
<name>GitHub Mahdi-jamil Apache Maven Packages</name>
<url>
https://maven.pkg.github.com/Mahdi-jamil/FCFS-scheduling-algorithm</url>
</repository>
</distributionManagement>


</project>
Binary file modified target/classes/com/mahdi/main/MainTest.class
Binary file not shown.
Binary file modified target/classes/com/mahdi/main/NewState$1.class
Binary file not shown.
Binary file modified target/classes/com/mahdi/main/NewState.class
Binary file not shown.
Binary file modified target/classes/com/mahdi/scheduler/CPU.class
Binary file not shown.
Binary file modified target/classes/com/mahdi/scheduler/ReadyQueue.class
Binary file not shown.
Binary file modified target/classes/com/mahdi/scheduler/WaitingQueue.class
Binary file not shown.
Loading

0 comments on commit a429049

Please sign in to comment.