@Override protected void recordCapabilitiesAndRequirements(OperationContext context, AttributeDefinition attribute, ModelNode newValue, ModelNode oldValue) { Map<Capability, Predicate<ModelNode>> capabilities = this.descriptor.getCapabilities(); if (!capabilities.isEmpty()) { PathAddress address = context.getCurrentAddress(); // newValue is already applied to the model ModelNode newModel = context.readResource(PathAddress.EMPTY_ADDRESS).getModel(); ModelNode oldModel = newModel.clone(); oldModel.get(attribute.getName()).set(oldValue); for (Map.Entry<Capability, Predicate<ModelNode>> entry : capabilities.entrySet()) { Capability capability = entry.getKey(); Predicate<ModelNode> predicate = entry.getValue(); boolean registered = predicate.test(oldModel); boolean shouldRegister = predicate.test(newModel); if (!registered && shouldRegister) { // Attribute change enables capability registration context.registerCapability(capability.resolve(address)); } else if (registered && !shouldRegister) { // Attribute change disables capability registration context.deregisterCapability(capability.resolve(address).getName()); } } } super.recordCapabilitiesAndRequirements(context, attribute, newValue, oldValue); }
@Override protected void recordCapabilitiesAndRequirements(OperationContext context, AttributeDefinition attribute, ModelNode newValue, ModelNode oldValue) { Map<Capability, Predicate<ModelNode>> capabilities = this.descriptor.getCapabilities(); if (!capabilities.isEmpty()) { PathAddress address = context.getCurrentAddress(); // newValue is already applied to the model ModelNode newModel = context.readResource(PathAddress.EMPTY_ADDRESS).getModel(); ModelNode oldModel = newModel.clone(); oldModel.get(attribute.getName()).set(oldValue); for (Map.Entry<Capability, Predicate<ModelNode>> entry : capabilities.entrySet()) { Capability capability = entry.getKey(); Predicate<ModelNode> predicate = entry.getValue(); boolean registered = predicate.test(oldModel); boolean shouldRegister = predicate.test(newModel); if (!registered && shouldRegister) { // Attribute change enables capability registration context.registerCapability(capability.resolve(address)); } else if (registered && !shouldRegister) { // Attribute change disables capability registration context.deregisterCapability(capability.resolve(address).getName()); } } } super.recordCapabilitiesAndRequirements(context, attribute, newValue, oldValue); }
@Override protected void recordCapabilitiesAndRequirements(OperationContext context, AttributeDefinition attributeDefinition, ModelNode newValue, ModelNode oldValue) { super.recordCapabilitiesAndRequirements(context, attributeDefinition, newValue, oldValue); Boolean needRemoting = needRemoting(context, newValue); if (needRemoting != null) { if (needRemoting) { context.registerAdditionalCapabilityRequirement(REMOTING_CAPABILITY, REMOTE_JMX_CAPABILITY.getName(), USE_MANAGEMENT_ENDPOINT.getName()); } else { context.deregisterCapabilityRequirement(REMOTING_CAPABILITY, REMOTE_JMX_CAPABILITY.getName(), USE_MANAGEMENT_ENDPOINT.getName()); } } }