From e49c72fcf11654b26ddcda722907be78569e8c76 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Thu, 26 Dec 2024 23:21:27 +0800 Subject: [PATCH] Merge GlobalLockPersistService and LockPersistService (#34171) --- .../mode/lock/LockPersistService.java | 44 ------------------- .../service/GlobalLockPersistService.java | 17 +++++-- 2 files changed, 13 insertions(+), 48 deletions(-) delete mode 100644 mode/core/src/main/java/org/apache/shardingsphere/mode/lock/LockPersistService.java diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/lock/LockPersistService.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/lock/LockPersistService.java deleted file mode 100644 index 08c0ee4324eb5..0000000000000 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/lock/LockPersistService.java +++ /dev/null @@ -1,44 +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.mode.lock; - -import org.apache.shardingsphere.infra.lock.LockDefinition; - -/** - * Lock persist service. - * - * @param type of lock definition - */ -public interface LockPersistService { - - /** - * Try lock. - * - * @param lockDefinition lock definition - * @param timeoutMillis timeout millis - * @return is locked or not - */ - boolean tryLock(T lockDefinition, long timeoutMillis); - - /** - * Unlock. - * - * @param lockDefinition lock definition - */ - void unlock(T lockDefinition); -} diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/GlobalLockPersistService.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/GlobalLockPersistService.java index f20366e5e52a5..b3a92fd61e0c0 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/GlobalLockPersistService.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/GlobalLockPersistService.java @@ -19,23 +19,32 @@ import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.mode.lock.global.GlobalLockDefinition; -import org.apache.shardingsphere.mode.lock.LockPersistService; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; /** * Global lock persist service. */ @RequiredArgsConstructor -public final class GlobalLockPersistService implements LockPersistService { +public final class GlobalLockPersistService { private final ClusterPersistRepository repository; - @Override + /** + * Try lock. + * + * @param lockDefinition lock definition + * @param timeoutMillis timeout millis + * @return is locked or not + */ public boolean tryLock(final GlobalLockDefinition lockDefinition, final long timeoutMillis) { return repository.getDistributedLockHolder().getDistributedLock(lockDefinition.getLockKey()).tryLock(timeoutMillis); } - @Override + /** + * Unlock. + * + * @param lockDefinition lock definition + */ public void unlock(final GlobalLockDefinition lockDefinition) { repository.getDistributedLockHolder().getDistributedLock(lockDefinition.getLockKey()).unlock(); }