Skip to content

Commit 32c1c99

Browse files
garyrussellartembilan
authored andcommitted
Resolve Deprecations in Spring Framework 6.0
- TaskScheduler
1 parent d538c39 commit 32c1c99

4 files changed

Lines changed: 17 additions & 15 deletions

File tree

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/AsyncRabbitTemplate.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 the original author or authors.
2+
* Copyright 2016-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,7 +16,7 @@
1616

1717
package org.springframework.amqp.rabbit;
1818

19-
import java.util.Date;
19+
import java.time.Instant;
2020
import java.util.UUID;
2121
import java.util.concurrent.ConcurrentHashMap;
2222
import java.util.concurrent.ConcurrentMap;
@@ -741,7 +741,7 @@ void startTimer() {
741741
throw new IllegalStateException("'AsyncRabbitTemplate' must be started.");
742742
}
743743
this.timeoutTask = AsyncRabbitTemplate.this.taskScheduler.schedule(new TimeoutTask(),
744-
new Date(System.currentTimeMillis() + AsyncRabbitTemplate.this.receiveTimeout));
744+
Instant.now().plusMillis(AsyncRabbitTemplate.this.receiveTimeout));
745745
}
746746
}
747747
else {

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/BatchingRabbitTemplate.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-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.
@@ -25,6 +25,7 @@
2525
import org.springframework.amqp.rabbit.batch.MessageBatch;
2626
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
2727
import org.springframework.amqp.rabbit.connection.CorrelationData;
28+
import org.springframework.lang.Nullable;
2829
import org.springframework.scheduling.TaskScheduler;
2930

3031
/**
@@ -74,12 +75,12 @@ public BatchingRabbitTemplate(ConnectionFactory connectionFactory, BatchingStrat
7475
}
7576

7677
@Override
77-
public synchronized void send(String exchange, String routingKey, Message message, CorrelationData correlationData)
78-
throws AmqpException {
78+
public synchronized void send(String exchange, String routingKey, Message message,
79+
@Nullable CorrelationData correlationData) throws AmqpException {
7980

8081
if (correlationData != null) {
81-
if (logger.isDebugEnabled()) {
82-
logger.debug("Cannot use batching with correlation data");
82+
if (this.logger.isDebugEnabled()) {
83+
this.logger.debug("Cannot use batching with correlation data");
8384
}
8485
super.send(exchange, routingKey, message, correlationData);
8586
}
@@ -93,7 +94,7 @@ public synchronized void send(String exchange, String routingKey, Message messag
9394
}
9495
Date next = this.batchingStrategy.nextRelease();
9596
if (next != null) {
96-
this.scheduledTask = this.scheduler.schedule((Runnable) () -> releaseBatches(), next);
97+
this.scheduledTask = this.scheduler.schedule((Runnable) () -> releaseBatches(), next.toInstant());
9798
}
9899
}
99100
}

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/DirectMessageListenerContainer.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 the original author or authors.
2+
* Copyright 2016-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.
@@ -18,11 +18,12 @@
1818

1919
import java.io.IOException;
2020
import java.lang.reflect.Constructor;
21+
import java.time.Duration;
22+
import java.time.Instant;
2123
import java.util.ArrayList;
2224
import java.util.Arrays;
2325
import java.util.Collection;
2426
import java.util.Collections;
25-
import java.util.Date;
2627
import java.util.Iterator;
2728
import java.util.LinkedHashSet;
2829
import java.util.LinkedList;
@@ -510,7 +511,7 @@ private void startMonitor(long idleEventInterval, final Map<String, Queue> names
510511
}
511512
}
512513
processMonitorTask();
513-
}, this.monitorInterval);
514+
}, Duration.ofMillis(this.monitorInterval));
514515
}
515516

516517
private void checkIdle(long idleEventInterval, long now) {
@@ -578,7 +579,7 @@ private boolean restartConsumer(final Map<String, Queue> namesToQueues, List<Sim
578579
this.logger.error("Cannot connect to server", e);
579580
if (e.getCause() instanceof AmqpApplicationContextClosedException) {
580581
this.logger.error("Application context is closed, terminating");
581-
this.taskScheduler.schedule(this::stop, new Date());
582+
this.taskScheduler.schedule(this::stop, Instant.now());
582583
}
583584
this.consumersToRestart.addAll(restartableConsumers);
584585
if (this.logger.isTraceEnabled()) {
@@ -612,7 +613,7 @@ private void startConsumers(final String[] queueNames) {
612613
shutdown();
613614
this.logger.error("Failed to start container - fatal error or backOffs exhausted",
614615
e);
615-
this.taskScheduler.schedule(this::stop, new Date());
616+
this.taskScheduler.schedule(this::stop, Instant.now());
616617
break;
617618
}
618619
this.logger.error("Error creating consumer; retrying in " + nextBackOff, e);

spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/ContainerInitializationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 the original author or authors.
2+
* Copyright 2016-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.

0 commit comments

Comments
 (0)