Lambdas for Remaining Modules JPA -> ZK

Polishing - PR Comments and Closeable Warnings

Eclipse emits bogus warnings with exceptions in lambdas.
Even though the lambda might run on another thread, elipse thinks it could
cause the context to not be closed.

SPR-14854: MessageChannel is now a @FunctionalInterface

* Additional Lambda polishing and some code style fixes
This commit is contained in:
Gary Russell
2016-10-28 12:07:06 -04:00
committed by Artem Bilan
parent 16be9fc47d
commit 67d6cd0c89
83 changed files with 870 additions and 1324 deletions

View File

@@ -118,18 +118,13 @@ public class MessageHandlerChain extends AbstractMessageProducingHandler impleme
if (i < this.handlers.size() - 1) { // not the last handler
Assert.isInstanceOf(MessageProducer.class, handler, "All handlers except for " +
"the last one in the chain must implement the MessageProducer interface.");
final MessageHandler nextHandler = this.handlers.get(i + 1);
final MessageChannel nextChannel = new MessageChannel() {
@Override
public boolean send(Message<?> message, long timeout) {
return this.send(message);
}
@Override
public boolean send(Message<?> message) {
nextHandler.handleMessage(message);
return true;
}
MessageHandler nextHandler = this.handlers.get(i + 1);
MessageChannel nextChannel = (message, timeout) -> {
nextHandler.handleMessage(message);
return true;
};
((MessageProducer) handler).setOutputChannel(nextChannel);
// If this 'handler' is a nested non-last &lt;chain&gt;, it is necessary
@@ -146,7 +141,7 @@ public class MessageHandlerChain extends AbstractMessageProducingHandler impleme
else {
Assert.isNull(getOutputChannel(),
"An output channel was provided, but the final handler in " +
"the chain does not implement the MessageProducer interface.");
"the chain does not implement the MessageProducer interface.");
}
}
}
@@ -239,16 +234,11 @@ public class MessageHandlerChain extends AbstractMessageProducingHandler impleme
}
@Override
public boolean send(Message<?> message) {
public boolean send(Message<?> message, long timeout) {
produceOutput(message, message);
return true;
}
@Override
public boolean send(Message<?> message, long timeout) {
return send(message);
}
}
}

View File

@@ -46,7 +46,6 @@ import org.springframework.integration.store.SimpleMessageStore;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.GenericMessage;
/**
@@ -94,33 +93,24 @@ public class AbstractCorrelatingMessageHandlerTests {
});
final List<Message<?>> outputMessages = new ArrayList<Message<?>>();
handler.setOutputChannel(new MessageChannel() {
handler.setOutputChannel((message, timeout) -> {
/*
* Executes when group 'bar' completes normally
*/
@Override
public boolean send(Message<?> message, long timeout) {
outputMessages.add(message);
// wake reaper
waitReapStartLatch.countDown();
try {
waitForSendLatch.await(10, TimeUnit.SECONDS);
// wait a little longer for reaper to grab groups
Thread.sleep(2000);
// simulate tx commit
groupStore.removeMessageGroup("bar");
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return true;
outputMessages.add(message);
// wake reaper
waitReapStartLatch.countDown();
try {
waitForSendLatch.await(10, TimeUnit.SECONDS);
// wait a little longer for reaper to grab groups
Thread.sleep(2000);
// simulate tx commit
groupStore.removeMessageGroup("bar");
}
@Override
public boolean send(Message<?> message) {
return this.send(message, 0);
catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return true;
});
handler.setReleaseStrategy(group -> group.size() == 2);
@@ -160,21 +150,12 @@ public class AbstractCorrelatingMessageHandlerTests {
AggregatingMessageHandler handler = new AggregatingMessageHandler(group -> group, groupStore);
final List<Message<?>> outputMessages = new ArrayList<Message<?>>();
handler.setOutputChannel(new MessageChannel() {
handler.setOutputChannel((message, timeout) -> {
/*
* Executes when group 'bar' completes normally
*/
@Override
public boolean send(Message<?> message, long timeout) {
outputMessages.add(message);
return true;
}
@Override
public boolean send(Message<?> message) {
return this.send(message, 0);
}
outputMessages.add(message);
return true;
});
handler.setReleaseStrategy(group -> group.size() == 1);
@@ -196,21 +177,12 @@ public class AbstractCorrelatingMessageHandlerTests {
AggregatingMessageHandler handler = new AggregatingMessageHandler(group -> group, groupStore);
final List<Message<?>> outputMessages = new ArrayList<Message<?>>();
handler.setOutputChannel(new MessageChannel() {
handler.setOutputChannel((message, timeout) -> {
/*
* Executes when group 'bar' completes normally
*/
@Override
public boolean send(Message<?> message, long timeout) {
outputMessages.add(message);
return true;
}
@Override
public boolean send(Message<?> message) {
return this.send(message, 0);
}
outputMessages.add(message);
return true;
});
handler.setReleaseStrategy(group -> group.size() == 1);