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