This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new f67b42f  Check if scaling is enabled in ProxyContext (#13289)
f67b42f is described below

commit f67b42fccdb67d8e634e228745ee6eb5c2cfc8c3
Author: Haoran Meng <[email protected]>
AuthorDate: Tue Oct 26 18:06:46 2021 +0800

    Check if scaling is enabled in ProxyContext (#13289)
---
 .../shardingsphere/proxy/backend/context/ProxyContext.java     | 10 ++++++++++
 .../apache/shardingsphere/scaling/core/api/ScalingWorker.java  |  5 +++++
 2 files changed, 15 insertions(+)

diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/context/ProxyContext.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/context/ProxyContext.java
index e6a8c2c..fe7558a 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/context/ProxyContext.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/context/ProxyContext.java
@@ -28,6 +28,7 @@ import org.apache.shardingsphere.infra.state.StateContext;
 import org.apache.shardingsphere.mode.manager.ContextManager;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.datasource.JDBCBackendDataSource;
 import 
org.apache.shardingsphere.proxy.backend.exception.NoDatabaseSelectedException;
+import org.apache.shardingsphere.scaling.core.api.ScalingWorker;
 
 import java.util.Collection;
 import java.util.LinkedList;
@@ -129,4 +130,13 @@ public final class ProxyContext {
         
result.addAll(contextManager.getMetaDataContexts().getGlobalRuleMetaData().getRules());
         return result;
     }
+    
+    /**
+     * Check if scaling is enabled.
+     * 
+     * @return true if scaling enabled, false if not
+     */
+    public boolean isScalingEnabled() {
+        return ScalingWorker.isEnabled();
+    }
 }
diff --git 
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/api/ScalingWorker.java
 
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/api/ScalingWorker.java
index 086cfb8..7483c21 100644
--- 
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/api/ScalingWorker.java
+++ 
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/api/ScalingWorker.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.scaling.core.api;
 
 import com.google.common.eventbus.Subscribe;
+import lombok.Getter;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
 import org.apache.shardingsphere.infra.yaml.config.pojo.YamlRootConfiguration;
@@ -45,6 +46,9 @@ public final class ScalingWorker {
     
     private static final ScalingWorker INSTANCE = new ScalingWorker();
     
+    @Getter
+    private static boolean enabled;
+    
     private final ScalingAPI scalingAPI = ScalingAPIFactory.getScalingAPI();
     
     /**
@@ -54,6 +58,7 @@ public final class ScalingWorker {
         ShardingSphereEventBus.getInstance().register(INSTANCE);
         new FinishedCheckJobExecutor().start();
         new ScalingJobExecutor().start();
+        enabled = true;
     }
     
     /**

Reply via email to