mirror of
https://github.com/bspeice/itcs3146-project
synced 2024-12-26 08:38:15 -05:00
Add in the reflection code for Jobs
This commit is contained in:
parent
c9cc6fc9ad
commit
ef42d9791f
@ -15,7 +15,7 @@ class FirstFit implements baseAlgorithm
|
|||||||
startLoc,
|
startLoc,
|
||||||
endLoc,
|
endLoc,
|
||||||
blkSize,
|
blkSize,
|
||||||
memSize = memoryManagement.memory,
|
memSize,
|
||||||
active,
|
active,
|
||||||
noJobs=0,
|
noJobs=0,
|
||||||
s1=0,
|
s1=0,
|
||||||
@ -26,8 +26,9 @@ class FirstFit implements baseAlgorithm
|
|||||||
private int[] memory = new int[memSize];
|
private int[] memory = new int[memSize];
|
||||||
|
|
||||||
//this is a no argument constructor
|
//this is a no argument constructor
|
||||||
public FirstFit()
|
public FirstFit(int memSize)
|
||||||
{
|
{
|
||||||
|
this.memSize = memSize;
|
||||||
memTable[0][0]=0; //job number
|
memTable[0][0]=0; //job number
|
||||||
memTable[0][1]=0; //job size
|
memTable[0][1]=0; //job size
|
||||||
memTable[0][2]=0; //start location in memory
|
memTable[0][2]=0; //start location in memory
|
||||||
|
7
Job.java
7
Job.java
@ -14,9 +14,12 @@ public class Job {
|
|||||||
private jobThread myThread; //Reference to the thread we control
|
private jobThread myThread; //Reference to the thread we control
|
||||||
private boolean myThreadPaused; //Used to keep track of the execution state of our thread
|
private boolean myThreadPaused; //Used to keep track of the execution state of our thread
|
||||||
|
|
||||||
public Job(int jobTime, int jobID, Method parentAlgorithmDeallocate, int jobSize, int beginningLocation ){
|
public Job(int jobTime, int jobID, int jobSize, int beginningLocation, Method parentAlgorithmDeallocate, Object parentAlgorithm ){
|
||||||
//Create a new job, and start it running
|
//Create a new job, and start it running
|
||||||
myThread = new jobThread(jobTime, jobID, parentAlgorithmDeallocate, jobSize, beginningLocation);
|
myThread = new jobThread(jobTime, jobID,jobSize, beginningLocation, parentAlgorithmDeallocate, parentAlgorithm);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start(){
|
||||||
myThread.start();
|
myThread.start();
|
||||||
myThreadPaused = false;
|
myThreadPaused = false;
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import java.lang.reflect.*;
|
||||||
|
|
||||||
public class dummyAlgorithm implements baseAlgorithm{
|
public class dummyAlgorithm implements baseAlgorithm{
|
||||||
|
|
||||||
int[] memoryBlock;
|
int[] memoryBlock;
|
||||||
@ -9,9 +11,21 @@ public class dummyAlgorithm implements baseAlgorithm{
|
|||||||
|
|
||||||
public 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 */
|
/* This method to be overloaded by each algorithm */
|
||||||
System.out.println("Allocating job " + jobID + " with size: " + jobSize + " for: " + jobTime + " milliseconds.");
|
|
||||||
|
//Generic code to get this classes deallocate() method
|
||||||
|
Method deallocateMethod;
|
||||||
|
try {
|
||||||
|
deallocateMethod = this.getClass().getMethod("deallocate", new Class[]{int.class, int.class});
|
||||||
|
Job newJob = new Job(jobTime, jobID, jobSize, 999, deallocateMethod, this);
|
||||||
|
newJob.start();
|
||||||
|
System.out.println("Allocating job " + jobID + " with size: " + jobSize + " for: " + jobTime + " milliseconds.");
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deallocate(int jobSize, int beginningLocation){
|
public void deallocate(int jobSize, int beginningLocation){
|
||||||
System.out.println("Removing job with size: " + jobSize + " beginning at: " + beginningLocation);
|
System.err.println("Removing job with size: " + jobSize + " beginning at: " + beginningLocation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public class jobThread extends Thread {
|
public class jobThread extends Thread {
|
||||||
@ -9,14 +10,16 @@ public class jobThread extends Thread {
|
|||||||
private int jobID;
|
private int jobID;
|
||||||
private boolean jobDone;
|
private boolean jobDone;
|
||||||
private Method parentAlgorithmDeallocate; //Our parent to notify when we're done.
|
private Method parentAlgorithmDeallocate; //Our parent to notify when we're done.
|
||||||
|
private Object parentAlgorithm; //The actual instance of our parent class
|
||||||
|
|
||||||
/* Fields that we need to know when calling the deallocate */
|
/* Fields that we need to know when calling the deallocate */
|
||||||
private int jobSize;
|
private int jobSize;
|
||||||
private int beginningLocation;
|
private int beginningLocation;
|
||||||
|
|
||||||
public jobThread(long jobTime, int jobID, Method parentAlgorithmDeallocate, int jobSize, int beginningLocation){
|
public jobThread(long jobTime, int jobID, int jobSize, int beginningLocation, Method parentAlgorithmDeallocate, Object parentClass){
|
||||||
this.jobTime = jobTime;
|
this.jobTime = jobTime;
|
||||||
this.parentAlgorithmDeallocate = parentAlgorithmDeallocate;
|
this.parentAlgorithmDeallocate = parentAlgorithmDeallocate;
|
||||||
|
this.parentAlgorithm = parentClass;
|
||||||
this.elapsedTime = 0;
|
this.elapsedTime = 0;
|
||||||
this.isPaused = false;
|
this.isPaused = false;
|
||||||
this.startTime = 0;
|
this.startTime = 0;
|
||||||
@ -76,8 +79,10 @@ public class jobThread extends Thread {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Object[] deallocateArgs = {this.jobSize, this.beginningLocation};
|
||||||
//We're done, go ahead and notify our algorithm to clean us up
|
//We're done, go ahead and notify our algorithm to clean us up
|
||||||
parentAlgorithmDeallocate.invoke(this.jobSize, this.beginningLocation);
|
parentAlgorithmDeallocate.invoke(parentAlgorithm, deallocateArgs);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,6 @@ import java.util.StringTokenizer;
|
|||||||
|
|
||||||
public class memoryManagement{
|
public class memoryManagement{
|
||||||
|
|
||||||
//added by David Turnbull variable to set memory for algorithms
|
|
||||||
public static int memory = 1024;
|
|
||||||
|
|
||||||
public static void main(String args[])throws Exception{
|
public static void main(String args[])throws Exception{
|
||||||
final int JOBAMOUNT = 1000;
|
final int JOBAMOUNT = 1000;
|
||||||
final int MEMORYSIZE = 10000;
|
final int MEMORYSIZE = 10000;
|
||||||
|
Loading…
Reference in New Issue
Block a user