You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by yx...@apache.org on 2022/04/30 16:37:05 UTC

[shardingsphere] branch master updated: Add OKProxyStateFactory (#17243)

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

yx9o 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 d443552ac0b Add OKProxyStateFactory (#17243)
d443552ac0b is described below

commit d443552ac0b30ea3c28cbce89eabc483bd7c4238
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sun May 1 00:36:58 2022 +0800

    Add OKProxyStateFactory (#17243)
---
 .../proxy/frontend/state/ProxyStateContext.java    |  8 ++--
 .../frontend/state/impl/OKProxyStateFactory.java   | 44 ++++++++++++++++++++++
 2 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/ProxyStateContext.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/ProxyStateContext.java
index 093614cdc33..086f8247eb5 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/ProxyStateContext.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/ProxyStateContext.java
@@ -28,8 +28,7 @@ import org.apache.shardingsphere.proxy.frontend.spi.DatabaseProtocolFrontendEngi
 import org.apache.shardingsphere.proxy.frontend.state.impl.CircuitBreakProxyState;
 import org.apache.shardingsphere.proxy.frontend.state.impl.LockProxyState;
 import org.apache.shardingsphere.proxy.frontend.state.impl.OKProxyState;
-import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.spi.type.typed.TypedSPIRegistry;
+import org.apache.shardingsphere.proxy.frontend.state.impl.OKProxyStateFactory;
 
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -49,9 +48,8 @@ public final class ProxyStateContext {
     }
     
     private static OKProxyState determineOKProxyState() {
-        ShardingSphereServiceLoader.register(OKProxyState.class);
-        String proxyBackendDriverType = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps().getValue(ConfigurationPropertyKey.PROXY_BACKEND_DRIVER_TYPE);
-        return TypedSPIRegistry.getRegisteredService(OKProxyState.class, proxyBackendDriverType);
+        String backendDriverType = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps().getValue(ConfigurationPropertyKey.PROXY_BACKEND_DRIVER_TYPE);
+        return OKProxyStateFactory.newInstance(backendDriverType);
     }
     
     /**
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyStateFactory.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyStateFactory.java
new file mode 100644
index 00000000000..9e01a53f0cf
--- /dev/null
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyStateFactory.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.proxy.frontend.state.impl;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.spi.type.typed.TypedSPIRegistry;
+
+/**
+ * OK proxy state factory.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class OKProxyStateFactory {
+    
+    static {
+        ShardingSphereServiceLoader.register(OKProxyState.class);
+    }
+    
+    /**
+     * Create new instance of OK proxy state.
+     * 
+     * @param type type
+     * @return OK proxy state
+     */
+    public static OKProxyState newInstance(final String type) {
+        return TypedSPIRegistry.getRegisteredService(OKProxyState.class, type);
+    }
+}