mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Use improved shutdown for receive command
This commit is contained in:
parent
1058e33f12
commit
5d33f71d4d
4 changed files with 37 additions and 1 deletions
|
@ -3,6 +3,7 @@ package org.asamk.signal.dbus;
|
|||
import org.asamk.Signal;
|
||||
import org.asamk.signal.DbusConfig;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.api.AlreadyReceivingException;
|
||||
import org.asamk.signal.manager.api.AttachmentInvalidException;
|
||||
import org.asamk.signal.manager.api.CaptchaRequiredException;
|
||||
import org.asamk.signal.manager.api.Configuration;
|
||||
|
@ -548,10 +549,17 @@ public class DbusManagerImpl implements Manager {
|
|||
}
|
||||
}
|
||||
|
||||
private Thread receiveThread;
|
||||
|
||||
@Override
|
||||
public void receiveMessages(
|
||||
Optional<Duration> timeout, Optional<Integer> maxMessages, ReceiveMessageHandler handler
|
||||
) throws IOException {
|
||||
) throws IOException, AlreadyReceivingException {
|
||||
if (receiveThread != null) {
|
||||
throw new AlreadyReceivingException("Already receiving message.");
|
||||
}
|
||||
receiveThread = Thread.currentThread();
|
||||
|
||||
final var remainingMessages = new AtomicInteger(maxMessages.orElse(-1));
|
||||
final var lastMessage = new AtomicLong(System.currentTimeMillis());
|
||||
final var thread = Thread.currentThread();
|
||||
|
@ -577,6 +585,7 @@ public class DbusManagerImpl implements Manager {
|
|||
}
|
||||
Thread.sleep(sleepTimeRemaining);
|
||||
} catch (InterruptedException ignored) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -589,6 +598,14 @@ public class DbusManagerImpl implements Manager {
|
|||
}
|
||||
|
||||
removeReceiveHandler(receiveHandler);
|
||||
receiveThread = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopReceiveMessages() {
|
||||
if (receiveThread != null) {
|
||||
receiveThread.interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue