?? device.java
字號(hào):
/*
* Device.java ver 0.1.0
*
* Created on 2006年12月12日, 下午3:12
*
*To simulate a device to the system
*
*History 2006年12月12日 ver 0.1.0 class create
* first release
*
*/
package ossimulation;
/**
*
* @author Decell.Zhou
*/
public class Device {
/** Creates a new instance of Device */
public Device(char argName) {
name = argName;
currentTime = 0;
interruptRequestBit = 0;
state = 0;//0 indicate that the device is idle
}
/**get the DRCB*/
public DRCB getDRCB(){
return currentRequest;
}
/**get the current device tiem for the current request process time*/
public int getCurrentTime(){
return currentTime;
}
/**return the device's state*/
public int getState(){
return state;
}
/**get the interrupt bit,0 indicate that there is no interrupt*/
public int getInterruptRequestBit(){
return interruptRequestBit;
}
/**clear the interrupt request bit*/
public void clearInterrupt(){
interruptRequestBit = 0;
}
/**run method,simulate the behavior of device */
public void run(){
if(currentTime != 0){
currentTime--;
if(currentTime == 0){
interruptRequestBit = 1;
state = 0;// set the device to idle
}
}
}
/** load method, load a job into the device*/
public void load(DRCB request){
currentRequest = request;
currentTime = currentRequest.getRequestTime();
interruptRequestBit = 0;
state = 1;//set the device to busy
}
/**main method, for the class debuging*/
public static void main(String[] args){
Device testDevice = new Device('A');
PCB testPCB = new PCB(1);
DRCB testDRCB = new DRCB(10,testPCB);
testDevice.load(testDRCB);
testDevice.run();
System.out.println(testDevice.getInterruptRequestBit());
System.out.println(testDevice.getDRCB().getRequestTime());
System.out.println(testDevice.getCurrentTime());
System.out.println(testDevice.getDRCB().getRequestProcess().getID());
System.out.println("------------------------------");
testDevice.run();
testDevice.run();
testDevice.run();
System.out.println(testDevice.getCurrentTime());
System.out.println(testDevice.getInterruptRequestBit());
System.out.println("------------------------------");
testDevice.run();
testDevice.run();
testDevice.run();
testDevice.run();
testDevice.run();
System.out.println(testDevice.getCurrentTime());
System.out.println(testDevice.getInterruptRequestBit());
System.out.println("------------------------------");
testDevice.run();
System.out.println(testDevice.getCurrentTime());
System.out.println(testDevice.getInterruptRequestBit());
}
private char name;//the name of the device
private DRCB currentRequest;//the process which requesting the device
private int currentTime;//the current running time of the device
private int interruptRequestBit;//the interrupt of the device
private int state;//the busy or idle state of the device
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -