Search in sources :

Example 6 with ConstructDeclarer

use of org.mule.runtime.api.meta.model.declaration.fluent.ConstructDeclarer in project mule by mulesoft.

the class MuleExtensionModelDeclarer method declareScatterGather.

private void declareScatterGather(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) {
    ConstructDeclarer scatterGather = extensionDeclarer.withConstruct("scatterGather").describedAs("Sends the same message to multiple message processors in parallel.").withErrorModel(compositeRoutingError);
    scatterGather.withRoute("route").withMinOccurs(2).withChain();
    scatterGather.onDefaultParameterGroup().withOptionalParameter("timeout").ofType(typeLoader.load(Long.class)).defaultingTo(Long.MAX_VALUE).withExpressionSupport(NOT_SUPPORTED).describedAs("Sets a timeout in milliseconds for each route. Values lower or equals than zero means no timeout.");
    scatterGather.onDefaultParameterGroup().withOptionalParameter("maxConcurrency").ofType(typeLoader.load(Integer.class)).defaultingTo(Integer.MAX_VALUE).withExpressionSupport(NOT_SUPPORTED).describedAs("This value determines the maximum level of parallelism that will be used by this router.");
    scatterGather.onDefaultParameterGroup().withOptionalParameter(TARGET_PARAMETER_NAME).ofType(typeLoader.load(String.class)).withExpressionSupport(NOT_SUPPORTED).describedAs(TARGET_PARAMETER_DESCRIPTION).withLayout(LayoutModel.builder().tabName(ADVANCED_TAB).build());
    scatterGather.onDefaultParameterGroup().withOptionalParameter(TARGET_VALUE_PARAMETER_NAME).ofType(typeLoader.load(String.class)).defaultingTo(PAYLOAD).withExpressionSupport(REQUIRED).describedAs(TARGET_VALUE_PARAMETER_DESCRIPTION).withRole(BEHAVIOUR).withDisplayModel(DisplayModel.builder().displayName(TARGET_VALUE_PARAMETER_DISPLAY_NAME).build()).withLayout(LayoutModel.builder().tabName(ADVANCED_TAB).build()).withModelProperty(new TargetModelProperty());
// TODO MULE-13316 Define error model (Routers should be able to define error type(s) thrown in ModelDeclarer but
// ConstructModel doesn't support it.)
}
Also used : ConstructDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConstructDeclarer) TargetModelProperty(org.mule.runtime.extension.internal.property.TargetModelProperty)

Example 7 with ConstructDeclarer

use of org.mule.runtime.api.meta.model.declaration.fluent.ConstructDeclarer in project mule by mulesoft.

the class RouterModelLoaderDelegate method declareRouter.

void declareRouter(ExtensionDeclarer extensionDeclarer, HasOperationDeclarer ownerDeclarer, OperationContainerElement enclosingType, OperationElement routerMethod, Optional<ExtensionParameter> configParameter, Optional<ExtensionParameter> connectionParameter) {
    checkDefinition(!configParameter.isPresent(), format("Scope '%s' requires a config, but that is not allowed, remove such parameter", routerMethod.getName()));
    checkDefinition(!connectionParameter.isPresent(), format("Scope '%s' requires a connection, but that is not allowed, remove such parameter", routerMethod.getName()));
    HasConstructDeclarer actualDeclarer = (HasConstructDeclarer) loader.selectDeclarerBasedOnConfig(extensionDeclarer, (Declarer) ownerDeclarer, configParameter, connectionParameter);
    if (constructDeclarers.containsKey(routerMethod)) {
        actualDeclarer.withConstruct(constructDeclarers.get(routerMethod));
        return;
    }
    final ConstructDeclarer router = actualDeclarer.withConstruct(routerMethod.getAlias());
    router.withModelProperty(new ExtensionOperationDescriptorModelProperty(routerMethod));
    Optional<Method> method = routerMethod.getMethod();
    Optional<Class<?>> declaringClass = enclosingType.getDeclaringClass();
    if (method.isPresent() && declaringClass.isPresent()) {
        router.withModelProperty(new ImplementingMethodModelProperty(method.get())).withModelProperty(new ComponentExecutorModelProperty(new ReflectiveOperationExecutorFactory<>(declaringClass.get(), method.get())));
    }
    processMimeType(router, routerMethod);
    List<ExtensionParameter> callbackParameters = routerMethod.getParameters().stream().filter(p -> VALID_CALLBACK_PARAMETERS.stream().anyMatch(validType -> p.getType().isSameType(validType))).collect(toList());
    List<ExtensionParameter> routes = routerMethod.getParameters().stream().filter(this::isRoute).collect(toList());
    checkDefinition(!callbackParameters.isEmpty(), format("Router '%s' does not declare a parameter with one of the types '%s'. One is required.", routerMethod.getAlias(), VALID_CALLBACK_PARAMETERS));
    checkDefinition(!routes.isEmpty(), format("Router '%s' does not declare a '%s' parameter. One is required.", routerMethod.getAlias(), Route.class.getSimpleName()));
    checkDefinition(callbackParameters.size() <= 1, format("Router '%s' defines more than one CompletionCallback parameters. Only one is allowed", routerMethod.getAlias()));
    checkDefinition(isVoid(routerMethod), format("Router '%s' is not declared in a void method.", routerMethod.getAlias()));
    List<ExtensionParameter> nonRouteParameters = routerMethod.getParameters().stream().filter(p -> !isRoute(p) && !callbackParameters.contains(p)).collect(toList());
    declareParameters(router, nonRouteParameters, routerMethod.getEnclosingType().getParameters(), new ParameterDeclarationContext(CONSTRUCT, router.getDeclaration()));
    declareRoutes(router, routes);
}
Also used : OperationModelLoaderDelegate.checkDefinition(org.mule.runtime.module.extension.internal.loader.java.OperationModelLoaderDelegate.checkDefinition) FieldElement(org.mule.runtime.module.extension.api.loader.java.type.FieldElement) HashMap(java.util.HashMap) RouterCompletionCallback(org.mule.runtime.extension.api.runtime.process.RouterCompletionCallback) OperationElement(org.mule.runtime.module.extension.api.loader.java.type.OperationElement) ReflectiveOperationExecutorFactory(org.mule.runtime.module.extension.internal.runtime.execution.ReflectiveOperationExecutorFactory) MethodElement(org.mule.runtime.module.extension.api.loader.java.type.MethodElement) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) ConstructDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConstructDeclarer) VoidCompletionCallback(org.mule.runtime.extension.api.runtime.process.VoidCompletionCallback) Parameter(org.mule.runtime.extension.api.annotation.param.Parameter) Method(java.lang.reflect.Method) String.format(java.lang.String.format) HasConstructDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasConstructDeclarer) NestedRouteDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.NestedRouteDeclarer) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) ParameterDeclarationContext(org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext) IntrospectionUtils.isVoid(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.isVoid) ComponentExecutorModelProperty(org.mule.runtime.module.extension.api.loader.java.property.ComponentExecutorModelProperty) Route(org.mule.runtime.extension.api.runtime.route.Route) OperationContainerElement(org.mule.runtime.module.extension.api.loader.java.type.OperationContainerElement) Optional(java.util.Optional) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) ExtensionParameter(org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter) Declarer(org.mule.runtime.api.meta.model.declaration.fluent.Declarer) ImplementingTypeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingTypeModelProperty) ImplementingMethodModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingMethodModelProperty) ExtensionOperationDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionOperationDescriptorModelProperty) HasOperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer) ParameterDeclarationContext(org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext) ExtensionOperationDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionOperationDescriptorModelProperty) ExtensionParameter(org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter) ConstructDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConstructDeclarer) HasConstructDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasConstructDeclarer) ReflectiveOperationExecutorFactory(org.mule.runtime.module.extension.internal.runtime.execution.ReflectiveOperationExecutorFactory) Method(java.lang.reflect.Method) HasConstructDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasConstructDeclarer) ImplementingMethodModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingMethodModelProperty) ConstructDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConstructDeclarer) HasConstructDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasConstructDeclarer) NestedRouteDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.NestedRouteDeclarer) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) Declarer(org.mule.runtime.api.meta.model.declaration.fluent.Declarer) HasOperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer) ComponentExecutorModelProperty(org.mule.runtime.module.extension.api.loader.java.property.ComponentExecutorModelProperty)

Example 8 with ConstructDeclarer

use of org.mule.runtime.api.meta.model.declaration.fluent.ConstructDeclarer in project mule by mulesoft.

the class MuleExtensionModelDeclarer method declareTry.

private void declareTry(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) {
    ConstructDeclarer tryScope = extensionDeclarer.withConstruct("try").describedAs("Processes the nested list of message processors, " + "within a transaction and with it's own error handler if required.");
    tryScope.onDefaultParameterGroup().withOptionalParameter("transactionalAction").ofType(BaseTypeBuilder.create(JAVA).stringType().enumOf("INDIFFERENT", "ALWAYS_BEGIN", "BEGIN_OR_JOIN").build()).defaultingTo("INDIFFERENT").withExpressionSupport(NOT_SUPPORTED).withLayout(LayoutModel.builder().tabName("Transactions").build()).describedAs("The action to take regarding transactions. By default nothing will be done.");
    tryScope.onDefaultParameterGroup().withOptionalParameter("transactionType").ofType(BaseTypeBuilder.create(JAVA).stringType().enumOf("LOCAL", "XA").build()).defaultingTo("LOCAL").withExpressionSupport(NOT_SUPPORTED).describedAs("Transaction type supported. Availability will depend on the runtime version, " + "though LOCAL is always available.");
    tryScope.withChain();
    tryScope.withOptionalComponent("errorHandler").withAllowedStereotypes(ERROR_HANDLER);
}
Also used : ConstructDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConstructDeclarer)

Example 9 with ConstructDeclarer

use of org.mule.runtime.api.meta.model.declaration.fluent.ConstructDeclarer in project mule by mulesoft.

the class MuleExtensionModelDeclarer method declareSubflow.

private void declareSubflow(ExtensionDeclarer extensionDeclarer) {
    ConstructDeclarer flow = extensionDeclarer.withConstruct("subFlow").allowingTopLevelDefinition();
    flow.withChain().setRequired(true).withAllowedStereotypes(PROCESSOR);
}
Also used : ConstructDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConstructDeclarer)

Example 10 with ConstructDeclarer

use of org.mule.runtime.api.meta.model.declaration.fluent.ConstructDeclarer in project mule by mulesoft.

the class MuleExtensionModelDeclarer method declareAsync.

private void declareAsync(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) {
    ConstructDeclarer async = extensionDeclarer.withConstruct("async").describedAs("Processes the nested list of message processors asynchronously using a thread pool");
    async.withChain();
    async.onDefaultParameterGroup().withOptionalParameter("name").withExpressionSupport(NOT_SUPPORTED).ofType(typeLoader.load(String.class)).describedAs("Name that will be used to name the async scheduler");
    async.onDefaultParameterGroup().withOptionalParameter("maxConcurrency").describedAs("The maximum concurrency. This value determines the maximum level of parallelism that this async router can use to optimize for performance when processing messages.").ofType(typeLoader.load(Integer.class));
}
Also used : ConstructDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConstructDeclarer)

Aggregations

ConstructDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ConstructDeclarer)15 NestedRouteDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.NestedRouteDeclarer)3 TargetModelProperty (org.mule.runtime.extension.internal.property.TargetModelProperty)2 TypeToken (com.google.gson.reflect.TypeToken)1 String.format (java.lang.String.format)1 Method (java.lang.reflect.Method)1 Arrays.asList (java.util.Arrays.asList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors.toList (java.util.stream.Collectors.toList)1 Declarer (org.mule.runtime.api.meta.model.declaration.fluent.Declarer)1 ExtensionDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer)1 HasConstructDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.HasConstructDeclarer)1 HasOperationDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer)1 PathModel (org.mule.runtime.api.meta.model.display.PathModel)1 Parameter (org.mule.runtime.extension.api.annotation.param.Parameter)1 DynamicConfigExpirationTypeBuilder (org.mule.runtime.extension.api.declaration.type.DynamicConfigExpirationTypeBuilder)1 RouterCompletionCallback (org.mule.runtime.extension.api.runtime.process.RouterCompletionCallback)1