statelistener.java

来自「It is Java for SIP phone」· Java 代码 · 共 65 行

JAVA
65
字号
package gov.nist.applet.phone.media.transmitter;import javax.media.*;public class StateListener implements ControllerListener {	private Integer stateLock = new Integer(0);    private boolean failed = false;    public Integer getStateLock() {        return stateLock;    }    public void setFailed() {        failed = true;    }	public void controllerUpdate(ControllerEvent ce) {		// If there was an error during configure or		// realize, the processor will be closed		if (ce instanceof ControllerClosedEvent)			setFailed();		// All controller events, send a notification		// to the waiting thread in waitForState method.		if (ce instanceof ControllerEvent) {			synchronized (getStateLock()) {				getStateLock().notifyAll();			}		}	}    public synchronized boolean waitForState(Processor p, int state) {        p.addControllerListener(this);        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;    }}

⌨️ 快捷键说明

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