Search in sources :

Example 1 with Scheduler

use of org.mule.runtime.core.api.source.scheduler.Scheduler 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();
        }
    }
}
Also used : BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Scheduler(org.mule.runtime.core.api.source.scheduler.Scheduler) PollingSource(org.mule.runtime.extension.api.runtime.source.PollingSource) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ResolverSetBasedObjectBuilder(org.mule.runtime.module.extension.internal.runtime.objectbuilder.ResolverSetBasedObjectBuilder) ValueResolvingContext(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolvingContext) PollingSource(org.mule.runtime.extension.api.runtime.source.PollingSource) Source(org.mule.runtime.extension.api.runtime.source.Source) PollingSourceWrapper(org.mule.runtime.module.extension.internal.runtime.source.poll.PollingSourceWrapper) MuleException(org.mule.runtime.api.exception.MuleException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException)

Aggregations

MuleException (org.mule.runtime.api.exception.MuleException)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)1 Scheduler (org.mule.runtime.core.api.source.scheduler.Scheduler)1 BaseEventContext (org.mule.runtime.core.privileged.event.BaseEventContext)1 PollingSource (org.mule.runtime.extension.api.runtime.source.PollingSource)1 Source (org.mule.runtime.extension.api.runtime.source.Source)1 ResolverSetBasedObjectBuilder (org.mule.runtime.module.extension.internal.runtime.objectbuilder.ResolverSetBasedObjectBuilder)1 ValueResolvingContext (org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolvingContext)1 PollingSourceWrapper (org.mule.runtime.module.extension.internal.runtime.source.poll.PollingSourceWrapper)1