@Override public synchronized boolean inhabitantChanged(EventType eventType, Inhabitant<?> inhabitant) { if (EventType.INHABITANT_ACTIVATED == eventType) { assert(inhabitant.isActive()); assert(AbstractInhabitantImpl.class.isInstance(inhabitant)); RunLevel rl = ((AbstractInhabitantImpl<?>)inhabitant).getAnnotation(RunLevel.class); // actually, it should really never be null (in real life we could consider tossing an exception) if (null != rl && rl.strict()) { if (targetScopeName.equals(rl.runLevelScope().getName())) { push(inhabitant); // verify it is not to a bad dependency if (rl.value() > runLevel) { throw new RunLevelException("Invalid RunLevel dependency to: " + inhabitant); } } } } return true; }
/** * Returns true if the RunLevel for the given inhabitant in question * should be processed by this RunLevelService instance. * * @param i the inhabitant * @param activeRunLevel the current runLevel * * @return */ protected boolean accept(AbstractInhabitantImpl<?> i, int activeRunLevel) { if (i.isActive()) { return false; } Integer runlevel = getRunLevel(i); if (null != runlevel) { if (Integer.valueOf(runlevel) != activeRunLevel) { return false; } } // avoid loading of the class until we have to ... at this point we have to RunLevel rl = i.getAnnotation(RunLevel.class); return (rl.value() == activeRunLevel && rl.environment() == targetEnv); }
/** * Returns true if the RunLevel for the given inhabitant in question should * be processed by this RunLevelService instance. * * @param i * the inhabitant * @param activeRunLevel * the current runLevel * * @return */ protected boolean accept(AbstractInhabitantImpl<?> i, int activeRunLevel) { if (i.isActive()) { return false; } Integer runlevel = getRunLevel(i); if (null != runlevel) { if (Integer.valueOf(runlevel) != activeRunLevel) { return false; } } // avoid loading of the class until we have to ... at this point we have // to RunLevel rl = i.getAnnotation(RunLevel.class); return (rl.value() == activeRunLevel && rl.runLevelScope() == targetScope); }
/** * Attempts to obtain the RunLevel value from the metadata() instead of from the annotation * which requires a class load. If it can't get it from the metadata() it will default to * load the class to obtain the RunLevel value. * * @param i the inhabitant to get the runLevel for * * @return */ protected Integer getRunLevel(AbstractInhabitantImpl<?> i) { Integer activeRunLevel; String runlevel = i.metadata().getOne(RunLevel.META_VAL_TAG); if (null != runlevel && runlevel.length() > 0) { activeRunLevel = Integer.valueOf(runlevel); } else { RunLevel rl = i.getAnnotation(RunLevel.class); activeRunLevel = (null == rl) ? null : rl.value(); } return activeRunLevel; }
/** * Check whether the strict constraint rules should be followed. * * @return true if strict constraint rules should be followed */ private boolean isStrict() { RunLevel rl = type().getAnnotation(RunLevel.class); return rl == null || rl.strict(); }
@Override public synchronized boolean inhabitantChanged(EventType eventType, Inhabitant<?> inhabitant) { if (EventType.INHABITANT_ACTIVATED == eventType) { assert(inhabitant.isActive()); assert(AbstractInhabitantImpl.class.isInstance(inhabitant)); RunLevel rl = ((AbstractInhabitantImpl<?>)inhabitant).getAnnotation(RunLevel.class); // actually, it should really never be null (in real life we could consider tossing an exception) if (null != rl) { if (targetEnv.equals(rl.environment().getName())) { push(inhabitant); // verify it is not to a bad dependency if (rl.value() > runLevel) { throw new ComponentException("Invalid RunLevel dependency to: " + inhabitant); } } } } return true; }
/** * Attempts to obtain the RunLevel value from the metadata() instead of from * the annotation which requires a class load. If it can't get it from the * metadata() it will default to load the class to obtain the RunLevel * value. * * @param i * the inhabitant to get the runLevel for * * @return */ protected Integer getRunLevel(AbstractInhabitantImpl<?> i) { Integer activeRunLevel; String runlevel = i.metadata().getOne(RunLevel.META_VAL_TAG); if (null != runlevel && runlevel.length() > 0) { activeRunLevel = Integer.valueOf(runlevel); } else { RunLevel rl = i.getAnnotation(RunLevel.class); activeRunLevel = (null == rl) ? null : rl.value(); } return activeRunLevel; }