Some Sonar fixes

This commit is contained in:
Artem Bilan
2022-11-01 16:29:14 -04:00
parent bd207ff42a
commit 6284070b45
9 changed files with 73 additions and 84 deletions

View File

@@ -32,6 +32,8 @@ import com.rabbitmq.stream.Environment;
* Spec for {@link StreamListenerContainer}.
*
* @author Gary Russell
* @author Artem Bilan
*
* @since 6.0
*
*/
@@ -46,18 +48,9 @@ public class RabbitStreamMessageListenerContainerSpec extends
this.target = new StreamListenerContainer(environment, codec);
}
/**
* Set the Stream queue name;
* Mutually exclusive with {@link #superStream(String, String)}.
* @return this spec.
*/
public RabbitStreamMessageListenerContainerSpec queueName(String queueName) {
return super.queueName(queueName);
}
/**
* Enable Single Active Consumer on a Super Stream.
* Mutually exclusive with {@link #setQueueName(String...)}.
* Mutually exclusive with {@link #queueName(String...)}.
* @param superStream the stream.
* @param name the consumer name.
* @return this spec.

View File

@@ -80,7 +80,7 @@ public class CassandraMessageHandler extends AbstractReplyProducingMessageHandle
/**
* Various options that can be used for Cassandra writes.
*/
private WriteOptions writeOptions = WriteOptions.empty();
private WriteOptions writeOptions;
private ReactiveSessionMessageCallback sessionMessageCallback;
@@ -95,18 +95,15 @@ public class CassandraMessageHandler extends AbstractReplyProducingMessageHandle
Assert.notNull(cassandraOperations, "'cassandraOperations' must not be null.");
Assert.notNull(queryType, "'queryType' must not be null.");
this.cassandraOperations = cassandraOperations;
this.cassandraOperations = cassandraOperations; // NOSONAR
this.mode = queryType;
setAsync(true);
switch (this.mode) {
case INSERT:
this.writeOptions = InsertOptions.empty();
break;
case UPDATE:
this.writeOptions = UpdateOptions.empty();
break;
}
this.writeOptions =
switch (this.mode) {
case INSERT -> InsertOptions.empty();
case UPDATE -> UpdateOptions.empty();
case DELETE, STATEMENT -> WriteOptions.empty();
};
}
public void setIngestQuery(String ingestQuery) {
@@ -183,7 +180,7 @@ public class CassandraMessageHandler extends AbstractReplyProducingMessageHandle
TypeLocator typeLocator = this.evaluationContext.getTypeLocator();
if (typeLocator instanceof StandardTypeLocator) {
/*
* Register the Cassandra Query DSL package so they don't need a FQCN for QueryBuilder, for example.
* Register the Cassandra Query DSL package, so they don't need a FQCN for QueryBuilder, for example.
*/
((StandardTypeLocator) typeLocator).registerImport(QueryBuilder.class.getPackage().getName());
}
@@ -193,28 +190,15 @@ public class CassandraMessageHandler extends AbstractReplyProducingMessageHandle
protected Object handleRequestMessage(Message<?> requestMessage) {
Object payload = requestMessage.getPayload();
Mono<? extends WriteResult> result = null;
Type modeToUse = payload instanceof Statement ? modeToUse = Type.STATEMENT : this.mode;
Type mode = this.mode;
if (payload instanceof Statement) {
mode = Type.STATEMENT;
}
switch (mode) {
case INSERT:
result = handleInsert(payload);
break;
case UPDATE:
result = handleUpdate(payload);
break;
case DELETE:
result = handleDelete(payload);
break;
case STATEMENT:
result = handleStatement(requestMessage);
break;
}
Mono<? extends WriteResult> result =
switch (modeToUse) {
case INSERT -> handleInsert(payload);
case UPDATE -> handleUpdate(payload);
case DELETE -> handleDelete(payload);
case STATEMENT -> handleStatement(requestMessage);
};
if (this.producesReply) {
return isAsync() ? result : result.block();

View File

@@ -21,6 +21,7 @@ import java.time.temporal.ChronoUnit;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
import org.springframework.lang.Nullable;
import org.springframework.scheduling.Trigger;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.scheduling.support.PeriodicTrigger;
@@ -46,7 +47,7 @@ public final class Pollers {
}
public static PollerSpec fixedRate(Duration period) {
return fixedRate(period, null);
return periodicTrigger(period, true, null);
}
/**
@@ -75,7 +76,7 @@ public final class Pollers {
}
public static PollerSpec fixedDelay(Duration period) {
return fixedDelay(period, null);
return periodicTrigger(period, false, null);
}
public static PollerSpec fixedDelay(long period) {
@@ -107,10 +108,12 @@ public final class Pollers {
return fixedDelay(Duration.of(period, chronoUnit), Duration.of(initialDelay, chronoUnit));
}
private static PollerSpec periodicTrigger(Duration period, boolean fixedRate, Duration initialDelay) {
private static PollerSpec periodicTrigger(Duration period, boolean fixedRate, @Nullable Duration initialDelay) {
PeriodicTrigger periodicTrigger = new PeriodicTrigger(period);
periodicTrigger.setFixedRate(fixedRate);
periodicTrigger.setInitialDelay(initialDelay);
if (initialDelay != null) {
periodicTrigger.setInitialDelay(initialDelay);
}
return new PollerSpec(periodicTrigger);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2021 the original author or authors.
* Copyright 2021-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.
@@ -16,6 +16,8 @@
package org.springframework.integration.http.config;
import java.util.Arrays;
import org.springframework.web.reactive.config.CorsRegistry;
import org.springframework.web.reactive.config.WebFluxConfigurer;
@@ -34,9 +36,9 @@ final class WebFluxIntegrationGraphCorsConfigurer implements WebFluxConfigurer {
private final String[] allowedOrigins;
WebFluxIntegrationGraphCorsConfigurer(String path, String[] allowedOrigins) { // NOSONAR
WebFluxIntegrationGraphCorsConfigurer(String path, String[] allowedOrigins) {
this.path = path;
this.allowedOrigins = allowedOrigins;
this.allowedOrigins = Arrays.copyOf(allowedOrigins, allowedOrigins.length);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2021 the original author or authors.
* Copyright 2021-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.
@@ -16,6 +16,8 @@
package org.springframework.integration.http.config;
import java.util.Arrays;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@@ -34,9 +36,9 @@ final class WebMvcIntegrationGraphCorsConfigurer implements WebMvcConfigurer {
private final String[] allowedOrigins;
WebMvcIntegrationGraphCorsConfigurer(String path, String[] allowedOrigins) { // NOSONAR
WebMvcIntegrationGraphCorsConfigurer(String path, String[] allowedOrigins) {
this.path = path;
this.allowedOrigins = allowedOrigins;
this.allowedOrigins = Arrays.copyOf(allowedOrigins, allowedOrigins.length);
}
@Override

View File

@@ -225,30 +225,34 @@ public class DefaultLockRepository
@Override
public boolean acquire(String lock) {
return this.serializableTransactionTemplate.execute(
transactionStatus -> {
if (this.template.update(this.updateQuery, this.id, LocalDateTime.now(ZoneOffset.UTC),
this.region, lock, this.id,
LocalDateTime.now(ZoneOffset.UTC).minus(this.ttl, ChronoUnit.MILLIS)) > 0) {
return true;
}
try {
return this.template.update(this.insertQuery, this.region, lock, this.id,
LocalDateTime.now(ZoneOffset.UTC)) > 0;
}
catch (DataIntegrityViolationException ex) {
return false;
}
});
Boolean result =
this.serializableTransactionTemplate.execute(
transactionStatus -> {
if (this.template.update(this.updateQuery, this.id, LocalDateTime.now(ZoneOffset.UTC),
this.region, lock, this.id,
LocalDateTime.now(ZoneOffset.UTC).minus(this.ttl, ChronoUnit.MILLIS)) > 0) {
return true;
}
try {
return this.template.update(this.insertQuery, this.region, lock, this.id,
LocalDateTime.now(ZoneOffset.UTC)) > 0;
}
catch (DataIntegrityViolationException ex) {
return false;
}
});
return Boolean.TRUE.equals(result);
}
@Override
public boolean isAcquired(String lock) {
return this.readOnlyTransactionTemplate.execute(
final Boolean result = this.readOnlyTransactionTemplate.execute(
transactionStatus ->
this.template.queryForObject(this.countQuery, // NOSONAR query never returns null
Integer.class, this.region, lock, this.id,
LocalDateTime.now(ZoneOffset.UTC).minus(this.ttl, ChronoUnit.MILLIS)) == 1);
Integer.valueOf(1).equals(
this.template.queryForObject(this.countQuery,
Integer.class, this.region, lock, this.id,
LocalDateTime.now(ZoneOffset.UTC).minus(this.ttl, ChronoUnit.MILLIS))));
return Boolean.TRUE.equals(result);
}
@Override
@@ -261,10 +265,11 @@ public class DefaultLockRepository
@Override
public boolean renew(String lock) {
return this.defaultTransactionTemplate.execute(
final Boolean result = this.defaultTransactionTemplate.execute(
transactionStatus ->
this.template.update(this.renewQuery, LocalDateTime.now(ZoneOffset.UTC),
this.region, lock, this.id) > 0);
return Boolean.TRUE.equals(result);
}
}

View File

@@ -61,7 +61,7 @@ public abstract class AbstractMqttClientManager<T, C> implements ClientManager<T
private String beanName;
private volatile T client;
private T client;
protected AbstractMqttClientManager(String clientId) {
Assert.notNull(clientId, "'clientId' is required");
@@ -102,7 +102,7 @@ public abstract class AbstractMqttClientManager<T, C> implements ClientManager<T
}
@Override
public T getClient() {
public synchronized T getClient() {
return this.client;
}

View File

@@ -41,7 +41,7 @@ class SpringIntegrationTestExecutionListener implements TestExecutionListener {
SpringIntegrationTest springIntegrationTest =
AnnotatedElementUtils.findMergedAnnotation(testContext.getTestClass(), SpringIntegrationTest.class);
String[] patterns = springIntegrationTest.noAutoStartup();
String[] patterns = springIntegrationTest != null ? springIntegrationTest.noAutoStartup() : new String[0];
ApplicationContext applicationContext = testContext.getApplicationContext();
MockIntegrationContext mockIntegrationContext = applicationContext.getBean(MockIntegrationContext.class);

View File

@@ -74,7 +74,7 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif
public ZookeeperMetadataStore(CuratorFramework client) {
Assert.notNull(client, "Client cannot be null");
this.client = client;
this.client = client; // NOSONAR
}
/**
@@ -195,7 +195,7 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif
return this.updateMap.get(key).value();
}
return IntegrationUtils.bytesToString(currentData.getData(), this.encoding);
return IntegrationUtils.bytesToString(currentData.getData(), this.encoding); // NOSONAR
})
.orElseGet(() -> {
if (this.updateMap.containsKey(key)) {
@@ -312,7 +312,7 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif
String value = IntegrationUtils.bytesToString(data.getData(), ZookeeperMetadataStore.this.encoding);
switch (type) {
case NODE_CREATED:
case NODE_CREATED -> {
if (ZookeeperMetadataStore.this.updateMap.containsKey(eventKey) &&
data.getStat().getVersion() >=
ZookeeperMetadataStore.this.updateMap.get(eventKey).version()) {
@@ -320,8 +320,8 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif
ZookeeperMetadataStore.this.updateMap.remove(eventPath);
}
ZookeeperMetadataStore.this.listeners.forEach((listener) -> listener.onAdd(eventKey, value));
break;
case NODE_CHANGED:
}
case NODE_CHANGED -> {
if (ZookeeperMetadataStore.this.updateMap.containsKey(eventKey) &&
data.getStat().getVersion() >=
ZookeeperMetadataStore.this.updateMap.get(eventKey).version()) {
@@ -329,11 +329,11 @@ public class ZookeeperMetadataStore implements ListenableMetadataStore, SmartLif
ZookeeperMetadataStore.this.updateMap.remove(eventPath);
}
ZookeeperMetadataStore.this.listeners.forEach((listener) -> listener.onUpdate(eventKey, value));
break;
case NODE_DELETED:
}
case NODE_DELETED -> {
ZookeeperMetadataStore.this.updateMap.remove(eventKey);
ZookeeperMetadataStore.this.listeners.forEach((listener) -> listener.onRemove(eventKey, value));
break;
}
}
}