import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.SignatureException;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
logger.debug("Starting receiving messages");
while (!Thread.interrupted()) {
try {
- receiveMessagesInternal(1L, TimeUnit.HOURS, false, (envelope, e) -> {
+ receiveMessagesInternal(Duration.ofMinutes(1), false, (envelope, e) -> {
synchronized (messageHandlers) {
Stream.concat(messageHandlers.stream(), weakHandlers.stream()).forEach(h -> {
try {
}
@Override
- public void receiveMessages(long timeout, TimeUnit unit, ReceiveMessageHandler handler) throws IOException {
- receiveMessages(timeout, unit, true, handler);
+ public void receiveMessages(Duration timeout, ReceiveMessageHandler handler) throws IOException {
+ receiveMessages(timeout, true, handler);
}
@Override
public void receiveMessages(ReceiveMessageHandler handler) throws IOException {
- receiveMessages(1L, TimeUnit.HOURS, false, handler);
+ receiveMessages(Duration.ofMinutes(1), false, handler);
}
private void receiveMessages(
- long timeout, TimeUnit unit, boolean returnOnTimeout, ReceiveMessageHandler handler
+ Duration timeout, boolean returnOnTimeout, ReceiveMessageHandler handler
) throws IOException {
if (isReceiving()) {
throw new IllegalStateException("Already receiving message.");
isReceivingSynchronous = true;
receiveThread = Thread.currentThread();
try {
- receiveMessagesInternal(timeout, unit, returnOnTimeout, handler);
+ receiveMessagesInternal(timeout, returnOnTimeout, handler);
} finally {
receiveThread = null;
hasCaughtUpWithOldMessages = false;
}
private void receiveMessagesInternal(
- long timeout, TimeUnit unit, boolean returnOnTimeout, ReceiveMessageHandler handler
+ Duration timeout, boolean returnOnTimeout, ReceiveMessageHandler handler
) throws IOException {
retryFailedReceivedMessages(handler);
}
logger.debug("Checking for new message from server");
try {
- var result = signalWebSocket.readOrEmpty(unit.toMillis(timeout), envelope1 -> {
+ var result = signalWebSocket.readOrEmpty(timeout.toMillis(), envelope1 -> {
final var recipientId = envelope1.hasSourceUuid()
? resolveRecipient(envelope1.getSourceAddress())
: null;
import org.slf4j.LoggerFactory;
import java.io.IOException;
+import java.time.Duration;
import java.util.List;
-import java.util.concurrent.TimeUnit;
public class ReceiveCommand implements LocalCommand {
if (timeout < 0) {
m.receiveMessages(handler);
} else {
- m.receiveMessages((long) (timeout * 1000), TimeUnit.MILLISECONDS, handler);
+ m.receiveMessages(Duration.ofMillis((long) (timeout * 1000)), handler);
}
} catch (IOException e) {
throw new IOErrorException("Error while receiving messages: " + e.getMessage(), e);
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
-import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
@Override
public void receiveMessages(
- final long timeout, final TimeUnit unit, final ReceiveMessageHandler handler
+ final Duration timeout, final ReceiveMessageHandler handler
) throws IOException {
addReceiveHandler(handler);
try {
- Thread.sleep(unit.toMillis(timeout));
+ Thread.sleep(timeout.toMillis());
} catch (InterruptedException ignored) {
}
removeReceiveHandler(handler);