diff --git a/.gitignore b/.gitignore index 1377554..4c9b02a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ *.swp +*.class +.classpath +.project diff --git a/Job.java b/Job.java index beae1d2..2eabae4 100644 --- a/Job.java +++ b/Job.java @@ -1,3 +1,5 @@ +import java.lang.reflect.Method; + /* * Author: Bradlee Speice * Job Class @@ -12,11 +14,11 @@ public class Job { private jobThread myThread; //Reference to the thread we control private boolean myThreadPaused; //Used to keep track of the execution state of our thread - public Job(int jobTime, int jobID, Method parentAlgorithmDeallocate ){ + public Job(int jobTime, int jobID, Method parentAlgorithmDeallocate, int jobSize, int beginningLocation ){ //Create a new job, and start it running - myThread = new jobThread(jobTime, jobID, parentAlgorithmDeallocate); + myThread = new jobThread(jobTime, jobID, parentAlgorithmDeallocate, jobSize, beginningLocation); myThread.start(); - myThreadPause = false; + myThreadPaused = false; } public void pause(){ diff --git a/baseAlgorithm.java b/baseAlgorithm.java index d5fffdb..4ae8101 100644 --- a/baseAlgorithm.java +++ b/baseAlgorithm.java @@ -1,16 +1,5 @@ -public class baseAlgorithm{ +interface baseAlgorithm{ - int[] memoryBlock; - - void baseAlgorithm(int memorySize){ - /* Constructor needed for each algorithm */ - memoryBlock = new int[memorySize]; - } - - void allocate(int jobID, int jobSize, int jobTime){ - /* This method to be overloaded by each algorithm */ - } - void deallocate(int jobSize, int beginningLocation){ - - } + void allocate(int jobID, int jobSize, int jobTime); + void deallocate(int jobSize, int beginningLocation); } diff --git a/dummyAlgorithm.java b/dummyAlgorithm.java index 251ca55..cf4ed64 100644 --- a/dummyAlgorithm.java +++ b/dummyAlgorithm.java @@ -1,4 +1,4 @@ -public class dummyAlgorithm{ +public class dummyAlgorithm implements baseAlgorithm{ int[] memoryBlock; @@ -7,11 +7,11 @@ public class dummyAlgorithm{ memoryBlock = new int[memorySize]; } - void allocate(int jobID, int jobSize, int jobTime){ + public void allocate(int jobID, int jobSize, int jobTime){ /* This method to be overloaded by each algorithm */ System.out.println("Allocating job " + jobID + " with size: " + jobSize + " for: " + jobTime + " milliseconds."); } - void deallocate(int jobSize, int beginningLocation){ + public void deallocate(int jobSize, int beginningLocation){ System.out.println("Removing job with size: " + jobSize + " beginning at: " + beginningLocation); } } diff --git a/jobThread.java b/jobThread.java index 26a0462..edfecbf 100644 --- a/jobThread.java +++ b/jobThread.java @@ -1,3 +1,5 @@ +import java.lang.reflect.Method; + public class jobThread extends Thread { private final int sleepResolution = 200; //Milliseconds private long jobTime; //Milliseconds @@ -8,14 +10,19 @@ public class jobThread extends Thread { private boolean jobDone; private Method parentAlgorithmDeallocate; //Our parent to notify when we're done. - public jobThread(long jobTime, int jobID, Method parentAlgorithmDeallocate){ + /* Fields that we need to know when calling the deallocate */ + private int jobSize; + private int beginningLocation; + + public jobThread(long jobTime, int jobID, Method parentAlgorithmDeallocate, int jobSize, int beginningLocation){ this.jobTime = jobTime; this.parentAlgorithmDeallocate = parentAlgorithmDeallocate; - elapsedTime = 0; - isPaused = false; - startTime = 0; + this.elapsedTime = 0; + this.isPaused = false; + this.startTime = 0; this.jobID = jobID; - //this.parentAlgorithm = parentAlgorithm; + this.jobSize = jobSize; + this.beginningLocation = beginningLocation; } public void pause(){ @@ -70,12 +77,9 @@ public class jobThread extends Thread { } //We're done, go ahead and notify our algorithm to clean us up - parentAlgorithmDeallocate(jobID); + parentAlgorithmDeallocate.invoke(this.jobSize, this.beginningLocation); } catch (Exception e) { return; } - - - } }