优化CacheSource.hmap方法
This commit is contained in:
@@ -237,7 +237,7 @@ public class CacheClusterAgent extends ClusterAgent implements Resourcable {
|
||||
}
|
||||
|
||||
private CompletableFuture<Set<InetSocketAddress>> queryAddress(final String serviceName) {
|
||||
final CompletableFuture<Map<String, AddressEntry>> future = source.hscanAsync(serviceName, AddressEntry.class, 0, 10000);
|
||||
final CompletableFuture<Map<String, AddressEntry>> future = source.hmapAsync(serviceName, AddressEntry.class, new AtomicInteger(), 10000);
|
||||
return future.thenApply(map -> {
|
||||
final Set<InetSocketAddress> set = new HashSet<>();
|
||||
map.forEach((n, v) -> {
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
package org.redkale.source;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Supplier;
|
||||
import org.redkale.annotation.AutoLoad;
|
||||
import org.redkale.annotation.ResourceListener;
|
||||
import org.redkale.annotation.ResourceType;
|
||||
@@ -108,4 +110,8 @@ public abstract class AbstractCacheSource extends AbstractService implements Cac
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
protected <U> CompletableFuture<U> supplyAsync(Supplier<U> supplier) {
|
||||
return CompletableFuture.supplyAsync(supplier);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.io.Serializable;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.atomic.*;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.*;
|
||||
import java.util.logging.*;
|
||||
@@ -393,12 +393,12 @@ public final class CacheMemorySource extends AbstractCacheSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Map<String, T> hscan(final String key, final Type type, int offset, int limit) {
|
||||
return hscan(key, type, offset, limit, null);
|
||||
public <T> Map<String, T> hmap(final String key, final Type type, AtomicInteger cursor, int limit) {
|
||||
return hmap(key, type, cursor, limit, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Map<String, T> hscan(final String key, final Type type, int offset, int limit, String pattern) {
|
||||
public <T> Map<String, T> hmap(final String key, final Type type, AtomicInteger cursor, int limit, String pattern) {
|
||||
if (key == null) {
|
||||
return new HashMap();
|
||||
}
|
||||
@@ -651,13 +651,13 @@ public final class CacheMemorySource extends AbstractCacheSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> CompletableFuture<Map<String, T>> hscanAsync(final String key, final Type type, int offset, int limit) {
|
||||
return CompletableFuture.supplyAsync(() -> hscan(key, type, offset, limit), getExecutor());
|
||||
public <T> CompletableFuture<Map<String, T>> hmapAsync(final String key, final Type type, AtomicInteger cursor, int limit) {
|
||||
return CompletableFuture.supplyAsync(() -> hmap(key, type, cursor, limit), getExecutor());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> CompletableFuture<Map<String, T>> hscanAsync(final String key, final Type type, int offset, int limit, String pattern) {
|
||||
return CompletableFuture.supplyAsync(() -> hscan(key, type, offset, limit, pattern), getExecutor());
|
||||
public <T> CompletableFuture<Map<String, T>> hmapAsync(final String key, final Type type, AtomicInteger cursor, int limit, String pattern) {
|
||||
return CompletableFuture.supplyAsync(() -> hmap(key, type, cursor, limit, pattern), getExecutor());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1993,9 +1993,8 @@ public final class CacheMemorySource extends AbstractCacheSource {
|
||||
return mapValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------- 过期方法 ----------------------------------
|
||||
|
||||
@Override
|
||||
@Deprecated(since = "2.8.0")
|
||||
public Collection<Long> getexLongCollection(String key, int expireSeconds) {
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.io.Serializable;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.redkale.annotation.Component;
|
||||
import org.redkale.convert.Convert;
|
||||
import org.redkale.util.*;
|
||||
@@ -247,9 +248,9 @@ public interface CacheSource extends Resourcable {
|
||||
|
||||
public <T> List<T> hmget(final String key, final Type type, final String... fields);
|
||||
|
||||
public <T> Map<String, T> hscan(final String key, final Type type, int offset, int limit);
|
||||
public <T> Map<String, T> hmap(final String key, final Type type, AtomicInteger cursor, int limit);
|
||||
|
||||
public <T> Map<String, T> hscan(final String key, final Type type, int offset, int limit, String pattern);
|
||||
public <T> Map<String, T> hmap(final String key, final Type type, AtomicInteger cursor, int limit, String pattern);
|
||||
|
||||
//------------------------ list ------------------------
|
||||
public int llen(final String key);
|
||||
@@ -552,9 +553,9 @@ public interface CacheSource extends Resourcable {
|
||||
|
||||
public <T> CompletableFuture<List<T>> hmgetAsync(final String key, final Type type, final String... fields);
|
||||
|
||||
public <T> CompletableFuture<Map<String, T>> hscanAsync(final String key, final Type type, int offset, int limit);
|
||||
public <T> CompletableFuture<Map<String, T>> hmapAsync(final String key, final Type type, AtomicInteger cursor, int limit);
|
||||
|
||||
public <T> CompletableFuture<Map<String, T>> hscanAsync(final String key, final Type type, int offset, int limit, String pattern);
|
||||
public <T> CompletableFuture<Map<String, T>> hmapAsync(final String key, final Type type, AtomicInteger cursor, int limit, String pattern);
|
||||
|
||||
//------------------------ listAsync ------------------------
|
||||
public CompletableFuture<Integer> llenAsync(final String key);
|
||||
|
||||
Reference in New Issue
Block a user