*/
private void setCtx(int key) throws StateException {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "UserAgent.setCtx(" + key + ')');
if (key < 0) throw new StateException("Invalid context: " + key);
// If the required context is the last used, no need to update the
// references:
if (key == activeCtxId) return;
// Else, updating the activeCtx reference:
setActiveCtxId(key);
activeCtx = (ClientContext) contexts.get(new Integer(key));
// If context not found, throwing an exception:
if (activeCtx == null) {
setActiveCtxId(-1);
activeCtx = null;
throw new StateException("Context " + key + " is closed or broken.");
}
}