Split receiveMessages method

This commit is contained in:
AsamK 2021-10-21 21:19:14 +02:00
parent 430c155f7e
commit 5c389c875d
6 changed files with 32 additions and 15 deletions

View file

@ -23,7 +23,6 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
public class DaemonCommand implements MultiLocalCommand {
@ -135,7 +134,7 @@ public class DaemonCommand implements MultiLocalCommand {
final var receiveMessageHandler = outputWriter instanceof JsonWriter
? new JsonDbusReceiveMessageHandler(m, (JsonWriter) outputWriter, conn, objectPath)
: new DbusReceiveMessageHandler(m, (PlainTextWriter) outputWriter, conn, objectPath);
m.receiveMessages(1, TimeUnit.HOURS, false, receiveMessageHandler);
m.receiveMessages(receiveMessageHandler);
break;
} catch (IOException e) {
logger.warn("Receiving messages failed, retrying", e);

View file

@ -33,7 +33,6 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
public class JsonRpcDispatcherCommand implements LocalCommand {
@ -173,7 +172,7 @@ public class JsonRpcDispatcherCommand implements LocalCommand {
while (!Thread.interrupted()) {
try {
final var receiveMessageHandler = new JsonReceiveMessageHandler(m, jsonWriter);
m.receiveMessages(1, TimeUnit.HOURS, false, receiveMessageHandler);
m.receiveMessages(receiveMessageHandler);
break;
} catch (IOException e) {
logger.warn("Receiving messages failed, retrying", e);

View file

@ -142,17 +142,16 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
final Namespace ns, final Manager m, final OutputWriter outputWriter
) throws CommandException {
double timeout = ns.getDouble("timeout");
var returnOnTimeout = true;
if (timeout < 0) {
returnOnTimeout = false;
timeout = 3600;
}
boolean ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
m.setIgnoreAttachments(ignoreAttachments);
try {
final var handler = outputWriter instanceof JsonWriter ? new JsonReceiveMessageHandler(m,
(JsonWriter) outputWriter) : new ReceiveMessageHandler(m, (PlainTextWriter) outputWriter);
m.receiveMessages((long) (timeout * 1000), TimeUnit.MILLISECONDS, returnOnTimeout, handler);
if (timeout < 0) {
m.receiveMessages(handler);
} else {
m.receiveMessages((long) (timeout * 1000), TimeUnit.MILLISECONDS, handler);
}
} catch (IOException e) {
throw new IOErrorException("Error while receiving messages: " + e.getMessage(), e);
}

View file

@ -423,9 +423,14 @@ public class DbusManagerImpl implements Manager {
signal.sendSyncRequest();
}
@Override
public void receiveMessages(final ReceiveMessageHandler handler) throws IOException {
throw new UnsupportedOperationException();
}
@Override
public void receiveMessages(
final long timeout, final TimeUnit unit, final boolean returnOnTimeout, final ReceiveMessageHandler handler
final long timeout, final TimeUnit unit, final ReceiveMessageHandler handler
) throws IOException {
throw new UnsupportedOperationException();
}