CacheSource增加flushdb方法

This commit is contained in:
redkale
2023-06-08 08:23:25 +08:00
parent 2e6ec01711
commit 685ae89685
4 changed files with 35 additions and 3 deletions

View File

@@ -1547,8 +1547,8 @@ public final class Application {
this.clusterAgent.start(); this.clusterAgent.start();
} }
if (this.messageAgents != null) { if (this.messageAgents != null) {
if (logger.isLoggable(Level.FINER)) { if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINER, "MessageAgent starting"); logger.log(Level.FINE, "MessageAgent starting");
} }
long s = System.currentTimeMillis(); long s = System.currentTimeMillis();
final StringBuffer sb = new StringBuffer(); final StringBuffer sb = new StringBuffer();

View File

@@ -643,6 +643,9 @@ public abstract class NodeServer {
} }
protected boolean acceptsComponent(Class<? extends Service> serviceImplClass) { protected boolean acceptsComponent(Class<? extends Service> serviceImplClass) {
if (Modifier.isAbstract(serviceImplClass.getModifiers()) || Modifier.isInterface(serviceImplClass.getModifiers())) {
return false;
}
if (MessageConsumer.class.isAssignableFrom(serviceImplClass)) { if (MessageConsumer.class.isAssignableFrom(serviceImplClass)) {
ResourceConsumer mqConsumer = serviceImplClass.getAnnotation(ResourceConsumer.class); ResourceConsumer mqConsumer = serviceImplClass.getAnnotation(ResourceConsumer.class);
if (mqConsumer == null) { if (mqConsumer == null) {
@@ -650,6 +653,7 @@ public abstract class NodeServer {
} }
MessageAgent mqAgent = application.getMessageAgent(mqConsumer.mq()); MessageAgent mqAgent = application.getMessageAgent(mqConsumer.mq());
if (mqAgent == null) { if (mqAgent == null) {
logger.info("not found MessageAgent(mq = " + mqConsumer.mq() + ")");
return false; return false;
} }
} }

View File

@@ -1812,6 +1812,26 @@ public final class CacheMemorySource extends AbstractCacheSource {
return container.size(); return container.size();
} }
@Override
public void flushdb() {
container.clear();
}
@Override
public CompletableFuture<Void> flushdbAsync() {
return CompletableFuture.runAsync(() -> flushdb(), getExecutor()).whenComplete(futureCompleteConsumer);
}
@Override
public void flushall() {
container.clear();
}
@Override
public CompletableFuture<Void> flushallAsync() {
return CompletableFuture.runAsync(() -> flushall(), getExecutor()).whenComplete(futureCompleteConsumer);
}
@Override @Override
public List<String> keys(String pattern) { public List<String> keys(String pattern) {
if (pattern == null || pattern.isEmpty()) { if (pattern == null || pattern.isEmpty()) {
@@ -1835,7 +1855,7 @@ public final class CacheMemorySource extends AbstractCacheSource {
return rs; return rs;
} }
} }
@Override @Override
public List<String> keysStartsWith(String startsWith) { public List<String> keysStartsWith(String startsWith) {
if (startsWith == null) { if (startsWith == null) {

View File

@@ -341,6 +341,10 @@ public interface CacheSource extends Resourcable {
public long dbsize(); public long dbsize();
public void flushdb();
public void flushall();
//---------------------- CompletableFuture 异步版 --------------------------------- //---------------------- CompletableFuture 异步版 ---------------------------------
default CompletableFuture<Boolean> isOpenAsync() { default CompletableFuture<Boolean> isOpenAsync() {
return CompletableFuture.completedFuture(isOpen()); return CompletableFuture.completedFuture(isOpen());
@@ -650,6 +654,10 @@ public interface CacheSource extends Resourcable {
public CompletableFuture<Long> dbsizeAsync(); public CompletableFuture<Long> dbsizeAsync();
public CompletableFuture<Void> flushdbAsync();
public CompletableFuture<Void> flushallAsync();
//-------------------------- 过期方法 ---------------------------------- //-------------------------- 过期方法 ----------------------------------
@Deprecated(since = "2.8.0") @Deprecated(since = "2.8.0")
public <T> Collection<T> getCollection(final String key, final Type componentType); public <T> Collection<T> getCollection(final String key, final Type componentType);