Use improved shutdown for receive command

This commit is contained in:
AsamK 2023-11-09 19:22:58 +01:00
parent 1058e33f12
commit 5d33f71d4d
4 changed files with 37 additions and 1 deletions

View file

@ -255,6 +255,8 @@ public interface Manager extends Closeable {
Optional<Duration> timeout, Optional<Integer> maxMessages, ReceiveMessageHandler handler
) throws IOException, AlreadyReceivingException;
void stopReceiveMessages();
void setReceiveConfig(ReceiveConfig receiveConfig);
boolean isContactBlocked(RecipientIdentifier.Single recipient);

View file

@ -1091,6 +1091,20 @@ public class ManagerImpl implements Manager {
receiveMessages(timeout.orElse(Duration.ofMinutes(1)), timeout.isPresent(), maxMessages.orElse(null), handler);
}
@Override
public void stopReceiveMessages() {
Thread thread = null;
synchronized (messageHandlers) {
if (isReceivingSynchronous) {
thread = receiveThread;
receiveThread = null;
}
}
if (thread != null) {
stopReceiveThread(thread);
}
}
private void receiveMessages(
Duration timeout, boolean returnOnTimeout, Integer maxMessages, ReceiveMessageHandler handler
) throws IOException, AlreadyReceivingException {