Additional DSL LambdaMessageProcesses Fixes

Fix CheckStyle violations and one more `isLambda()`` in the `RecipientListRouterSpec`

Add `Assert` for method ambiguity to the `LambdaMessageProcessor` to be sure that we get deal only with the Function Interface impl
This commit is contained in:
Artem Bilan
2016-11-28 17:23:30 -05:00
committed by Gary Russell
parent 092d876fae
commit d9e1584a80
2 changed files with 20 additions and 11 deletions

View File

@@ -102,9 +102,10 @@ public class RecipientListRouterSpec extends AbstractRouterSpec<RecipientListRou
messageSelector = (MessageSelector) selector;
}
else {
messageSelector = isLambda(selector)
? new MethodInvokingSelector(new LambdaMessageProcessor(selector, null))
: new MethodInvokingSelector(selector);
messageSelector =
isLambda(selector)
? new MethodInvokingSelector(new LambdaMessageProcessor(selector, null))
: new MethodInvokingSelector(selector);
}
this.target.addRecipient(channelName, messageSelector);
return _this();
@@ -170,7 +171,10 @@ public class RecipientListRouterSpec extends AbstractRouterSpec<RecipientListRou
messageSelector = (MessageSelector) selector;
}
else {
messageSelector = new MethodInvokingSelector(new LambdaMessageProcessor(selector, null));
messageSelector =
isLambda(selector)
? new MethodInvokingSelector(new LambdaMessageProcessor(selector, null))
: new MethodInvokingSelector(selector);
}
this.target.addRecipient(channel, messageSelector);
return _this();

View File

@@ -60,18 +60,23 @@ public class LambdaMessageProcessor implements MessageProcessor<Object>, BeanFac
final AtomicReference<Method> methodValue = new AtomicReference<>();
ReflectionUtils.doWithMethods(target.getClass(),
methodValue::set,
methodCandidate ->
!methodCandidate.isBridge()
&& !methodCandidate.isDefault()
&& methodCandidate.getDeclaringClass() != Object.class
&& Modifier.isPublic(methodCandidate.getModifiers())
&& !Modifier.isStatic(methodCandidate.getModifiers()));
methodCandidate -> {
boolean isCandidate = !methodCandidate.isBridge()
&& !methodCandidate.isDefault()
&& methodCandidate.getDeclaringClass() != Object.class
&& Modifier.isPublic(methodCandidate.getModifiers())
&& !Modifier.isStatic(methodCandidate.getModifiers());
if (isCandidate) {
Assert.isNull(methodValue.get(), "LambdaMessageProcessor is applicable for inline or lambda " +
"classes with single method - functional interface implementations.");
}
return isCandidate;
});
Assert.notNull(methodValue.get(), "LambdaMessageProcessor is applicable for inline or lambda " +
"classes with single method - functional interface implementations.");
this.method = methodValue.get();
this.method.setAccessible(true);
this.parameterTypes = this.method.getParameterTypes();
this.payloadType = payloadType != null ? TypeDescriptor.valueOf(payloadType) : null;
}