This commit is contained in:
@@ -200,18 +200,6 @@ public class CacheMemorySource<K extends Serializable, V extends Object> extends
|
|||||||
return CompletableFuture.supplyAsync(() -> exists(key), getExecutor());
|
return CompletableFuture.supplyAsync(() -> exists(key), getExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void existsAsync(final AsyncHandler<Boolean, K> handler, @RpcAttachment final K key) {
|
|
||||||
super.runAsync(() -> {
|
|
||||||
try {
|
|
||||||
boolean rs = exists(key);
|
|
||||||
if (handler != null) handler.completed(rs, key);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
if (handler != null) handler.failed(t, key);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public V get(K key) {
|
public V get(K key) {
|
||||||
if (key == null) return null;
|
if (key == null) return null;
|
||||||
@@ -227,18 +215,6 @@ public class CacheMemorySource<K extends Serializable, V extends Object> extends
|
|||||||
return CompletableFuture.supplyAsync(() -> get(key), getExecutor());
|
return CompletableFuture.supplyAsync(() -> get(key), getExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getAsync(final AsyncHandler<V, K> handler, @RpcAttachment final K key) {
|
|
||||||
super.runAsync(() -> {
|
|
||||||
try {
|
|
||||||
V rs = get(key);
|
|
||||||
if (handler != null) handler.completed(rs, key);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
if (handler != null) handler.failed(t, key);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@RpcMultiRun
|
@RpcMultiRun
|
||||||
public V getAndRefresh(K key, final int expireSeconds) {
|
public V getAndRefresh(K key, final int expireSeconds) {
|
||||||
@@ -257,18 +233,6 @@ public class CacheMemorySource<K extends Serializable, V extends Object> extends
|
|||||||
return CompletableFuture.supplyAsync(() -> getAndRefresh(key, expireSeconds), getExecutor());
|
return CompletableFuture.supplyAsync(() -> getAndRefresh(key, expireSeconds), getExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getAndRefreshAsync(final AsyncHandler<V, K> handler, @RpcAttachment final K key, final int expireSeconds) {
|
|
||||||
super.runAsync(() -> {
|
|
||||||
try {
|
|
||||||
V rs = getAndRefresh(key, expireSeconds);
|
|
||||||
if (handler != null) handler.completed(rs, key);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
if (handler != null) handler.failed(t, key);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@RpcMultiRun
|
@RpcMultiRun
|
||||||
public void refresh(K key, final int expireSeconds) {
|
public void refresh(K key, final int expireSeconds) {
|
||||||
@@ -284,18 +248,6 @@ public class CacheMemorySource<K extends Serializable, V extends Object> extends
|
|||||||
return CompletableFuture.runAsync(() -> refresh(key, expireSeconds), getExecutor());
|
return CompletableFuture.runAsync(() -> refresh(key, expireSeconds), getExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void refreshAsync(final AsyncHandler<Void, K> handler, @RpcAttachment final K key, final int expireSeconds) {
|
|
||||||
super.runAsync(() -> {
|
|
||||||
try {
|
|
||||||
refresh(key, expireSeconds);
|
|
||||||
if (handler != null) handler.completed(null, key);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
if (handler != null) handler.failed(t, key);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@RpcMultiRun
|
@RpcMultiRun
|
||||||
public void set(K key, V value) {
|
public void set(K key, V value) {
|
||||||
@@ -316,18 +268,6 @@ public class CacheMemorySource<K extends Serializable, V extends Object> extends
|
|||||||
return CompletableFuture.runAsync(() -> set(key, value), getExecutor());
|
return CompletableFuture.runAsync(() -> set(key, value), getExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setAsync(final AsyncHandler<Void, K> handler, @RpcAttachment final K key, final V value) {
|
|
||||||
super.runAsync(() -> {
|
|
||||||
try {
|
|
||||||
set(key, value);
|
|
||||||
if (handler != null) handler.completed(null, key);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
if (handler != null) handler.failed(t, key);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@RpcMultiRun
|
@RpcMultiRun
|
||||||
public void set(int expireSeconds, K key, V value) {
|
public void set(int expireSeconds, K key, V value) {
|
||||||
@@ -348,18 +288,6 @@ public class CacheMemorySource<K extends Serializable, V extends Object> extends
|
|||||||
return CompletableFuture.runAsync(() -> set(expireSeconds, key, value), getExecutor());
|
return CompletableFuture.runAsync(() -> set(expireSeconds, key, value), getExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setAsync(final AsyncHandler<Void, K> handler, final int expireSeconds, @RpcAttachment final K key, final V value) {
|
|
||||||
super.runAsync(() -> {
|
|
||||||
try {
|
|
||||||
set(expireSeconds, key, value);
|
|
||||||
if (handler != null) handler.completed(null, key);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
if (handler != null) handler.failed(t, key);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@RpcMultiRun
|
@RpcMultiRun
|
||||||
public void setExpireSeconds(K key, int expireSeconds) {
|
public void setExpireSeconds(K key, int expireSeconds) {
|
||||||
@@ -374,18 +302,6 @@ public class CacheMemorySource<K extends Serializable, V extends Object> extends
|
|||||||
return CompletableFuture.runAsync(() -> setExpireSeconds(key, expireSeconds), getExecutor());
|
return CompletableFuture.runAsync(() -> setExpireSeconds(key, expireSeconds), getExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setExpireSecondsAsync(final AsyncHandler<Void, K> handler, @RpcAttachment final K key, final int expireSeconds) {
|
|
||||||
super.runAsync(() -> {
|
|
||||||
try {
|
|
||||||
setExpireSeconds(key, expireSeconds);
|
|
||||||
if (handler != null) handler.completed(null, key);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
if (handler != null) handler.failed(t, key);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@RpcMultiRun
|
@RpcMultiRun
|
||||||
public void remove(K key) {
|
public void remove(K key) {
|
||||||
@@ -398,18 +314,6 @@ public class CacheMemorySource<K extends Serializable, V extends Object> extends
|
|||||||
return CompletableFuture.runAsync(() -> remove(key), getExecutor());
|
return CompletableFuture.runAsync(() -> remove(key), getExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeAsync(final AsyncHandler<Void, K> handler, @RpcAttachment final K key) {
|
|
||||||
super.runAsync(() -> {
|
|
||||||
try {
|
|
||||||
remove(key);
|
|
||||||
if (handler != null) handler.completed(null, key);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
if (handler != null) handler.failed(t, key);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<V> getCollection(final K key) {
|
public Collection<V> getCollection(final K key) {
|
||||||
return (Collection<V>) get(key);
|
return (Collection<V>) get(key);
|
||||||
@@ -420,18 +324,6 @@ public class CacheMemorySource<K extends Serializable, V extends Object> extends
|
|||||||
return CompletableFuture.supplyAsync(() -> getCollection(key), getExecutor());
|
return CompletableFuture.supplyAsync(() -> getCollection(key), getExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getCollectionAsync(final AsyncHandler<Collection<V>, K> handler, @RpcAttachment final K key) {
|
|
||||||
super.runAsync(() -> {
|
|
||||||
try {
|
|
||||||
Collection<V> rs = getCollection(key);
|
|
||||||
if (handler != null) handler.completed(rs, key);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
if (handler != null) handler.failed(t, key);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<V> getCollectionAndRefresh(final K key, final int expireSeconds) {
|
public Collection<V> getCollectionAndRefresh(final K key, final int expireSeconds) {
|
||||||
return (Collection<V>) getAndRefresh(key, expireSeconds);
|
return (Collection<V>) getAndRefresh(key, expireSeconds);
|
||||||
@@ -442,18 +334,6 @@ public class CacheMemorySource<K extends Serializable, V extends Object> extends
|
|||||||
return CompletableFuture.supplyAsync(() -> getCollectionAndRefresh(key, expireSeconds), getExecutor());
|
return CompletableFuture.supplyAsync(() -> getCollectionAndRefresh(key, expireSeconds), getExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getCollectionAndRefreshAsync(final AsyncHandler<Collection<V>, K> handler, @RpcAttachment final K key, final int expireSeconds) {
|
|
||||||
super.runAsync(() -> {
|
|
||||||
try {
|
|
||||||
Collection<V> rs = getCollectionAndRefresh(key, expireSeconds);
|
|
||||||
if (handler != null) handler.completed(rs, key);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
if (handler != null) handler.failed(t, key);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@RpcMultiRun
|
@RpcMultiRun
|
||||||
public void appendListItem(K key, V value) {
|
public void appendListItem(K key, V value) {
|
||||||
@@ -475,18 +355,6 @@ public class CacheMemorySource<K extends Serializable, V extends Object> extends
|
|||||||
return CompletableFuture.runAsync(() -> appendListItem(key, value), getExecutor());
|
return CompletableFuture.runAsync(() -> appendListItem(key, value), getExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void appendListItemAsync(final AsyncHandler<Void, K> handler, @RpcAttachment final K key, final V value) {
|
|
||||||
super.runAsync(() -> {
|
|
||||||
try {
|
|
||||||
appendListItem(key, value);
|
|
||||||
if (handler != null) handler.completed(null, key);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
if (handler != null) handler.failed(t, key);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@RpcMultiRun
|
@RpcMultiRun
|
||||||
public void removeListItem(K key, V value) {
|
public void removeListItem(K key, V value) {
|
||||||
@@ -501,18 +369,6 @@ public class CacheMemorySource<K extends Serializable, V extends Object> extends
|
|||||||
return CompletableFuture.runAsync(() -> removeListItem(key, value), getExecutor());
|
return CompletableFuture.runAsync(() -> removeListItem(key, value), getExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeListItemAsync(final AsyncHandler<Void, K> handler, @RpcAttachment final K key, final V value) {
|
|
||||||
super.runAsync(() -> {
|
|
||||||
try {
|
|
||||||
removeListItem(key, value);
|
|
||||||
if (handler != null) handler.completed(null, key);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
if (handler != null) handler.failed(t, key);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@RpcMultiRun
|
@RpcMultiRun
|
||||||
public void appendSetItem(K key, V value) {
|
public void appendSetItem(K key, V value) {
|
||||||
@@ -534,18 +390,6 @@ public class CacheMemorySource<K extends Serializable, V extends Object> extends
|
|||||||
return CompletableFuture.runAsync(() -> appendSetItem(key, value), getExecutor());
|
return CompletableFuture.runAsync(() -> appendSetItem(key, value), getExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void appendSetItemAsync(final AsyncHandler<Void, K> handler, @RpcAttachment final K key, final V value) {
|
|
||||||
super.runAsync(() -> {
|
|
||||||
try {
|
|
||||||
appendSetItem(key, value);
|
|
||||||
if (handler != null) handler.completed(null, key);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
if (handler != null) handler.failed(t, key);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@RpcMultiRun
|
@RpcMultiRun
|
||||||
public void removeSetItem(K key, V value) {
|
public void removeSetItem(K key, V value) {
|
||||||
@@ -560,18 +404,6 @@ public class CacheMemorySource<K extends Serializable, V extends Object> extends
|
|||||||
return CompletableFuture.runAsync(() -> removeSetItem(key, value), getExecutor());
|
return CompletableFuture.runAsync(() -> removeSetItem(key, value), getExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeSetItemAsync(final AsyncHandler<Void, K> handler, @RpcAttachment final K key, final V value) {
|
|
||||||
super.runAsync(() -> {
|
|
||||||
try {
|
|
||||||
removeSetItem(key, value);
|
|
||||||
if (handler != null) handler.completed(null, key);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
if (handler != null) handler.failed(t, key);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static enum CacheEntryType {
|
public static enum CacheEntryType {
|
||||||
OBJECT, SET, LIST;
|
OBJECT, SET, LIST;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ package org.redkale.source;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import org.redkale.util.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -86,36 +85,4 @@ public interface CacheSource<K extends Serializable, V extends Object> {
|
|||||||
return CompletableFuture.completedFuture(true);
|
return CompletableFuture.completedFuture(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------- AsyncHandler 异步版 ---------------------------------
|
|
||||||
public void existsAsync(final AsyncHandler<Boolean, K> handler, final K key);
|
|
||||||
|
|
||||||
public void getAsync(final AsyncHandler<V, K> handler, final K key);
|
|
||||||
|
|
||||||
public void getAndRefreshAsync(final AsyncHandler<V, K> handler, final K key, final int expireSeconds);
|
|
||||||
|
|
||||||
public void refreshAsync(final AsyncHandler<Void, K> handler, final K key, final int expireSeconds);
|
|
||||||
|
|
||||||
public void setAsync(final AsyncHandler<Void, K> handler, final K key, final V value);
|
|
||||||
|
|
||||||
public void setAsync(final AsyncHandler<Void, K> handler, final int expireSeconds, final K key, final V value);
|
|
||||||
|
|
||||||
public void setExpireSecondsAsync(final AsyncHandler<Void, K> handler, final K key, final int expireSeconds);
|
|
||||||
|
|
||||||
public void removeAsync(final AsyncHandler<Void, K> handler, final K key);
|
|
||||||
|
|
||||||
public void getCollectionAsync(final AsyncHandler<Collection<V>, K> handler, final K key);
|
|
||||||
|
|
||||||
public void getCollectionAndRefreshAsync(final AsyncHandler<Collection<V>, K> handler, final K key, final int expireSeconds);
|
|
||||||
|
|
||||||
public void appendListItemAsync(final AsyncHandler<Void, K> handler, final K key, final V value);
|
|
||||||
|
|
||||||
public void removeListItemAsync(final AsyncHandler<Void, K> handler, final K key, final V value);
|
|
||||||
|
|
||||||
public void appendSetItemAsync(final AsyncHandler<Void, K> handler, final K key, final V value);
|
|
||||||
|
|
||||||
public void removeSetItemAsync(final AsyncHandler<Void, K> handler, final K key, final V value);
|
|
||||||
|
|
||||||
default void isOpenAsync(final AsyncHandler<Boolean, Void> handler) {
|
|
||||||
if (handler != null) handler.completed(Boolean.TRUE, null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,7 @@
|
|||||||
package org.redkale.test.rest;
|
package org.redkale.test.rest;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import org.redkale.net.http.*;
|
import org.redkale.net.http.*;
|
||||||
|
|
||||||
@@ -77,7 +78,7 @@ public class HelloService implements Service {
|
|||||||
if (source != null) return source.queryList(HelloEntity.class, bean);
|
if (source != null) return source.queryList(HelloEntity.class, bean);
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
//查询单个
|
//查询单个
|
||||||
@RestMapping(name = "find")
|
@RestMapping(name = "find")
|
||||||
public HelloEntity findHello(@RestParam(name = "#") int id) { //通过 /pipes/hello/find/1234、/pipes/hello/jsfind/1234 查询对象
|
public HelloEntity findHello(@RestParam(name = "#") int id) { //通过 /pipes/hello/find/1234、/pipes/hello/jsfind/1234 查询对象
|
||||||
@@ -86,10 +87,7 @@ public class HelloService implements Service {
|
|||||||
|
|
||||||
//异步查询单个
|
//异步查询单个
|
||||||
@RestMapping(name = "asyncfind")
|
@RestMapping(name = "asyncfind")
|
||||||
public void findHello(AsyncHandler handler, @RestParam(name = "#") int id) { //通过 /pipes/hello/find/1234、/pipes/hello/jsfind/1234 查询对象
|
public CompletableFuture<HelloEntity> asyncFindHello(@RestParam(name = "#") int id) { //通过 /pipes/hello/find/1234、/pipes/hello/jsfind/1234 查询对象
|
||||||
if (source != null) source.findAsync(handler, HelloEntity.class, id);
|
return source.findAsync(HelloEntity.class, id);
|
||||||
HelloEntity rs = new HelloEntity();
|
|
||||||
rs.setHelloname("Hello名称");
|
|
||||||
if (handler != null) handler.completed(rs, null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,6 +133,6 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
|||||||
public void asyncfind(HttpRequest req, HttpResponse resp) throws IOException {
|
public void asyncfind(HttpRequest req, HttpResponse resp) throws IOException {
|
||||||
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||||
int id = Integer.parseInt(req.getRequstURILastPath());
|
int id = Integer.parseInt(req.getRequstURILastPath());
|
||||||
service.findHello(resp.createAsyncHandler(), id);
|
resp.finishJson(service.asyncFindHello(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user