You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by qi...@apache.org on 2021/02/01 07:40:45 UTC
[shardingsphere] branch master updated: Remove useless class (#9248)
This is an automated email from the ASF dual-hosted git repository.
qiulu 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 419b070 Remove useless class (#9248)
419b070 is described below
commit 419b07083ca00a3fbd7d3db80f879fc21e9065d4
Author: Haoran Meng <me...@gmail.com>
AuthorDate: Mon Feb 1 15:40:24 2021 +0800
Remove useless class (#9248)
---
.../core/lock/strategy/GovernanceLockStrategy.java | 85 ----------------------
...g.apache.shardingsphere.infra.lock.LockStrategy | 18 -----
...egyTest.java => GovernanceLockContextTest.java} | 16 ++--
.../shardingsphere/infra/lock/LockStrategy.java | 42 -----------
.../infra/lock/LockStrategyType.java | 26 -------
.../infra/lock/StandardLockStrategy.java | 59 ---------------
...g.apache.shardingsphere.infra.lock.LockStrategy | 18 -----
...ategyTest.java => StandardLockContextTest.java} | 12 +--
.../infra/lock/fixture/FixtureLockStrategy.java | 40 ----------
...g.apache.shardingsphere.infra.lock.LockStrategy | 18 -----
10 files changed, 13 insertions(+), 321 deletions(-)
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/lock/strategy/GovernanceLockStrategy.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/lock/strategy/GovernanceLockStrategy.java
deleted file mode 100644
index f573a0f..0000000
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/lock/strategy/GovernanceLockStrategy.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * 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.governance.core.lock.strategy;
-
-import com.google.common.eventbus.Subscribe;
-import org.apache.shardingsphere.governance.core.event.model.lock.GlobalLockAddedEvent;
-import org.apache.shardingsphere.governance.core.registry.RegistryCenter;
-import org.apache.shardingsphere.governance.core.registry.RegistryCenterNodeStatus;
-import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
-import org.apache.shardingsphere.infra.lock.LockStrategy;
-import org.apache.shardingsphere.infra.lock.LockStrategyType;
-import org.apache.shardingsphere.infra.state.StateContext;
-import org.apache.shardingsphere.infra.state.StateEvent;
-import org.apache.shardingsphere.infra.state.StateType;
-
-import java.util.concurrent.TimeUnit;
-
-/**
- * Governance lock strategy.
- */
-public final class GovernanceLockStrategy implements LockStrategy {
-
- private RegistryCenter registryCenter;
-
- /**
- * Init governance lock strategy.
- *
- * @param registryCenter registry center
- */
- public void init(final RegistryCenter registryCenter) {
- this.registryCenter = registryCenter;
- ShardingSphereEventBus.getInstance().register(this);
- }
-
- @Override
- public boolean tryGlobalLock(final long timeout, final TimeUnit timeUnit) {
- return registryCenter.tryGlobalLock(timeout, timeUnit);
- }
-
- @Override
- public void releaseGlobalLock() {
- registryCenter.releaseGlobalLock();
- }
-
- @Override
- public String getType() {
- return LockStrategyType.GOVERNANCE.name();
- }
-
- /**
- * Switch state.
- *
- * @param event state event
- */
- @Subscribe
- public void switchState(final StateEvent event) {
- StateContext.switchState(event);
- }
-
- /**
- * Lock instance after global lock added.
- *
- * @param event global lock added event
- */
- @Subscribe
- public void doLock(final GlobalLockAddedEvent event) {
- StateContext.switchState(new StateEvent(StateType.LOCK, true));
- registryCenter.persistInstanceData(RegistryCenterNodeStatus.LOCKED.toString());
- }
-}
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.lock.LockStrategy b/shardingsphere-governance/shardingsphere-governance-core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.lock.LockStrategy
deleted file mode 100644
index 27a4d7d..0000000
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.lock.LockStrategy
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# 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.
-#
-
-org.apache.shardingsphere.governance.core.lock.strategy.GovernanceLockStrategy
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/lock/strategy/GovernanceLockStrategyTest.java b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/lock/GovernanceLockContextTest.java
similarity index 75%
rename from shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/lock/strategy/GovernanceLockStrategyTest.java
rename to shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/lock/GovernanceLockContextTest.java
index de1cd04..e005ddf 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/lock/strategy/GovernanceLockStrategyTest.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/lock/GovernanceLockContextTest.java
@@ -15,11 +15,10 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.governance.core.lock.strategy;
+package org.apache.shardingsphere.governance.core.lock;
import org.apache.shardingsphere.governance.core.registry.RegistryCenter;
-import org.apache.shardingsphere.governance.core.registry.util.FieldUtil;
-import org.apache.shardingsphere.infra.lock.LockStrategy;
+import org.apache.shardingsphere.infra.lock.LockContext;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -32,28 +31,27 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
@RunWith(MockitoJUnitRunner.class)
-public final class GovernanceLockStrategyTest {
+public final class GovernanceLockContextTest {
@Mock
private RegistryCenter registryCenter;
- private LockStrategy lockStrategy;
+ private LockContext lockContext;
@Before
public void setUp() {
- lockStrategy = new GovernanceLockStrategy();
- FieldUtil.setField(lockStrategy, "registryCenter", registryCenter);
+ lockContext = new GovernanceLockContext(registryCenter);
}
@Test
public void assertTryLock() {
- lockStrategy.tryGlobalLock(50L, TimeUnit.MILLISECONDS);
+ lockContext.tryGlobalLock(50L, TimeUnit.MILLISECONDS);
verify(registryCenter).tryGlobalLock(eq(50L), eq(TimeUnit.MILLISECONDS));
}
@Test
public void assertReleaseLock() {
- lockStrategy.releaseGlobalLock();
+ lockContext.releaseGlobalLock();
verify(registryCenter).releaseGlobalLock();
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/LockStrategy.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/LockStrategy.java
deleted file mode 100644
index 66284e6..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/LockStrategy.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.infra.lock;
-
-import org.apache.shardingsphere.infra.spi.typed.TypedSPI;
-
-import java.util.concurrent.TimeUnit;
-
-/**
- * Lock strategy.
- */
-public interface LockStrategy extends TypedSPI {
-
- /**
- * Try to get lock.
- *
- * @param timeout the maximum time in milliseconds to acquire lock
- * @param timeUnit time unit
- * @return true if get the lock, false if not
- */
- boolean tryGlobalLock(long timeout, TimeUnit timeUnit);
-
- /**
- * Release lock.
- */
- void releaseGlobalLock();
-}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/LockStrategyType.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/LockStrategyType.java
deleted file mode 100644
index 240cc12..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/LockStrategyType.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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.infra.lock;
-
-/**
- * Lock strategy type.
- */
-public enum LockStrategyType {
-
- STANDARD, GOVERNANCE
-}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/StandardLockStrategy.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/StandardLockStrategy.java
deleted file mode 100644
index 303a00b..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/StandardLockStrategy.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.infra.lock;
-
-import org.apache.shardingsphere.infra.state.StateContext;
-import org.apache.shardingsphere.infra.state.StateEvent;
-import org.apache.shardingsphere.infra.state.StateType;
-
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.ReentrantLock;
-
-/**
- * Standard lock strategy.
- */
-public final class StandardLockStrategy implements LockStrategy {
-
- private final ReentrantLock lock = new ReentrantLock();
-
- @Override
- public boolean tryGlobalLock(final long timeout, final TimeUnit timeUnit) {
- boolean result = false;
- try {
- result = lock.tryLock(timeout, timeUnit);
- // CHECKSTYLE:OFF
- } catch (final InterruptedException e) {
- // CHECKSTYLE:ON
- }
- if (result) {
- StateContext.switchState(new StateEvent(StateType.LOCK, true));
- }
- return result;
- }
-
- @Override
- public void releaseGlobalLock() {
- lock.unlock();
- StateContext.switchState(new StateEvent(StateType.LOCK, false));
- }
-
- @Override
- public String getType() {
- return LockStrategyType.STANDARD.name();
- }
-}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.lock.LockStrategy b/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.lock.LockStrategy
deleted file mode 100644
index 4ea7904..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.lock.LockStrategy
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# 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.
-#
-
-org.apache.shardingsphere.infra.lock.StandardLockStrategy
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/lock/StandardLockStrategyTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/lock/StandardLockContextTest.java
similarity index 80%
rename from shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/lock/StandardLockStrategyTest.java
rename to shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/lock/StandardLockContextTest.java
index aa4c66a..89f5560 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/lock/StandardLockStrategyTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/lock/StandardLockContextTest.java
@@ -27,22 +27,22 @@ import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
-public final class StandardLockStrategyTest {
+public final class StandardLockContextTest {
- private final StandardLockStrategy lockStrategy = new StandardLockStrategy();
+ private final StandardLockContext lockContext = new StandardLockContext();
@Test
public void assertTryLock() {
- assertTrue(lockStrategy.tryGlobalLock(50L, TimeUnit.MILLISECONDS));
+ assertTrue(lockContext.tryGlobalLock(50L, TimeUnit.MILLISECONDS));
assertThat(StateContext.getCurrentState(), is(StateType.LOCK));
- lockStrategy.releaseGlobalLock();
+ lockContext.releaseGlobalLock();
}
@Test
public void assertReleaseLock() {
- assertTrue(lockStrategy.tryGlobalLock(50L, TimeUnit.MILLISECONDS));
+ assertTrue(lockContext.tryGlobalLock(50L, TimeUnit.MILLISECONDS));
assertThat(StateContext.getCurrentState(), is(StateType.LOCK));
- lockStrategy.releaseGlobalLock();
+ lockContext.releaseGlobalLock();
assertThat(StateContext.getCurrentState(), is(StateType.OK));
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/lock/fixture/FixtureLockStrategy.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/lock/fixture/FixtureLockStrategy.java
deleted file mode 100644
index c04d4b2..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/lock/fixture/FixtureLockStrategy.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.infra.lock.fixture;
-
-import org.apache.shardingsphere.infra.lock.LockStrategy;
-import org.apache.shardingsphere.infra.lock.LockStrategyType;
-
-import java.util.concurrent.TimeUnit;
-
-public final class FixtureLockStrategy implements LockStrategy {
-
- @Override
- public String getType() {
- return LockStrategyType.STANDARD.name();
- }
-
- @Override
- public boolean tryGlobalLock(final long timeout, final TimeUnit timeUnit) {
- return false;
- }
-
- @Override
- public void releaseGlobalLock() {
- }
-}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.lock.LockStrategy b/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.lock.LockStrategy
deleted file mode 100644
index e150e66..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.lock.LockStrategy
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# 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.
-#
-
-org.apache.shardingsphere.infra.lock.fixture.FixtureLockStrategy