Search in sources :

Example 6 with Result

use of org.mule.runtime.extension.api.runtime.operation.Result in project mule by mulesoft.

the class DEARadioSource method makeResult.

private Result<List<Result<String, DEAOfficerAttributes>>, Object> makeResult() {
    List<Result<String, DEAOfficerAttributes>> messages = new ArrayList<>(MESSAGES_PER_POLL);
    for (int i = 0; i < MESSAGES_PER_POLL; i++) {
        boolean isHank = random.nextInt() % 2 == 0;
        messages.add(Result.<String, DEAOfficerAttributes>builder().output(MESSAGE_TEXT).attributes(new DEAOfficerAttributes(isHank)).build());
    }
    return Result.<List<Result<String, DEAOfficerAttributes>>, Object>builder().output(messages).build();
}
Also used : DEAOfficerAttributes(org.mule.test.heisenberg.extension.model.types.DEAOfficerAttributes) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Result(org.mule.runtime.extension.api.runtime.operation.Result)

Example 7 with Result

use of org.mule.runtime.extension.api.runtime.operation.Result in project mule by mulesoft.

the class HeisenbergOperations method getEnemy.

@MediaType(TEXT_PLAIN)
public Result<String, IntegerAttributes> getEnemy(@Config HeisenbergExtension config, @Optional(defaultValue = "0") int index) {
    Charset lastSupportedEncoding = Charset.availableCharsets().values().stream().reduce((first, last) -> last).get();
    org.mule.runtime.api.metadata.DataType dt = DataType.builder().type(String.class).mediaType("dead/dead").charset(lastSupportedEncoding.toString()).build();
    return Result.<String, IntegerAttributes>builder().output(config.getEnemies().get(index)).mediaType(dt.getMediaType()).attributes(new IntegerAttributes(index)).build();
}
Also used : TEXT_PLAIN(org.mule.runtime.extension.api.annotation.param.MediaType.TEXT_PLAIN) KillingStereotype(org.mule.test.heisenberg.extension.stereotypes.KillingStereotype) ByteArrayInputStream(java.io.ByteArrayInputStream) BarberPreferences(org.mule.test.heisenberg.extension.model.BarberPreferences) KNOCKING_DOOR(org.mule.test.heisenberg.extension.HeisenbergNotificationAction.KNOCKING_DOOR) Map(java.util.Map) DisplayName(org.mule.runtime.extension.api.annotation.param.display.DisplayName) OnException(org.mule.runtime.extension.api.annotation.OnException) HEISENBERG(org.mule.test.heisenberg.extension.HeisenbergExtension.HEISENBERG) OperationParameters(org.mule.runtime.extension.api.client.OperationParameters) HealthException(org.mule.test.heisenberg.extension.exception.HealthException) Execution(org.mule.runtime.extension.api.annotation.execution.Execution) Weapon(org.mule.test.heisenberg.extension.model.Weapon) ObjectStore(org.mule.runtime.api.store.ObjectStore) HeisenbergException(org.mule.test.heisenberg.extension.exception.HeisenbergException) ImmutableMap(com.google.common.collect.ImmutableMap) Connection(org.mule.runtime.extension.api.annotation.param.Connection) EmpireStereotype(org.mule.test.heisenberg.extension.stereotypes.EmpireStereotype) String.format(java.lang.String.format) KillParameters(org.mule.test.heisenberg.extension.model.KillParameters) OutputResolver(org.mule.runtime.extension.api.annotation.metadata.OutputResolver) List(java.util.List) ParameterResolver(org.mule.runtime.extension.api.runtime.parameter.ParameterResolver) SimpleKnockeableDoor(org.mule.test.heisenberg.extension.model.SimpleKnockeableDoor) ExtensionsClient(org.mule.runtime.extension.api.client.ExtensionsClient) Entry(java.util.Map.Entry) Summary(org.mule.runtime.extension.api.annotation.param.display.Summary) PersonalInfo(org.mule.test.heisenberg.extension.model.PersonalInfo) Alias(org.mule.runtime.extension.api.annotation.Alias) DefaultOperationParametersBuilder(org.mule.runtime.extension.api.client.DefaultOperationParametersBuilder) CureCancerExceptionEnricher(org.mule.test.heisenberg.extension.exception.CureCancerExceptionEnricher) CPU_INTENSIVE(org.mule.runtime.api.meta.model.operation.ExecutionType.CPU_INTENSIVE) KNOCKED_DOOR(org.mule.test.heisenberg.extension.HeisenbergNotificationAction.KNOCKED_DOOR) Ignore(org.mule.runtime.extension.api.annotation.Ignore) Config(org.mule.runtime.extension.api.annotation.param.Config) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Charset(java.nio.charset.Charset) MuleException(org.mule.runtime.api.exception.MuleException) PAYLOAD(org.mule.runtime.extension.api.annotation.param.Optional.PAYLOAD) Literal(org.mule.runtime.extension.api.runtime.parameter.Literal) Content(org.mule.runtime.extension.api.annotation.param.Content) NullExceptionEnricher(org.mule.test.heisenberg.extension.exception.NullExceptionEnricher) IOUtils(org.mule.runtime.core.api.util.IOUtils) Optional(org.mule.runtime.extension.api.annotation.param.Optional) ParameterGroup(org.mule.runtime.extension.api.annotation.param.ParameterGroup) Disposable(org.mule.runtime.api.lifecycle.Disposable) Stereotype(org.mule.runtime.extension.api.annotation.param.stereotype.Stereotype) KnockeableDoor(org.mule.test.heisenberg.extension.model.KnockeableDoor) NotificationEmitter(org.mule.runtime.extension.api.notification.NotificationEmitter) SaleInfo(org.mule.test.heisenberg.extension.model.SaleInfo) DataType(org.mule.runtime.api.metadata.DataType) Throws(org.mule.runtime.extension.api.annotation.error.Throws) Investment(org.mule.test.heisenberg.extension.model.Investment) RecursivePojo(org.mule.test.heisenberg.extension.model.RecursivePojo) Example(org.mule.runtime.extension.api.annotation.param.display.Example) Result(org.mule.runtime.extension.api.runtime.operation.Result) DefaultOperationParameters.builder(org.mule.runtime.extension.api.client.DefaultOperationParameters.builder) TypedValue.of(org.mule.runtime.api.metadata.TypedValue.of) TypedValue(org.mule.runtime.api.metadata.TypedValue) RecursiveChainB(org.mule.test.heisenberg.extension.model.RecursiveChainB) Collectors.toList(java.util.stream.Collectors.toList) RecursiveChainA(org.mule.test.heisenberg.extension.model.RecursiveChainA) Streaming(org.mule.runtime.extension.api.annotation.Streaming) ExtensionManager(org.mule.runtime.core.api.extension.ExtensionManager) MediaType(org.mule.runtime.extension.api.annotation.param.MediaType) Fires(org.mule.runtime.extension.api.annotation.notification.Fires) HealthStatus(org.mule.test.heisenberg.extension.model.HealthStatus) IntegerAttributes(org.mule.test.heisenberg.extension.model.types.IntegerAttributes) ANY(org.mule.runtime.extension.api.annotation.param.MediaType.ANY) InputStream(java.io.InputStream) DataType(org.mule.runtime.api.metadata.DataType) Charset(java.nio.charset.Charset) IntegerAttributes(org.mule.test.heisenberg.extension.model.types.IntegerAttributes) MediaType(org.mule.runtime.extension.api.annotation.param.MediaType)

Example 8 with Result

use of org.mule.runtime.extension.api.runtime.operation.Result in project mule by mulesoft.

the class HeisenbergRouters method concurrentRouteExecutor.

public void concurrentRouteExecutor(WhenRoute when, RouterCompletionCallback callback) {
    Consumer<Chain> processor = (chain) -> {
        final Latch latch = new Latch();
        chain.process((result -> latch.release()), (error, result) -> latch.release());
        try {
            latch.await(10000, MILLISECONDS);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    };
    Thread first = new Thread(() -> processor.accept(when.getChain()));
    Thread second = new Thread(() -> processor.accept(when.getChain()));
    first.start();
    second.start();
    try {
        first.join();
        second.join();
    } catch (Exception e) {
        callback.error(e);
    }
    callback.success(Result.builder().output("SUCCESS").build());
}
Also used : Summary(org.mule.runtime.extension.api.annotation.param.display.Summary) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) Attribute(org.mule.test.heisenberg.extension.model.Attribute) Preconditions.checkArgument(org.mule.runtime.api.util.Preconditions.checkArgument) OtherwiseRoute(org.mule.test.heisenberg.extension.route.OtherwiseRoute) RouterCompletionCallback(org.mule.runtime.extension.api.runtime.process.RouterCompletionCallback) DrugKillingRoute(org.mule.test.heisenberg.extension.route.DrugKillingRoute) AfterCall(org.mule.test.heisenberg.extension.route.AfterCall) Collectors.toMap(java.util.stream.Collectors.toMap) MuleException(org.mule.runtime.api.exception.MuleException) BeforeCall(org.mule.test.heisenberg.extension.route.BeforeCall) Map(java.util.Map) Chain(org.mule.runtime.extension.api.runtime.route.Chain) VoidCompletionCallback(org.mule.runtime.extension.api.runtime.process.VoidCompletionCallback) Optional(org.mule.runtime.extension.api.annotation.param.Optional) Parameter(org.mule.runtime.extension.api.annotation.param.Parameter) Disposable(org.mule.runtime.api.lifecycle.Disposable) Startable(org.mule.runtime.api.lifecycle.Startable) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Initialisable(org.mule.runtime.api.lifecycle.Initialisable) Result(org.mule.runtime.extension.api.runtime.operation.Result) Consumer(java.util.function.Consumer) Latch(org.mule.runtime.api.util.concurrent.Latch) List(java.util.List) WhenRoute(org.mule.test.heisenberg.extension.route.WhenRoute) Stoppable(org.mule.runtime.api.lifecycle.Stoppable) NullSafe(org.mule.runtime.extension.api.annotation.param.NullSafe) KillingRoute(org.mule.test.heisenberg.extension.route.KillingRoute) NOT_SUPPORTED(org.mule.runtime.api.meta.ExpressionSupport.NOT_SUPPORTED) Expression(org.mule.runtime.extension.api.annotation.Expression) Chain(org.mule.runtime.extension.api.runtime.route.Chain) Latch(org.mule.runtime.api.util.concurrent.Latch) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleException(org.mule.runtime.api.exception.MuleException)

Example 9 with Result

use of org.mule.runtime.extension.api.runtime.operation.Result in project mule by mulesoft.

the class AbstractReturnDelegate method toMessage.

protected Message toMessage(Object value, ExecutionContextAdapter operationContext) {
    final MediaType mediaType = resolveMediaType(value, operationContext);
    final CoreEvent event = operationContext.getEvent();
    if (value instanceof Result) {
        Result resultValue = (Result) value;
        return isSpecialHandling && returnHandler.handles(resultValue.getOutput()) ? MessageUtils.toMessage((Result) value, mediaType, cursorProviderFactory, event, returnHandler.getDataType()) : MessageUtils.toMessage((Result) value, mediaType, cursorProviderFactory, event);
    } else {
        if (value instanceof Collection && returnsListOfMessages) {
            value = toMessageCollection((Collection<Result>) value, cursorProviderFactory, event);
        } else if (value instanceof Iterator && returnsListOfMessages) {
            value = toMessageIterator((Iterator<Result>) value, cursorProviderFactory, event);
        }
        value = streamingContent(value, cursorProviderFactory, event);
        Message.Builder messageBuilder;
        // org.mule.runtime.api.metadata.DataType.MULE_MESSAGE_COLLECTION doesn't completely makes sense
        if (returnsListOfMessages && value instanceof Collection) {
            messageBuilder = Message.builder().collectionValue((Collection) value, Message.class);
        } else if (isSpecialHandling && returnHandler.handles(value)) {
            messageBuilder = returnHandler.toMessageBuilder(value);
        } else {
            messageBuilder = Message.builder().value(value);
        }
        return messageBuilder.mediaType(mediaType).build();
    }
}
Also used : Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Iterator(java.util.Iterator) MessageUtils.toMessageIterator(org.mule.runtime.core.internal.util.message.MessageUtils.toMessageIterator) MediaType(org.mule.runtime.api.metadata.MediaType) MessageUtils.toMessageCollection(org.mule.runtime.core.internal.util.message.MessageUtils.toMessageCollection) Collection(java.util.Collection) ExtensionMetadataTypeUtils.isJavaCollection(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.isJavaCollection) Result(org.mule.runtime.extension.api.runtime.operation.Result)

Example 10 with Result

use of org.mule.runtime.extension.api.runtime.operation.Result in project mule by mulesoft.

the class OperationReturnTypeModelValidatorTestCase method resultListWithoutGenerics.

@Test(expected = IllegalModelDefinitionException.class)
public void resultListWithoutGenerics() {
    when(methodElement.getReturnType()).thenReturn(new TypeWrapper(forType(new TypeToken<List<Result>>() {
    }.getType()), typeLoader));
    validate(extensionModel, validator);
}
Also used : TypeWrapper(org.mule.runtime.module.extension.internal.loader.java.type.runtime.TypeWrapper) TypeToken(com.google.common.reflect.TypeToken) Result(org.mule.runtime.extension.api.runtime.operation.Result) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

Result (org.mule.runtime.extension.api.runtime.operation.Result)10 List (java.util.List)6 TypeToken (com.google.common.reflect.TypeToken)3 Map (java.util.Map)3 InputStream (java.io.InputStream)2 Charset (java.nio.charset.Charset)2 ArrayList (java.util.ArrayList)2 Arrays.asList (java.util.Arrays.asList)2 Collectors.toMap (java.util.stream.Collectors.toMap)2 MuleException (org.mule.runtime.api.exception.MuleException)2 Disposable (org.mule.runtime.api.lifecycle.Disposable)2 OutputModel (org.mule.runtime.api.meta.model.OutputModel)2 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)2 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)2 TypedValue (org.mule.runtime.api.metadata.TypedValue)2 Optional (org.mule.runtime.extension.api.annotation.param.Optional)2 Summary (org.mule.runtime.extension.api.annotation.param.display.Summary)2 DefaultOperationParameters.builder (org.mule.runtime.extension.api.client.DefaultOperationParameters.builder)2 DefaultOperationParametersBuilder (org.mule.runtime.extension.api.client.DefaultOperationParametersBuilder)2 ExtensionsClient (org.mule.runtime.extension.api.client.ExtensionsClient)2