use of org.mule.runtime.extension.api.runtime.source.Source 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.extension.api.runtime.source.Source in project mule by mulesoft.
the class SourceAdapter method doCreateCompletionHandler.
private SourceCompletionHandlerFactory doCreateCompletionHandler(SourceCallbackModelProperty modelProperty) {
SourceCallbackExecutor onSuccessExecutor;
SourceCallbackExecutor onErrorExecutor;
SourceCallbackExecutor onTerminateExecutor;
SourceCallbackExecutor onBackPressureExecutor;
if (source instanceof SourceWrapper) {
SourceWrapper wrapper = (SourceWrapper) source;
onSuccessExecutor = getMethodExecutor(modelProperty.getOnSuccessMethod(), modelProperty, wrapper::onSuccess);
onErrorExecutor = getMethodExecutor(modelProperty.getOnErrorMethod(), modelProperty, wrapper::onError);
onTerminateExecutor = getMethodExecutor(modelProperty.getOnTerminateMethod(), modelProperty, wrapper::onTerminate);
onBackPressureExecutor = getMethodExecutor(modelProperty.getOnBackPressureMethod(), modelProperty, wrapper::onBackPressure);
} else {
onSuccessExecutor = getMethodExecutor(modelProperty.getOnSuccessMethod(), modelProperty);
onErrorExecutor = getMethodExecutor(modelProperty.getOnErrorMethod(), modelProperty);
onTerminateExecutor = getMethodExecutor(modelProperty.getOnTerminateMethod(), modelProperty);
onBackPressureExecutor = getMethodExecutor(modelProperty.getOnBackPressureMethod(), modelProperty);
}
return context -> new DefaultSourceCompletionHandler(onSuccessExecutor, onErrorExecutor, onTerminateExecutor, onBackPressureExecutor, context);
}
Aggregations