?? statehelper.java
字號:
/****************************************************************************************/
/* 2001-Spring: Java Network-Programming Term-Project */
/* Title: Streaming media generation, capture and store. */
/* Team Member: Yumin Yuan(yuany@rpi.edu), Rui Mu(mur@rpi.edu), Yining Hu(huyn@rpi.edu) */
/* StateHelper.java: This class keeps track of the state of media transmission */
/* Complile: javac StateHelper.java */
/****************************************************************************************/
import javax.media.*;
public class StateHelper implements ControllerListener{
protected Integer stateLock = new Integer(0);
protected boolean failed = false;
Processor p;
public StateHelper(Processor _p){
p=_p;
p.addControllerListener(this);
}
Integer getStateLock() {
return stateLock;
}
void setFailed() {
failed = true;
}
public synchronized boolean waitForState(int state) {
failed = false;
// Call the required method on the processor
if (state == Processor.Configured) {
p.configure();
} else if (state == Processor.Realized) {
p.realize();
}
// Wait until we get an event that confirms the
// success of the method, or a failure event.
// See StateListener inner class
while (p.getState() < state && !failed) {
synchronized (getStateLock()) {
try {
getStateLock().wait();
} catch (InterruptedException ie) {
return false;
}
}
}
if (failed)
return false;
else
return true;
}
public void controllerUpdate(ControllerEvent event){
if (event instanceof ControllerClosedEvent)
setFailed();
// All controller events, send a notification
// to the waiting thread in waitForState method.
if (event instanceof ControllerEvent) {
synchronized (getStateLock()) {
getStateLock().notifyAll();
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -