Search in sources :

Example 1 with SourceCallbackModelProperty

use of org.mule.runtime.module.extension.internal.loader.java.property.SourceCallbackModelProperty in project mule by mulesoft.

the class SourceModelLoaderDelegate method declareSourceCallback.

private void declareSourceCallback(SourceElement sourceType, SourceDeclarer source) {
    final Optional<MethodElement> onResponseMethod = sourceType.getOnResponseMethod();
    final Optional<MethodElement> onErrorMethod = sourceType.getOnErrorMethod();
    final Optional<MethodElement> onTerminateMethod = sourceType.getOnTerminateMethod();
    final Optional<MethodElement> onBackPressureMethod = sourceType.getOnBackPressureMethod();
    // TODO: MULE-9220 add syntax validator to check that none of these use @UseConfig or @Connection
    declareSourceCallbackParameters(source, onResponseMethod, source::onSuccess);
    declareSourceCallbackParameters(source, onErrorMethod, source::onError);
    declareSourceCallbackParameters(source, onTerminateMethod, source::onTerminate);
    declareSourceCallbackParameters(source, onBackPressureMethod, source::onBackPressure);
    source.withModelProperty(new SourceCallbackModelProperty(getMethod(onResponseMethod), getMethod(onErrorMethod), getMethod(onTerminateMethod), getMethod(onBackPressureMethod)));
}
Also used : SourceCallbackModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.SourceCallbackModelProperty) MethodElement(org.mule.runtime.module.extension.api.loader.java.type.MethodElement)

Example 2 with SourceCallbackModelProperty

use of org.mule.runtime.module.extension.internal.loader.java.property.SourceCallbackModelProperty 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);
}
Also used : SourceTransactionalAction(org.mule.runtime.extension.api.tx.SourceTransactionalAction) TransactionalActionModelProperty(org.mule.runtime.extension.internal.property.TransactionalActionModelProperty) Mono.create(reactor.core.publisher.Mono.create) ReflectionUtils.withAnnotation(org.reflections.ReflectionUtils.withAnnotation) Optional.of(java.util.Optional.of) FAIL(org.mule.runtime.extension.api.runtime.source.BackPressureAction.FAIL) Source(org.mule.runtime.extension.api.runtime.source.Source) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) ErrorTypeRepository(org.mule.runtime.api.exception.ErrorTypeRepository) PollingSourceWrapper(org.mule.runtime.module.extension.internal.runtime.source.poll.PollingSourceWrapper) ReactiveReconnectionCallback(org.mule.runtime.module.extension.internal.runtime.connectivity.ReactiveReconnectionCallback) DeclaringMemberModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.DeclaringMemberModelProperty) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) FLOW_BACK_PRESSURE(org.mule.runtime.core.api.exception.Errors.ComponentIdentifiers.Unhandleable.FLOW_BACK_PRESSURE) Map(java.util.Map) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) ModelProperty(org.mule.runtime.api.meta.model.ModelProperty) Method(java.lang.reflect.Method) TRANSACTIONAL_TYPE_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.TRANSACTIONAL_TYPE_PARAMETER_NAME) MessagingExceptionResolver(org.mule.runtime.core.internal.util.MessagingExceptionResolver) Startable(org.mule.runtime.api.lifecycle.Startable) ConnectionProvider(org.mule.runtime.api.connection.ConnectionProvider) Reconnectable(org.mule.runtime.extension.api.runtime.connectivity.Reconnectable) Connection(org.mule.runtime.extension.api.annotation.param.Connection) Set(java.util.Set) TRANSACTIONAL_ACTION_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.TRANSACTIONAL_ACTION_PARAMETER_NAME) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance) String.format(java.lang.String.format) SourceCallbackModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.SourceCallbackModelProperty) MuleExtensionUtils.getInitialiserEvent(org.mule.runtime.module.extension.api.util.MuleExtensionUtils.getInitialiserEvent) List(java.util.List) ConnectionException(org.mule.runtime.api.connection.ConnectionException) TransactionException(org.mule.runtime.api.tx.TransactionException) ErrorType(org.mule.runtime.api.message.ErrorType) Annotation(java.lang.annotation.Annotation) Optional(java.util.Optional) NONE(org.mule.runtime.extension.api.tx.SourceTransactionalAction.NONE) CursorProviderFactory(org.mule.runtime.core.api.streaming.CursorProviderFactory) BackPressureAction(org.mule.runtime.extension.api.runtime.source.BackPressureAction) ValueResolvingContext.from(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolvingContext.from) IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) Optional.empty(java.util.Optional.empty) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) LOCAL(org.mule.runtime.api.tx.TransactionType.LOCAL) TransactionalTypeModelProperty(org.mule.runtime.extension.internal.property.TransactionalTypeModelProperty) ResolverSet(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet) StreamingManager(org.mule.runtime.core.api.streaming.StreamingManager) Supplier(java.util.function.Supplier) BACK_PRESSURE_ACTION_CONTEXT_PARAM(org.mule.runtime.module.extension.internal.ExtensionProperties.BACK_PRESSURE_ACTION_CONTEXT_PARAM) Config(org.mule.runtime.extension.api.annotation.param.Config) Inject(javax.inject.Inject) IntrospectionUtils.getSourceName(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getSourceName) MuleContext(org.mule.runtime.core.api.MuleContext) FieldSetter(org.mule.runtime.module.extension.internal.util.FieldSetter) MuleException(org.mule.runtime.api.exception.MuleException) CollectionUtils(org.apache.commons.collections.CollectionUtils) Component(org.mule.runtime.api.component.Component) Mono.from(reactor.core.publisher.Mono.from) Collections.emptyMap(java.util.Collections.emptyMap) SourceCallback(org.mule.runtime.extension.api.runtime.source.SourceCallback) Logger(org.slf4j.Logger) ValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Publisher(org.reactivestreams.Publisher) BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) Initialisable(org.mule.runtime.api.lifecycle.Initialisable) Field(java.lang.reflect.Field) TransactionType(org.mule.runtime.api.tx.TransactionType) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) Either(org.mule.runtime.core.api.functional.Either) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) Stoppable(org.mule.runtime.api.lifecycle.Stoppable) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) ReflectionUtils.getAllFields(org.reflections.ReflectionUtils.getAllFields) ResolverSetResult(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSetResult) IntrospectionUtils.getFieldsOfType(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getFieldsOfType) PollingSourceWrapper(org.mule.runtime.module.extension.internal.runtime.source.poll.PollingSourceWrapper)

Aggregations

SourceCallbackModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.SourceCallbackModelProperty)2 String.format (java.lang.String.format)1 Annotation (java.lang.annotation.Annotation)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 Collections.emptyMap (java.util.Collections.emptyMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Optional.empty (java.util.Optional.empty)1 Optional.of (java.util.Optional.of)1 Set (java.util.Set)1 Supplier (java.util.function.Supplier)1 Inject (javax.inject.Inject)1 CollectionUtils (org.apache.commons.collections.CollectionUtils)1 Component (org.mule.runtime.api.component.Component)1 ComponentLocation (org.mule.runtime.api.component.location.ComponentLocation)1 ConnectionException (org.mule.runtime.api.connection.ConnectionException)1 ConnectionProvider (org.mule.runtime.api.connection.ConnectionProvider)1 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)1