use of org.mule.runtime.core.api.retry.policy.RetryPolicyTemplate in project mule by mulesoft.
the class LifecycleAwareConfigurationInstance method testConnectivity.
private void testConnectivity() throws MuleException {
ConnectionProvider provider = connectionProvider.get();
if (provider instanceof NoConnectivityTest) {
return;
}
Scheduler retryScheduler = schedulerService.ioScheduler();
RetryPolicyTemplate retryTemplate = connectionManager.getRetryTemplateFor(provider);
ReconnectionConfig reconnectionConfig = connectionManager.getReconnectionConfigFor(provider);
RetryCallback retryCallback = new RetryCallback() {
@Override
public void doWork(RetryContext context) throws Exception {
Lock lock = testConnectivityLock;
if (lock != null) {
final boolean lockAcquired = lock.tryLock();
if (lockAcquired) {
LOGGER.info("Doing testConnectivity() for config " + getName());
try {
ConnectionValidationResult result = connectionManager.testConnectivity(LifecycleAwareConfigurationInstance.this);
if (result.isValid()) {
context.setOk();
} else {
if ((reconnectionConfig.isFailsDeployment())) {
context.setFailed(result.getException());
throw new ConnectionException(format("Connectivity test failed for config '%s'", getName()), result.getException());
} else {
if (LOGGER.isInfoEnabled()) {
LOGGER.info(format("Connectivity test failed for config '%s'. Application deployment will continue. Error was: ", getName(), result.getMessage()), result.getException());
}
}
}
} finally {
lock.unlock();
}
} else {
LOGGER.warn("There is a testConnectivity() already running for config " + getName());
}
}
}
@Override
public String getWorkDescription() {
return format("Testing connectivity for config '%s'", getName());
}
@Override
public Object getWorkOwner() {
return value;
}
};
try {
retryTemplate.execute(retryCallback, retryScheduler);
} catch (Exception e) {
throw new DefaultMuleException(createStaticMessage(format("Could not perform connectivity testing for config '%s'", getName())), e);
} finally {
if (retryScheduler != null) {
retryScheduler.stop();
}
}
}
use of org.mule.runtime.core.api.retry.policy.RetryPolicyTemplate in project mule by mulesoft.
the class AbstractComponentDefinitionParser method doParse.
@Override
protected Builder doParse(Builder definitionBuilder) throws ConfigurationException {
Builder finalBuilder = definitionBuilder.withIdentifier(operationDsl.getElementName()).withTypeDefinition(fromType(getMessageProcessorType())).withObjectFactoryType(getMessageProcessorFactoryType()).withConstructorParameterDefinition(fromFixedValue(extensionModel).build()).withConstructorParameterDefinition(fromFixedValue(componentModel).build()).withConstructorParameterDefinition(fromReferenceObject(MuleContext.class).build()).withConstructorParameterDefinition(fromReferenceObject(Registry.class).build()).withConstructorParameterDefinition(fromReferenceObject(PolicyManager.class).build()).withSetterParameterDefinition(TARGET_PARAMETER_NAME, fromSimpleParameter(TARGET_PARAMETER_NAME).build()).withSetterParameterDefinition(TARGET_VALUE_PARAMETER_NAME, fromSimpleParameter(TARGET_VALUE_PARAMETER_NAME).build()).withSetterParameterDefinition(CONFIG_PROVIDER_ATTRIBUTE_NAME, fromSimpleReferenceParameter(CONFIG_ATTRIBUTE_NAME).build()).withSetterParameterDefinition(CURSOR_PROVIDER_FACTORY_FIELD_NAME, fromChildConfiguration(CursorProviderFactory.class).build()).withSetterParameterDefinition("retryPolicyTemplate", fromChildConfiguration(RetryPolicyTemplate.class).build());
Optional<? extends NestableElementModel> nestedChain = componentModel.getNestedComponents().stream().filter(c -> c instanceof NestedChainModel).findFirst();
if (nestedChain.isPresent()) {
// TODO MULE-13483: improve parsers to support things like [source, chainOfProcessors, errorHandler]
// or [chainOfProcessors, errorHandler]
finalBuilder = finalBuilder.withSetterParameterDefinition("nestedProcessors", fromChildCollectionConfiguration(Processor.class).build());
parseParameters(componentModel.getAllParameterModels());
} else {
List<ParameterGroupModel> inlineGroups = getInlineGroups(componentModel);
parseParameters(getFlatParameters(inlineGroups, componentModel.getAllParameterModels()));
for (ParameterGroupModel group : inlineGroups) {
parseInlineParameterGroup(group);
}
// TODO MULE-13483
parseNestedComponents(componentModel.getNestedComponents());
}
return finalBuilder;
}
Aggregations