⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 statehelper.java

📁 this is the media streaming project
💻 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();
		}
	    }	
    }
}
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -