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);
}
}
Aggregations