use of org.mule.runtime.api.exception.DefaultMuleException 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.api.exception.DefaultMuleException in project mule by mulesoft.
the class SourceAdapter method setConnection.
private void setConnection() throws MuleException {
if (!connectionSetter.isPresent()) {
return;
}
FieldSetter<Object, ConnectionProvider> setter = connectionSetter.get();
ConfigurationInstance config = configurationInstance.orElseThrow(() -> new DefaultMuleException(createStaticMessage("Message Source on root component '%s' requires a connection but it doesn't point to any configuration. Please review your " + "application", component.getLocation().getRootContainerName())));
if (!config.getConnectionProvider().isPresent()) {
throw new DefaultMuleException(createStaticMessage(format("Message Source on root component '%s' requires a connection, but points to config '%s' which doesn't specify any. " + "Please review your application", component.getLocation().getRootContainerName(), config.getName())));
}
ConnectionProvider<Object> connectionProvider = new SourceConnectionProvider(connectionManager, config);
setter.set(sourceInvokationTarget.get(), connectionProvider);
}
use of org.mule.runtime.api.exception.DefaultMuleException in project mule by mulesoft.
the class SourceAdapter method start.
@Override
public void start() throws MuleException {
injectComponentLocation();
try {
setConfiguration(configurationInstance);
setConnection();
muleContext.getInjector().inject(sourceInvokationTarget.get());
if (source instanceof SourceWrapper) {
muleContext.getInjector().inject(source);
}
source.onStart(createSourceCallback());
} catch (Exception e) {
throw new DefaultMuleException(e);
}
}
use of org.mule.runtime.api.exception.DefaultMuleException in project mule by mulesoft.
the class ExtensionMessageSourceTestCase method failWithNonConnectionExceptionWhenStartingAndGetRetryPolicyExhausted.
@Test
public void failWithNonConnectionExceptionWhenStartingAndGetRetryPolicyExhausted() throws Exception {
doThrow(new DefaultMuleException(new IOException(ERROR_MESSAGE))).when(source).onStart(sourceCallback);
messageSource.initialise();
final Throwable throwable = catchThrowable(messageSource::start);
assertThat(throwable, is(instanceOf(RetryPolicyExhaustedException.class)));
assertThat(getThrowables(throwable), hasItemInArray(instanceOf(IOException.class)));
verify(source, times(3)).onStart(sourceCallback);
}
use of org.mule.runtime.api.exception.DefaultMuleException in project mule by mulesoft.
the class ExtensionMessageSourceTestCase method failToStart.
@Test
public void failToStart() throws Exception {
MuleException e = new DefaultMuleException(new Exception());
doThrow(e).when(source).onStart(any());
expectedException.expect(is(instanceOf(RetryPolicyExhaustedException.class)));
messageSource.initialise();
messageSource.start();
}
Aggregations