Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@

package org.springframework.integration.metadata;

import org.jspecify.annotations.Nullable;

/**
* Supports atomic updates to values in the store.
*
* @author Gary Russell
* @author Glenn Renfro
* @since 4.0
*
*/
Expand All @@ -32,6 +35,7 @@ public interface ConcurrentMetadataStore extends MetadataStore {
* @param value The value.
* @return null if successful, the old value otherwise.
*/
@Nullable
String putIfAbsent(String key, String value);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.integration.metadata;

import org.jspecify.annotations.Nullable;

import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedResource;

Expand All @@ -27,6 +29,7 @@
* @author Oleg Zhurakousky
* @author Mark Fisher
* @author Gary Russell
* @author Glenn Renfro
* @since 2.0
*/
@ManagedResource
Expand All @@ -47,7 +50,7 @@ public interface MetadataStore {
* @return The value.
*/
@ManagedAttribute
String get(String key);
@Nullable String get(String key);

/**
* Remove a value for the given key from this MetadataStore.
Expand All @@ -56,6 +59,6 @@ public interface MetadataStore {
* null if there was no mapping for key.
*/
@ManagedAttribute
String remove(String key);
@Nullable String remove(String key);

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
Expand All @@ -51,14 +52,13 @@
* @author Mark Fisher
* @author Gary Russell
* @author Artem Bilan
* @author Glenn Renfro
*
* @since 2.0
*/
public class PropertiesPersistingMetadataStore implements ConcurrentMetadataStore, InitializingBean, DisposableBean,
Closeable, Flushable {

private static final String KEY_CANNOT_BE_NULL = "'key' cannot be null";

private final Log logger = LogFactory.getLog(getClass());

private final Properties metadata = new Properties();
Expand All @@ -71,6 +71,7 @@ public class PropertiesPersistingMetadataStore implements ConcurrentMetadataStor

private String fileName = "metadata-store.properties";

@SuppressWarnings("NullAway.Init")
private File file;

private volatile boolean dirty;
Expand Down Expand Up @@ -115,8 +116,6 @@ public void afterPropertiesSet() {

@Override
public void put(String key, String value) {
Assert.notNull(key, KEY_CANNOT_BE_NULL);
Assert.notNull(value, "'value' cannot be null");
Lock lock = this.lockRegistry.obtain(key);
lock.lock();
try {
Expand All @@ -129,8 +128,7 @@ public void put(String key, String value) {
}

@Override
public String get(String key) {
Assert.notNull(key, KEY_CANNOT_BE_NULL);
public @Nullable String get(String key) {
Lock lock = this.lockRegistry.obtain(key);
lock.lock();
try {
Expand All @@ -142,8 +140,7 @@ public String get(String key) {
}

@Override
public String remove(String key) {
Assert.notNull(key, KEY_CANNOT_BE_NULL);
public @Nullable String remove(String key) {
Lock lock = this.lockRegistry.obtain(key);
lock.lock();
try {
Expand All @@ -156,9 +153,7 @@ public String remove(String key) {
}

@Override
public String putIfAbsent(String key, String value) {
Assert.notNull(key, KEY_CANNOT_BE_NULL);
Assert.notNull(value, "'value' cannot be null");
public @Nullable String putIfAbsent(String key, String value) {
Lock lock = this.lockRegistry.obtain(key);
lock.lock();
try {
Expand All @@ -179,9 +174,6 @@ public String putIfAbsent(String key, String value) {

@Override
public boolean replace(String key, String oldValue, String newValue) {
Assert.notNull(key, KEY_CANNOT_BE_NULL);
Assert.notNull(oldValue, "'oldValue' cannot be null");
Assert.notNull(newValue, "'newValue' cannot be null");
Lock lock = this.lockRegistry.obtain(key);
lock.lock();
try {
Expand Down Expand Up @@ -216,7 +208,7 @@ public void destroy() {
}

private void saveMetadata() {
if (this.file == null || !this.dirty) {
if (!this.dirty) {
return;
}
this.dirty = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.jspecify.annotations.Nullable;

import org.springframework.util.Assert;

/**
Expand All @@ -29,6 +31,7 @@
* @author Mark Fisher
* @author Gary Russell
* @author Artem Bilan
* @author Glenn Renfro
* @since 2.0
*/
public class SimpleMetadataStore implements ConcurrentMetadataStore {
Expand Down Expand Up @@ -59,17 +62,17 @@ public void put(String key, String value) {
}

@Override
public String get(String key) {
public @Nullable String get(String key) {
return this.metadata.get(key);
}

@Override
public String remove(String key) {
public @Nullable String remove(String key) {
return this.metadata.remove(key);
}

@Override
public String putIfAbsent(String key, String value) {
public @Nullable String putIfAbsent(String key, String value) {
return this.metadata.putIfAbsent(key, value);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* Provides classes supporting metadata stores.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.integration.metadata;
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
* @author Artem Bilan
* @author Gary Russell
* @author Christian Tzolov
* @author Glenn Renfro
*
* @since 4.1
*/
Expand Down Expand Up @@ -114,10 +115,13 @@ public MetadataStoreSelector compareValues(@Nullable BiPredicate<String, String>
@Override
public boolean accept(Message<?> message) {
String key = this.keyStrategy.processMessage(message);
Assert.state(key != null, () -> "The keyStrategy.processMessage must not return null.");

Long timestamp = message.getHeaders().getTimestamp();
String value = (this.valueStrategy != null)
? this.valueStrategy.processMessage(message)
: (timestamp == null ? "0" : Long.toString(timestamp));
Assert.state(value != null, () -> "The valueStrategy.processMessage must not return null.");

BiPredicate<String, String> predicate = this.compareValues;
if (predicate == null) {
Expand Down