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.)
}
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);
}
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);
}
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);
}
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));
}
Aggregations