Skip to content

Commit

Permalink
Resolve Deprecations in Spring Framework 6.0
Browse files Browse the repository at this point in the history
- TaskScheduler
  • Loading branch information
garyrussell authored and artembilan committed Jul 19, 2022
1 parent d538c39 commit 32c1c99
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 the original author or authors.
* Copyright 2016-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.
Expand All @@ -16,7 +16,7 @@

package org.springframework.amqp.rabbit;

import java.util.Date;
import java.time.Instant;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
Expand Down Expand Up @@ -741,7 +741,7 @@ void startTimer() {
throw new IllegalStateException("'AsyncRabbitTemplate' must be started.");
}
this.timeoutTask = AsyncRabbitTemplate.this.taskScheduler.schedule(new TimeoutTask(),
new Date(System.currentTimeMillis() + AsyncRabbitTemplate.this.receiveTimeout));
Instant.now().plusMillis(AsyncRabbitTemplate.this.receiveTimeout));
}
}
else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2019 the original author or authors.
* Copyright 2014-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.
Expand All @@ -25,6 +25,7 @@
import org.springframework.amqp.rabbit.batch.MessageBatch;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.lang.Nullable;
import org.springframework.scheduling.TaskScheduler;

/**
Expand Down Expand Up @@ -74,12 +75,12 @@ public BatchingRabbitTemplate(ConnectionFactory connectionFactory, BatchingStrat
}

@Override
public synchronized void send(String exchange, String routingKey, Message message, CorrelationData correlationData)
throws AmqpException {
public synchronized void send(String exchange, String routingKey, Message message,
@Nullable CorrelationData correlationData) throws AmqpException {

if (correlationData != null) {
if (logger.isDebugEnabled()) {
logger.debug("Cannot use batching with correlation data");
if (this.logger.isDebugEnabled()) {
this.logger.debug("Cannot use batching with correlation data");
}
super.send(exchange, routingKey, message, correlationData);
}
Expand All @@ -93,7 +94,7 @@ public synchronized void send(String exchange, String routingKey, Message messag
}
Date next = this.batchingStrategy.nextRelease();
if (next != null) {
this.scheduledTask = this.scheduler.schedule((Runnable) () -> releaseBatches(), next);
this.scheduledTask = this.scheduler.schedule((Runnable) () -> releaseBatches(), next.toInstant());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 the original author or authors.
* Copyright 2016-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.
Expand All @@ -18,11 +18,12 @@

import java.io.IOException;
import java.lang.reflect.Constructor;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.LinkedList;
Expand Down Expand Up @@ -510,7 +511,7 @@ private void startMonitor(long idleEventInterval, final Map<String, Queue> names
}
}
processMonitorTask();
}, this.monitorInterval);
}, Duration.ofMillis(this.monitorInterval));
}

private void checkIdle(long idleEventInterval, long now) {
Expand Down Expand Up @@ -578,7 +579,7 @@ private boolean restartConsumer(final Map<String, Queue> namesToQueues, List<Sim
this.logger.error("Cannot connect to server", e);
if (e.getCause() instanceof AmqpApplicationContextClosedException) {
this.logger.error("Application context is closed, terminating");
this.taskScheduler.schedule(this::stop, new Date());
this.taskScheduler.schedule(this::stop, Instant.now());
}
this.consumersToRestart.addAll(restartableConsumers);
if (this.logger.isTraceEnabled()) {
Expand Down Expand Up @@ -612,7 +613,7 @@ private void startConsumers(final String[] queueNames) {
shutdown();
this.logger.error("Failed to start container - fatal error or backOffs exhausted",
e);
this.taskScheduler.schedule(this::stop, new Date());
this.taskScheduler.schedule(this::stop, Instant.now());
break;
}
this.logger.error("Error creating consumer; retrying in " + nextBackOff, e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 the original author or authors.
* Copyright 2016-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.
Expand Down

0 comments on commit 32c1c99

Please sign in to comment.