You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2021/03/01 12:08:47 UTC

[shardingsphere] branch master updated: Remove timeunit by method signature (#9551)

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

zhangyonglun 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 8036178  Remove timeunit by method signature (#9551)
8036178 is described below

commit 80361784809c92a25da4d3a3cad542c91122203a
Author: Liang Zhang <te...@163.com>
AuthorDate: Mon Mar 1 20:08:17 2021 +0800

    Remove timeunit by method signature (#9551)
---
 .../governance/core/lock/GovernanceLock.java           |  6 ++----
 .../governance/core/registry/RegistryCenter.java       |  5 ++---
 .../governance/core/lock/GovernanceLockTest.java       |  6 ++----
 .../governance/core/registry/RegistryCenterTest.java   |  2 +-
 .../infra/lock/AbstractShardingSphereLock.java         |  4 ++--
 .../shardingsphere/infra/lock/ShardingSphereLock.java  | 18 +++++++-----------
 .../apache/shardingsphere/infra/lock/StandardLock.java |  4 ++--
 .../shardingsphere/infra/lock/StandardLockTest.java    |  6 ++----
 .../driver/executor/DriverJDBCExecutor.java            |  3 +--
 .../internal/state/impl/LockDriverState.java           |  3 +--
 .../communication/DatabaseCommunicationEngine.java     |  3 +--
 .../proxy/frontend/state/impl/LockProxyState.java      |  3 +--
 12 files changed, 24 insertions(+), 39 deletions(-)

diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/lock/GovernanceLock.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/lock/GovernanceLock.java
index c376331..8ba03e6 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/lock/GovernanceLock.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/lock/GovernanceLock.java
@@ -27,8 +27,6 @@ import org.apache.shardingsphere.infra.lock.AbstractShardingSphereLock;
 import org.apache.shardingsphere.infra.state.StateEvent;
 import org.apache.shardingsphere.infra.state.StateType;
 
-import java.util.concurrent.TimeUnit;
-
 /**
  * Governance lock.
  */
@@ -42,8 +40,8 @@ public final class GovernanceLock extends AbstractShardingSphereLock {
     }
     
     @Override
-    public boolean tryGlobalLock(final long timeout, final TimeUnit timeUnit) {
-        return registryCenter.tryGlobalLock(timeout, timeUnit);
+    public boolean tryGlobalLock(final long timeoutMilliseconds) {
+        return registryCenter.tryGlobalLock(timeoutMilliseconds);
     }
     
     @Override
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java
index 591fe78..16b931a 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenter.java
@@ -157,11 +157,10 @@ public final class RegistryCenter {
      * Try to get global lock.
      *
      * @param timeout the maximum time in milliseconds to acquire lock
-     * @param timeUnit time unit
      * @return true if get the lock, false if not
      */
-    public boolean tryGlobalLock(final long timeout, final TimeUnit timeUnit) {
-        return repository.tryLock(lockNode.getGlobalLockNodePath(), timeout, timeUnit) && checkLock();
+    public boolean tryGlobalLock(final long timeout) {
+        return repository.tryLock(lockNode.getGlobalLockNodePath(), timeout, TimeUnit.MILLISECONDS) && checkLock();
     }
     
     /**
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/lock/GovernanceLockTest.java b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/lock/GovernanceLockTest.java
index fde7cd3..4e3735a 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/lock/GovernanceLockTest.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/lock/GovernanceLockTest.java
@@ -25,8 +25,6 @@ import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
 
-import java.util.concurrent.TimeUnit;
-
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.verify;
 
@@ -45,8 +43,8 @@ public final class GovernanceLockTest {
     
     @Test
     public void assertTryLock() {
-        lock.tryGlobalLock(50L, TimeUnit.MILLISECONDS);
-        verify(registryCenter).tryGlobalLock(eq(50L), eq(TimeUnit.MILLISECONDS));
+        lock.tryGlobalLock(50L);
+        verify(registryCenter).tryGlobalLock(eq(50L));
     }
     
     @Test
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java
index d23575b..40e14f3 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterTest.java
@@ -86,7 +86,7 @@ public final class RegistryCenterTest {
     
     @Test
     public void assertTryGlobalLock() {
-        registryCenter.tryGlobalLock(50L, TimeUnit.MILLISECONDS);
+        registryCenter.tryGlobalLock(50L);
         verify(registryRepository).tryLock(eq(new LockNode().getGlobalLockNodePath()), eq(50L), eq(TimeUnit.MILLISECONDS));
     }
     
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/AbstractShardingSphereLock.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/AbstractShardingSphereLock.java
index 9994431..b61a553 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/AbstractShardingSphereLock.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/AbstractShardingSphereLock.java
@@ -32,10 +32,10 @@ public abstract class AbstractShardingSphereLock implements ShardingSphereLock {
     private final Condition innerCondition = innerLock.newCondition();
     
     @Override
-    public final boolean await(final Long timeout, final TimeUnit timeUnit) {
+    public final boolean await(final Long timeoutMilliseconds) {
         innerLock.lock();
         try {
-            return innerCondition.await(timeout, TimeUnit.MILLISECONDS);
+            return innerCondition.await(timeoutMilliseconds, TimeUnit.MILLISECONDS);
         } catch (final InterruptedException ignored) {
         } finally {
             innerLock.unlock();
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/ShardingSphereLock.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/ShardingSphereLock.java
index 7c2b868..08487e4 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/ShardingSphereLock.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/ShardingSphereLock.java
@@ -17,21 +17,18 @@
 
 package org.apache.shardingsphere.infra.lock;
 
-import java.util.concurrent.TimeUnit;
-
 /**
  * ShardingSphere lock.
  */
 public interface ShardingSphereLock {
     
     /**
-     * Try to get lock.
+     * Try to lock.
      *
-     * @param timeout time out to acquire lock
-     * @param timeUnit time unit
+     * @param timeoutMilliseconds time out milliseconds to acquire lock
      * @return true if get the lock, false if not
      */
-    boolean tryGlobalLock(long timeout, TimeUnit timeUnit);
+    boolean tryGlobalLock(long timeoutMilliseconds);
     
     /**
      * Release lock.
@@ -39,16 +36,15 @@ public interface ShardingSphereLock {
     void releaseGlobalLock();
     
     /**
-     * Await.
+     * Await lock.
      * 
-     * @param timeout time out to await lock
-     * @param timeUnit  time unit
+     * @param timeoutMilliseconds time out milliseconds to await lock
      * @return true if no exception
      */
-    boolean await(Long timeout, TimeUnit timeUnit);
+    boolean await(Long timeoutMilliseconds);
     
     /**
-     * signal all.
+     * Signal all.
      */
     void signalAll();
 }
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/StandardLock.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/StandardLock.java
index 9d7580a..14c63e1 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/StandardLock.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/StandardLock.java
@@ -32,10 +32,10 @@ public final class StandardLock extends AbstractShardingSphereLock {
     private final ReentrantLock lock = new ReentrantLock();
     
     @Override
-    public boolean tryGlobalLock(final long timeout, final TimeUnit timeUnit) {
+    public boolean tryGlobalLock(final long timeoutMilliseconds) {
         boolean result = false;
         try {
-            result = lock.tryLock(timeout, timeUnit);
+            result = lock.tryLock(timeoutMilliseconds, TimeUnit.MILLISECONDS);
         } catch (final InterruptedException ignored) {
         }
         if (result) {
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/lock/StandardLockTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/lock/StandardLockTest.java
index c87c002..72df9a1 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/lock/StandardLockTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/lock/StandardLockTest.java
@@ -19,8 +19,6 @@ package org.apache.shardingsphere.infra.lock;
 
 import org.junit.Test;
 
-import java.util.concurrent.TimeUnit;
-
 import static org.junit.Assert.assertTrue;
 
 public final class StandardLockTest {
@@ -29,13 +27,13 @@ public final class StandardLockTest {
     
     @Test
     public void assertTryLock() {
-        assertTrue(lock.tryGlobalLock(50L, TimeUnit.MILLISECONDS));
+        assertTrue(lock.tryGlobalLock(50L));
         lock.releaseGlobalLock();
     }
     
     @Test
     public void assertReleaseLock() {
-        assertTrue(lock.tryGlobalLock(50L, TimeUnit.MILLISECONDS));
+        assertTrue(lock.tryGlobalLock(50L));
         lock.releaseGlobalLock();
     }
 }
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/DriverJDBCExecutor.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/DriverJDBCExecutor.java
index 84c1000..741d86f 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/DriverJDBCExecutor.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/DriverJDBCExecutor.java
@@ -50,7 +50,6 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
-import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 /**
@@ -136,7 +135,7 @@ public final class DriverJDBCExecutor {
     
     private boolean tryGlobalLock(final SQLStatement sqlStatement, final long lockTimeoutMilliseconds) {
         if (needLock(sqlStatement)) {
-            if (!metaDataContexts.getLock().tryGlobalLock(lockTimeoutMilliseconds, TimeUnit.MILLISECONDS)) {
+            if (!metaDataContexts.getLock().tryGlobalLock(lockTimeoutMilliseconds)) {
                 throw new ShardingSphereException("Service lock wait timeout of %s ms exceeded", lockTimeoutMilliseconds);
             }
             return true;
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/impl/LockDriverState.java b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/impl/LockDriverState.java
index b0925e3..48bf050 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/impl/LockDriverState.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/impl/LockDriverState.java
@@ -28,7 +28,6 @@ import org.apache.shardingsphere.transaction.core.TransactionType;
 import javax.sql.DataSource;
 import java.sql.Connection;
 import java.util.Map;
-import java.util.concurrent.TimeUnit;
 
 /**
  * Lock driver state.
@@ -44,7 +43,7 @@ public final class LockDriverState implements DriverState {
     
     private void block(final MetaDataContexts metaDataContexts) {
         long lockTimeoutMilliseconds = metaDataContexts.getProps().<Long>getValue(ConfigurationPropertyKey.LOCK_WAIT_TIMEOUT_MILLISECONDS);
-        if (!metaDataContexts.getLock().await(lockTimeoutMilliseconds, TimeUnit.MILLISECONDS)) {
+        if (!metaDataContexts.getLock().await(lockTimeoutMilliseconds)) {
             throw new ShardingSphereException("Service lock wait timeout of %s ms exceeded", lockTimeoutMilliseconds); 
         }
     }
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
index fa9cbca..811640a 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
@@ -53,7 +53,6 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Optional;
-import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 /**
@@ -122,7 +121,7 @@ public final class DatabaseCommunicationEngine {
     
     private boolean tryGlobalLock(final ExecutionContext executionContext, final Long lockTimeoutMilliseconds) {
         if (needLock(executionContext.getSqlStatementContext().getSqlStatement())) {
-            if (!ProxyContext.getInstance().getLock().tryGlobalLock(lockTimeoutMilliseconds, TimeUnit.MILLISECONDS)) {
+            if (!ProxyContext.getInstance().getLock().tryGlobalLock(lockTimeoutMilliseconds)) {
                 throw new LockWaitTimeoutException(lockTimeoutMilliseconds);
             }
             return true;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/LockProxyState.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/LockProxyState.java
index 43a2a78..cdf5807 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/LockProxyState.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/LockProxyState.java
@@ -30,7 +30,6 @@ import org.apache.shardingsphere.proxy.frontend.state.ProxyState;
 import org.apache.shardingsphere.proxy.frontend.state.ProxyStateContext;
 
 import java.util.Optional;
-import java.util.concurrent.TimeUnit;
 
 /**
  * Lock proxy state.
@@ -46,7 +45,7 @@ public final class LockProxyState implements ProxyState {
     
     private void block(final ChannelHandlerContext context, final DatabaseProtocolFrontendEngine databaseProtocolFrontendEngine) {
         Long lockTimeoutMilliseconds = ProxyContext.getInstance().getMetaDataContexts().getProps().<Long>getValue(ConfigurationPropertyKey.LOCK_WAIT_TIMEOUT_MILLISECONDS);
-        if (!ProxyContext.getInstance().getLock().await(lockTimeoutMilliseconds, TimeUnit.MILLISECONDS)) {
+        if (!ProxyContext.getInstance().getLock().await(lockTimeoutMilliseconds)) {
             doError(context, databaseProtocolFrontendEngine, new LockWaitTimeoutException(lockTimeoutMilliseconds));
         }
     }