Search in sources :

Example 1 with ApplicationPolicyInstance

use of org.mule.runtime.module.deployment.impl.internal.policy.ApplicationPolicyInstance in project mule by mulesoft.

the class MuleApplicationPolicyProvider method addPolicy.

@Override
public synchronized void addPolicy(PolicyTemplateDescriptor policyTemplateDescriptor, PolicyParametrization parametrization) throws PolicyRegistrationException {
    try {
        checkArgument(application != null, "application was not configured on the policy provider");
        Optional<RegisteredPolicyInstanceProvider> registeredPolicyInstanceProvider = registeredPolicyInstanceProviders.stream().filter(p -> p.getPolicyId().equals(parametrization.getId())).findFirst();
        if (registeredPolicyInstanceProvider.isPresent()) {
            throw new IllegalArgumentException(createPolicyAlreadyRegisteredError(parametrization.getId()));
        }
        Optional<RegisteredPolicyTemplate> registeredPolicyTemplate = registeredPolicyTemplates.stream().filter(p -> p.policyTemplate.getDescriptor().getBundleDescriptor().getArtifactId().equals(policyTemplateDescriptor.getBundleDescriptor().getArtifactId())).findAny();
        if (!registeredPolicyTemplate.isPresent()) {
            PolicyTemplate policyTemplate = policyTemplateFactory.createArtifact(application, policyTemplateDescriptor);
            registeredPolicyTemplate = of(new RegisteredPolicyTemplate(policyTemplate));
            registeredPolicyTemplates.add(registeredPolicyTemplate.get());
        }
        ApplicationPolicyInstance applicationPolicyInstance = policyInstanceProviderFactory.create(application, registeredPolicyTemplate.get().policyTemplate, parametrization);
        applicationPolicyInstance.initialise();
        registeredPolicyInstanceProviders.add(new RegisteredPolicyInstanceProvider(applicationPolicyInstance, parametrization.getId()));
        registeredPolicyInstanceProviders.sort(null);
        registeredPolicyTemplate.get().count++;
    } catch (Exception e) {
        throw new PolicyRegistrationException(createPolicyRegistrationError(parametrization.getId()), e);
    }
}
Also used : Disposable(org.mule.runtime.api.lifecycle.Disposable) PolicyTemplate(org.mule.runtime.deployment.model.api.policy.PolicyTemplate) Optional.of(java.util.Optional.of) Preconditions.checkArgument(org.mule.runtime.api.util.Preconditions.checkArgument) PolicyParametrization(org.mule.runtime.core.api.policy.PolicyParametrization) PolicyRegistrationException(org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException) PolicyInstanceProviderFactory(org.mule.runtime.module.deployment.impl.internal.policy.PolicyInstanceProviderFactory) String.format(java.lang.String.format) ArrayList(java.util.ArrayList) PolicyProvider(org.mule.runtime.core.api.policy.PolicyProvider) PolicyTemplateDescriptor(org.mule.runtime.deployment.model.api.policy.PolicyTemplateDescriptor) List(java.util.List) Integer.compare(java.lang.Integer.compare) ApplicationPolicyInstance(org.mule.runtime.module.deployment.impl.internal.policy.ApplicationPolicyInstance) Policy(org.mule.runtime.core.api.policy.Policy) PolicyPointcutParameters(org.mule.runtime.policy.api.PolicyPointcutParameters) Optional(java.util.Optional) Application(org.mule.runtime.deployment.model.api.application.Application) LinkedList(java.util.LinkedList) PolicyTemplateFactory(org.mule.runtime.module.deployment.impl.internal.policy.PolicyTemplateFactory) PolicyRegistrationException(org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException) ApplicationPolicyInstance(org.mule.runtime.module.deployment.impl.internal.policy.ApplicationPolicyInstance) PolicyTemplate(org.mule.runtime.deployment.model.api.policy.PolicyTemplate) PolicyRegistrationException(org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException)

Aggregations

Integer.compare (java.lang.Integer.compare)1 String.format (java.lang.String.format)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Optional (java.util.Optional)1 Optional.of (java.util.Optional.of)1 Disposable (org.mule.runtime.api.lifecycle.Disposable)1 Preconditions.checkArgument (org.mule.runtime.api.util.Preconditions.checkArgument)1 Policy (org.mule.runtime.core.api.policy.Policy)1 PolicyParametrization (org.mule.runtime.core.api.policy.PolicyParametrization)1 PolicyProvider (org.mule.runtime.core.api.policy.PolicyProvider)1 Application (org.mule.runtime.deployment.model.api.application.Application)1 PolicyRegistrationException (org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException)1 PolicyTemplate (org.mule.runtime.deployment.model.api.policy.PolicyTemplate)1 PolicyTemplateDescriptor (org.mule.runtime.deployment.model.api.policy.PolicyTemplateDescriptor)1 ApplicationPolicyInstance (org.mule.runtime.module.deployment.impl.internal.policy.ApplicationPolicyInstance)1 PolicyInstanceProviderFactory (org.mule.runtime.module.deployment.impl.internal.policy.PolicyInstanceProviderFactory)1 PolicyTemplateFactory (org.mule.runtime.module.deployment.impl.internal.policy.PolicyTemplateFactory)1 PolicyPointcutParameters (org.mule.runtime.policy.api.PolicyPointcutParameters)1