public void setState(final QName pid, final ProcessState state) { __log.debug("Changing process state for " + pid + " to " + state); final ProcessConfImpl pconf; _rw.readLock().lock(); try { pconf = _processes.get(pid); if (pconf == null) { String msg = __msgs.msgProcessNotFound(pid); __log.info(msg); throw new ContextException(msg); } } finally { _rw.readLock().unlock(); } final DeploymentUnitDir dudir = pconf.getDeploymentUnit(); // Update in the database. ProcessState old = exec( new Callable<ProcessState>() { public ProcessState call(ConfStoreConnection conn) { DeploymentUnitDAO dudao = conn.getDeploymentUnit(dudir.getName()); if (dudao == null) { String errmsg = __msgs.msgProcessNotFound(pid); __log.error(errmsg); throw new ContextException(errmsg); } ProcessConfDAO dao = dudao.getProcess(pid); if (dao == null) { String errmsg = __msgs.msgProcessNotFound(pid); __log.error(errmsg); throw new ContextException(errmsg); } Set processKeys = _processes.keySet(); Iterator processConfQNameItr = processKeys.iterator(); while (processConfQNameItr.hasNext()) { ProcessConf cachedProcessConf = _processes.get(processConfQNameItr.next()); if (dao.getType().equals(cachedProcessConf.getType())) { if (ProcessState.ACTIVE == cachedProcessConf.getState() && ProcessState.RETIRED == dao.getState() && ProcessState.ACTIVE == state) { String errorMsg = "Can't activate the process with PID: " + dao.getPID() + " with version " + dao.getVersion() + ", as another version of the process with PID : " + cachedProcessConf.getProcessId() + " with version " + cachedProcessConf.getVersion() + " is already active."; __log.error(errorMsg); throw new ContextException(errorMsg); } } } ProcessState old = dao.getState(); dao.setState(state); pconf.setState(state); return old; } }); pconf.setState(state); if (old != null && old != state) fireStateChange(pid, state, pconf.getDeploymentUnit().getName()); }