use of org.mule.runtime.api.exception.MuleException 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.MuleException in project mule by mulesoft.
the class SourceConfigurer method configure.
/**
* Performs the configuration of the given {@code source} and returns the result
*
* @param source a {@link Source}
* @param config the {@link ConfigurationInstance config instance} associated to {@code this} source object.
* @return the configured instance
* @throws MuleException
*/
public Source configure(Source source, Optional<ConfigurationInstance> config) throws MuleException {
ResolverSetBasedObjectBuilder<Source> builder = new ResolverSetBasedObjectBuilder<Source>(source.getClass(), model, resolverSet) {
@Override
protected Source instantiateObject() {
return source;
}
@Override
public Source build(ValueResolvingContext context) throws MuleException {
Source source = build(resolverSet.resolve(context));
injectDefaultEncoding(model, source, muleContext.getConfiguration().getDefaultEncoding());
injectComponentLocation(source, componentLocation);
config.ifPresent(c -> injectRefName(source, c.getName(), getReflectionCache()));
return source;
}
};
CoreEvent initialiserEvent = null;
try {
initialiserEvent = getInitialiserEvent(muleContext);
Source configuredSource = builder.build(from(initialiserEvent, config));
if (configuredSource instanceof PollingSource) {
Scheduler scheduler = (Scheduler) resolverSet.getResolvers().get(SCHEDULING_STRATEGY_PARAMETER_NAME).resolve(ValueResolvingContext.from(initialiserEvent));
configuredSource = new PollingSourceWrapper((PollingSource) configuredSource, scheduler);
}
return configuredSource;
} catch (Exception e) {
throw new MuleRuntimeException(createStaticMessage("Exception was found trying to configure source of type " + source.getClass().getName()), e);
} finally {
if (initialiserEvent != null) {
((BaseEventContext) initialiserEvent.getContext()).success();
}
}
}
use of org.mule.runtime.api.exception.MuleException 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.MuleException in project mule by mulesoft.
the class ExtensionConnectivityTestingStrategyTestCase method connectionProviderThrowsException.
@Test
public void connectionProviderThrowsException() throws MuleException {
final Exception e = new RuntimeException();
when(connectionProviderResolver.resolve(any())).thenThrow(e);
ConnectionValidationResult connectionResult = extensionConnectivityTestingStrategy.testConnectivity(connectionProviderResolver);
assertThat(connectionResult.isValid(), is(false));
assertThat(connectionResult.getException(), is(sameInstance(e)));
}
use of org.mule.runtime.api.exception.MuleException 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