@AllowConcurrentEvents @Subscribe public void handle(final ConditionEvent.Satisfied event) { if (event.getCondition() == activationCondition) { reference.activate(); } }
@AllowConcurrentEvents @Subscribe public void handle(final ConditionEvent.Unsatisfied event) { if (event.getCondition() == activationCondition || event.getCondition() == nexusActiveCondition) { reference.passivate(); } }
ActivationConditionHandler bind() { if (activationCondition == null) { nexusActiveCondition = conditions.nexus().active(); try { activationCondition = reference.capability().activationCondition(); if (activationCondition instanceof CapabilityContextAware) { ((CapabilityContextAware) activationCondition).setContext(reference.context()); } } catch (Exception e) { activationCondition = new UnsatisfiedCondition("Failed to determine activation condition"); getLogger() .error( "Could not get activation condition from capability {} ({}). Considering it as non activatable", new Object[] {reference.capability(), reference.context().id(), e}); } if (activationCondition == null) { activationCondition = new SatisfiedCondition("Capability has no activation condition"); } nexusActiveCondition.bind(); activationCondition.bind(); eventBus.register(this); } return this; }
@Override public String toString() { return String.format( "Watching '%s' condition to activate/passivate capability '%s (id=%s)'", activationCondition, reference.capability(), reference.context().id()); }