Skip to content

Optimize MessageTriggerAction for Java DSL #8595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ protected MessageChannel getCurrentMessageChannel() {
*/
protected InterceptableChannel currentInterceptableChannel() {
MessageChannel currentChannel = getCurrentMessageChannel();
if (currentChannel instanceof InterceptableChannel) {
return (InterceptableChannel) currentChannel;
if (currentChannel instanceof InterceptableChannel interceptableChannel) {
return interceptableChannel;
}
else {
DirectChannel newCurrentChannel = new DirectChannel();
Expand Down Expand Up @@ -1161,7 +1161,7 @@ public B bridge() {
* @see GenericEndpointSpec
*/
public B bridge(Consumer<GenericEndpointSpec<BridgeHandler>> endpointConfigurer) {
return register(new GenericEndpointSpec<>(new BridgeHandler()), endpointConfigurer);
return handle(new BridgeHandler(), endpointConfigurer);
}

/**
Expand Down Expand Up @@ -2836,7 +2836,9 @@ public B trigger(MessageTriggerAction triggerAction) {
public B trigger(MessageTriggerAction triggerAction,
Consumer<GenericEndpointSpec<ServiceActivatingHandler>> endpointConfigurer) {

return handle(new ServiceActivatingHandler(triggerAction, "trigger"), endpointConfigurer);
Consumer<Message<?>> trigger = triggerAction::trigger;
return handle(new ServiceActivatingHandler(new LambdaMessageProcessor(trigger, Message.class)),
endpointConfigurer);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2022 the original author or authors.
* Copyright 2016-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,6 +21,7 @@
import java.lang.reflect.Modifier;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;

import org.apache.commons.logging.Log;
Expand Down Expand Up @@ -98,7 +99,8 @@ public LambdaMessageProcessor(Object target, @Nullable Class<?> expectedType) {
}

private static boolean isExplicit(Object target) {
return target instanceof Function<?, ?> ||
return target instanceof Consumer<?> ||
target instanceof Function<?, ?> ||
target instanceof GenericHandler<?> ||
target instanceof GenericSelector<?> ||
target instanceof GenericTransformer<?, ?>;
Expand Down Expand Up @@ -189,7 +191,11 @@ else if (Map.class.isAssignableFrom(parameterType)) {

@SuppressWarnings({"unchecked", "rawtypes"})
private Object invokeMethod(Object[] args) throws InvocationTargetException, IllegalAccessException {
if (this.target instanceof Function function) {
if (this.target instanceof Consumer consumer) {
consumer.accept(args[0]);
return null;
}
else if (this.target instanceof Function function) {
return function.apply(args[0]);
}
else if (this.target instanceof GenericSelector selector) {
Expand Down