/** * Calls shutdown on current state and waits until a finished state is reached. * * @throws InterruptedException if the waiting for a finished state is interrupted. */ public void shutdown() throws InterruptedException { stateLock.lock(); try { isShutdown = true; // interrupts any take operations takeCallLock.lock(); try { takeCallCondition.signalAll(); } finally { takeCallLock.unlock(); } currentServerState.shutdown(); while (true) { if (currentServerState.getCurrentState() == ServerStates.Finished) { break; } if (currentServerState.getCurrentState() == ServerStates.Error) { break; } stateChangeCondition.await(); } callMapCleanupTimer.cancel(); callMapCleanupTask.cancel(); stateTimeoutTimer.cancel(); } catch (InterruptedException e) { throw e; } finally { stateLock.unlock(); } }
public void register() throws UCESipException, InterruptedException { stateLock.lock(); try { currentServerState.startRegister(); while (true) { if (currentServerState.getCurrentState() == ServerStates.Registered) { break; } if (currentServerState.getCurrentState() == ServerStates.Error) { // check for asynchronous error throw ((ErrorServerState) currentServerState).getError(); } stateChangeCondition.await(); } long tp = sipSettings.getServerCallMapCleanupPeriodMillis(); callMapCleanupTimer.scheduleAtFixedRate(callMapCleanupTask, tp, tp); } catch (InterruptedException e) { throw e; } finally { stateLock.unlock(); } }
/** Call only with state lock, from state itself it should have the lock already */ @Override public void changeState(final IServerState newState) { if (currentServerState.equals(newState) == false) { // reset state timeout timer. if (currentStateTimeoutTask != null) { currentStateTimeoutTask.cancel(); currentStateTimeoutTask = null; } // check if the new state wants a timeout timer, and how long the // timeout shall be if (newState.getStateTimeoutMillis() != 0) { currentStateTimeoutTask = new StateTimeoutTask(); stateTimeoutTimer.schedule(currentStateTimeoutTask, newState.getStateTimeoutMillis()); } currentServerState = newState; LOGGER.trace("sip server changed state to " + newState.getCurrentState().toString()); currentServerState.onInit(); stateChangeCondition.signalAll(); } }