Skip to content

Commit f85423a

Browse files
committed
Fix more deprecations around TaskScheduler
1 parent 4a55fa3 commit f85423a

File tree

9 files changed

+50
-39
lines changed

9 files changed

+50
-39
lines changed

spring-integration-core/src/main/java/org/springframework/integration/channel/DefaultHeaderChannelRegistry.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.integration.channel;
1818

1919
import java.time.Instant;
20-
import java.util.Date;
2120
import java.util.Iterator;
2221
import java.util.Map;
2322
import java.util.Map.Entry;
@@ -224,7 +223,7 @@ public synchronized void run() {
224223
}
225224
this.reaperScheduledFuture =
226225
getTaskScheduler()
227-
.schedule(this, new Date(System.currentTimeMillis() + this.reaperDelay));
226+
.schedule(this, Instant.now().plusMillis(this.reaperDelay));
228227

229228
logger.trace(() -> "Reaper completed; channels size=" + this.channels.size());
230229
}

spring-integration-core/src/main/java/org/springframework/integration/handler/DelayHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
* concurrently, even very long delays, without producing a buildup of blocked Threads.
6969
* <p>
7070
* One thing to keep in mind, however, is that any active transactional context will not
71-
* propagate from the original sender to the eventual recipient. This is a side-effect of
71+
* propagate from the original sender to the eventual recipient. This is a side effect of
7272
* passing the Message to the output channel after the delay with a different Thread in
7373
* control.
7474
* <p>
@@ -532,7 +532,7 @@ private void rescheduleNow(final Message<?> message) {
532532

533533
protected void rescheduleAt(Message<?> message, Date startTime) {
534534
Runnable releaseTask = releaseTaskForMessage(message);
535-
getTaskScheduler().schedule(releaseTask, startTime);
535+
getTaskScheduler().schedule(releaseTask, startTime.toInstant());
536536
}
537537

538538
private void doReleaseMessage(Message<?> message) {
@@ -594,7 +594,7 @@ public synchronized void reschedulePersistedMessages() {
594594
else {
595595
releaseMessage(message);
596596
}
597-
}, new Date()));
597+
}, Instant.now()));
598598
}
599599
}
600600

spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@
3131
import java.nio.file.Files;
3232
import java.nio.file.StandardCopyOption;
3333
import java.nio.file.attribute.PosixFilePermission;
34+
import java.time.Duration;
3435
import java.util.BitSet;
3536
import java.util.HashMap;
3637
import java.util.Iterator;
@@ -450,7 +451,8 @@ public void start() {
450451
if (this.flushTask == null && FileExistsMode.APPEND_NO_FLUSH.equals(this.fileExistsMode)) {
451452
TaskScheduler taskScheduler = getTaskScheduler();
452453
Assert.state(taskScheduler != null, "'taskScheduler' is required for FileExistsMode.APPEND_NO_FLUSH");
453-
this.flushTask = taskScheduler.scheduleAtFixedRate(new Flusher(), this.flushInterval / 3); // NOSONAR
454+
this.flushTask = taskScheduler
455+
.scheduleAtFixedRate(new Flusher(), Duration.ofMillis(this.flushInterval / 3)); // NOSONAR
454456
}
455457
}
456458

spring-integration-file/src/main/java/org/springframework/integration/file/tail/FileTailingMessageProducerSupport.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package org.springframework.integration.file.tail;
1818

1919
import java.io.File;
20+
import java.io.Serial;
21+
import java.time.Duration;
2022
import java.util.concurrent.ScheduledFuture;
2123
import java.util.concurrent.atomic.AtomicLong;
2224

@@ -37,6 +39,7 @@
3739
* @author Artem Bilan
3840
* @author Ali Shahbour
3941
* @author Vladimir Plizga
42+
*
4043
* @since 3.0
4144
*
4245
*/
@@ -146,21 +149,21 @@ protected void publish(String message) {
146149
}
147150
}
148151

149-
150-
151152
@Override
152153
protected void doStart() {
153154
if (this.idleEventInterval > 0) {
154-
this.idleEventScheduledFuture = getTaskScheduler().scheduleWithFixedDelay(() -> {
155-
long now = System.currentTimeMillis();
156-
long lastAlertAt = this.lastNoMessageAlert.get();
157-
long lastSend = this.lastProduce;
158-
if (now > lastSend + this.idleEventInterval
159-
&& now > lastAlertAt + this.idleEventInterval
160-
&& this.lastNoMessageAlert.compareAndSet(lastAlertAt, now)) {
161-
publishIdleEvent(now - lastSend);
162-
}
163-
}, this.idleEventInterval);
155+
this.idleEventScheduledFuture =
156+
getTaskScheduler()
157+
.scheduleWithFixedDelay(() -> {
158+
long now = System.currentTimeMillis();
159+
long lastAlertAt = this.lastNoMessageAlert.get();
160+
long lastSend = this.lastProduce;
161+
if (now > lastSend + this.idleEventInterval
162+
&& now > lastAlertAt + this.idleEventInterval
163+
&& this.lastNoMessageAlert.compareAndSet(lastAlertAt, now)) {
164+
publishIdleEvent(now - lastSend);
165+
}
166+
}, Duration.ofMillis(this.idleEventInterval));
164167
}
165168
}
166169

@@ -191,6 +194,7 @@ private void updateLastProduce() {
191194

192195
public static class FileTailingIdleEvent extends FileTailingEvent {
193196

197+
@Serial
194198
private static final long serialVersionUID = -967118535347976767L;
195199

196200
private final long idleTime;
@@ -210,6 +214,7 @@ public String toString() {
210214

211215
public static class FileTailingEvent extends FileIntegrationEvent {
212216

217+
@Serial
213218
private static final long serialVersionUID = -3382255736225946206L;
214219

215220
private final String message;

spring-integration-file/src/main/java/org/springframework/integration/file/tail/OSDelegatingFileTailingMessageProducer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.BufferedReader;
2020
import java.io.IOException;
2121
import java.io.InputStreamReader;
22+
import java.time.Instant;
2223
import java.util.Date;
2324

2425
import org.springframework.messaging.MessagingException;
@@ -165,9 +166,10 @@ private void startProcessMonitor() {
165166
destroyProcess();
166167
}
167168
if (isRunning()) {
168-
logger.info(() -> "Restarting tail process in " + getMissingFileDelay() + " milliseconds");
169+
long missingFileDelay = getMissingFileDelay();
170+
logger.info(() -> "Restarting tail process in " + missingFileDelay + " milliseconds");
169171
getTaskScheduler()
170-
.schedule(this::runExec, new Date(System.currentTimeMillis() + getMissingFileDelay()));
172+
.schedule(this::runExec, Instant.now().plusMillis(missingFileDelay));
171173
}
172174
});
173175
}

spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/TcpOutboundGateway.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2001-2021 the original author or authors.
2+
* Copyright 2001-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@
1717
package org.springframework.integration.ip.tcp;
1818

1919
import java.io.IOException;
20-
import java.util.Date;
20+
import java.time.Instant;
2121
import java.util.Map;
2222
import java.util.concurrent.ConcurrentHashMap;
2323
import java.util.concurrent.CountDownLatch;
@@ -440,11 +440,12 @@ private final class AsyncReply {
440440
this.connection = connection;
441441
this.haveSemaphore = haveSemaphore;
442442
if (async && remoteTimeout > 0) {
443-
getTaskScheduler().schedule(() -> {
444-
TcpOutboundGateway.this.pendingReplies.remove(connection.getConnectionId());
445-
this.future.setException(
446-
new MessageTimeoutException(requestMessage, "Timed out waiting for response"));
447-
}, new Date(System.currentTimeMillis() + remoteTimeout));
443+
getTaskScheduler()
444+
.schedule(() -> {
445+
TcpOutboundGateway.this.pendingReplies.remove(connection.getConnectionId());
446+
this.future.setException(
447+
new MessageTimeoutException(requestMessage, "Timed out waiting for response"));
448+
}, Instant.now().plusMillis(remoteTimeout));
448449
}
449450
}
450451

spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/TcpReceivingChannelAdapter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.integration.ip.tcp;
1818

19+
import java.time.Duration;
1920
import java.util.concurrent.ScheduledFuture;
2021
import java.util.concurrent.atomic.AtomicInteger;
2122

@@ -72,7 +73,7 @@ public boolean onMessage(Message<?> message) {
7273
boolean isErrorMessage = message instanceof ErrorMessage;
7374
try {
7475
if (this.shuttingDown) {
75-
logger.info(() -> "Inbound message ignored; shutting down; " + message.toString());
76+
logger.info(() -> "Inbound message ignored; shutting down; " + message);
7677
}
7778
else {
7879
if (isErrorMessage) {
@@ -134,7 +135,7 @@ protected void doStart() {
134135
this.clientModeConnectionManager = manager;
135136
TaskScheduler taskScheduler = getTaskScheduler();
136137
Assert.state(taskScheduler != null, "Client mode requires a task scheduler");
137-
this.scheduledFuture = taskScheduler.scheduleAtFixedRate(manager, this.retryInterval);
138+
this.scheduledFuture = taskScheduler.scheduleAtFixedRate(manager, Duration.ofMillis(this.retryInterval));
138139
}
139140
}
140141

spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/TcpSendingMessageHandler.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package org.springframework.integration.ip.tcp;
1818

1919
import java.io.IOException;
20+
import java.time.Duration;
2021
import java.util.Map;
2122
import java.util.concurrent.ConcurrentHashMap;
2223
import java.util.concurrent.ScheduledFuture;
@@ -267,7 +268,8 @@ public void start() {
267268
this.clientModeConnectionManager = manager;
268269
TaskScheduler taskScheduler = getTaskScheduler();
269270
Assert.state(taskScheduler != null, "Client mode requires a task scheduler");
270-
this.scheduledFuture = taskScheduler.scheduleAtFixedRate(manager, this.retryInterval);
271+
this.scheduledFuture =
272+
taskScheduler.scheduleAtFixedRate(manager, Duration.ofMillis(this.retryInterval));
271273
}
272274
}
273275
}

spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/AbstractServerConnectionFactory.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2001-2020 the original author or authors.
2+
* Copyright 2001-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@
2020
import java.net.Socket;
2121
import java.net.SocketAddress;
2222
import java.net.SocketException;
23-
import java.util.Date;
23+
import java.time.Instant;
2424

2525
import org.springframework.context.ApplicationEventPublisher;
2626
import org.springframework.core.task.TaskRejectedException;
@@ -56,7 +56,6 @@ public abstract class AbstractServerConnectionFactory extends AbstractConnection
5656

5757
/**
5858
* The port on which the factory will listen.
59-
*
6059
* @param port The port.
6160
*/
6261
public AbstractServerConnectionFactory(int port) {
@@ -201,10 +200,10 @@ public int afterShutdown() {
201200
return 0;
202201
}
203202

204-
protected void publishServerExceptionEvent(Exception e) {
203+
protected void publishServerExceptionEvent(Exception ex) {
205204
ApplicationEventPublisher applicationEventPublisher = getApplicationEventPublisher();
206205
if (applicationEventPublisher != null) {
207-
applicationEventPublisher.publishEvent(new TcpConnectionServerExceptionEvent(this, e));
206+
applicationEventPublisher.publishEvent(new TcpConnectionServerExceptionEvent(this, ex));
208207
}
209208
}
210209

@@ -215,7 +214,7 @@ protected void publishServerListeningEvent(int port) {
215214
TaskScheduler taskScheduler = getTaskScheduler();
216215
if (taskScheduler != null) {
217216
try {
218-
taskScheduler.schedule(() -> eventPublisher.publishEvent(event), new Date());
217+
taskScheduler.schedule(() -> eventPublisher.publishEvent(event), Instant.now());
219218
}
220219
catch (@SuppressWarnings("unused") TaskRejectedException e) {
221220
eventPublisher.publishEvent(event);

0 commit comments

Comments
 (0)