/** * Change the context to the given state * * @param context the context * @param required the required state * @return the actual state * @throws Throwable for any error */ protected ControllerState change(KernelControllerContext context, ControllerState required) throws Throwable { Controller controller = kernel.getController(); controller.change(context, required); return context.getState(); }
public Set<KernelControllerContext> getContexts(Class<?> clazz, ControllerState state) { lockRead(); try { Set<KernelControllerContext> contexts = getContexts(clazz); if (contexts != null && contexts.isEmpty() == false) { Set<KernelControllerContext> kccs = new HashSet<KernelControllerContext>(); for(KernelControllerContext context : contexts) { if (isBeforeState(context.getState(), state) == false) kccs.add(context); } return Collections.unmodifiableSet(kccs); } else return null; } finally { unlockRead(); } }
@SuppressWarnings("unchecked") T getInstanceFromContext() { if (context == null) throw new IllegalArgumentException("Null context"); if (context.getState() != ControllerState.INSTALLED) { ControllerStateModel states = context.getController().getStates(); if (states.isBeforeState(context.getState(), ControllerState.INSTALLED)) { throw new ResolutionException(context + " has not reached the INSTALLED state"); } } T target = (T)context.getTarget(); if (target == null) { throw new ResolutionException(context + " has an empty instance"); } return target; } }
/** * Change a bean * * @param controller the controller * @param context the context * @param state the state * @throws Throwable for any error */ protected void changeBean(KernelController controller, KernelControllerContext context, ControllerState state) throws Throwable { if (ControllerMode.MANUAL.equals(context.getMode()) && ControllerState.ERROR.equals(context.getState()) == false) controller.change(context, state); }