Fix more deprecations around TaskScheduler

This commit is contained in:
Artem Bilan
2022-07-11 11:41:38 -04:00
parent 4a55fa3188
commit f85423a436
9 changed files with 50 additions and 39 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@ import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.PosixFilePermission;
import java.time.Duration;
import java.util.BitSet;
import java.util.HashMap;
import java.util.Iterator;
@@ -450,7 +451,8 @@ public class FileWritingMessageHandler extends AbstractReplyProducingMessageHand
if (this.flushTask == null && FileExistsMode.APPEND_NO_FLUSH.equals(this.fileExistsMode)) {
TaskScheduler taskScheduler = getTaskScheduler();
Assert.state(taskScheduler != null, "'taskScheduler' is required for FileExistsMode.APPEND_NO_FLUSH");
this.flushTask = taskScheduler.scheduleAtFixedRate(new Flusher(), this.flushInterval / 3); // NOSONAR
this.flushTask = taskScheduler
.scheduleAtFixedRate(new Flusher(), Duration.ofMillis(this.flushInterval / 3)); // NOSONAR
}
}

View File

@@ -17,6 +17,8 @@
package org.springframework.integration.file.tail;
import java.io.File;
import java.io.Serial;
import java.time.Duration;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.atomic.AtomicLong;
@@ -37,6 +39,7 @@ import org.springframework.util.Assert;
* @author Artem Bilan
* @author Ali Shahbour
* @author Vladimir Plizga
*
* @since 3.0
*
*/
@@ -146,21 +149,21 @@ public abstract class FileTailingMessageProducerSupport extends MessageProducerS
}
}
@Override
protected void doStart() {
if (this.idleEventInterval > 0) {
this.idleEventScheduledFuture = getTaskScheduler().scheduleWithFixedDelay(() -> {
long now = System.currentTimeMillis();
long lastAlertAt = this.lastNoMessageAlert.get();
long lastSend = this.lastProduce;
if (now > lastSend + this.idleEventInterval
&& now > lastAlertAt + this.idleEventInterval
&& this.lastNoMessageAlert.compareAndSet(lastAlertAt, now)) {
publishIdleEvent(now - lastSend);
}
}, this.idleEventInterval);
this.idleEventScheduledFuture =
getTaskScheduler()
.scheduleWithFixedDelay(() -> {
long now = System.currentTimeMillis();
long lastAlertAt = this.lastNoMessageAlert.get();
long lastSend = this.lastProduce;
if (now > lastSend + this.idleEventInterval
&& now > lastAlertAt + this.idleEventInterval
&& this.lastNoMessageAlert.compareAndSet(lastAlertAt, now)) {
publishIdleEvent(now - lastSend);
}
}, Duration.ofMillis(this.idleEventInterval));
}
}
@@ -191,6 +194,7 @@ public abstract class FileTailingMessageProducerSupport extends MessageProducerS
public static class FileTailingIdleEvent extends FileTailingEvent {
@Serial
private static final long serialVersionUID = -967118535347976767L;
private final long idleTime;
@@ -210,6 +214,7 @@ public abstract class FileTailingMessageProducerSupport extends MessageProducerS
public static class FileTailingEvent extends FileIntegrationEvent {
@Serial
private static final long serialVersionUID = -3382255736225946206L;
private final String message;

View File

@@ -19,6 +19,7 @@ package org.springframework.integration.file.tail;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.time.Instant;
import java.util.Date;
import org.springframework.messaging.MessagingException;
@@ -165,9 +166,10 @@ public class OSDelegatingFileTailingMessageProducer extends FileTailingMessagePr
destroyProcess();
}
if (isRunning()) {
logger.info(() -> "Restarting tail process in " + getMissingFileDelay() + " milliseconds");
long missingFileDelay = getMissingFileDelay();
logger.info(() -> "Restarting tail process in " + missingFileDelay + " milliseconds");
getTaskScheduler()
.schedule(this::runExec, new Date(System.currentTimeMillis() + getMissingFileDelay()));
.schedule(this::runExec, Instant.now().plusMillis(missingFileDelay));
}
});
}