Skip to content

Commit 7914e08

Browse files
authored
Add GlobalLockNodePath (#35020)
* Add GlobalLockNodePath * Add GlobalLockNodePath
1 parent f6bf118 commit 7914e08

File tree

3 files changed

+79
-6
lines changed

3 files changed

+79
-6
lines changed

mode/core/src/main/java/org/apache/shardingsphere/mode/lock/global/GlobalLockDefinition.java

+13-6
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,27 @@
1717

1818
package org.apache.shardingsphere.mode.lock.global;
1919

20-
import lombok.Getter;
2120
import org.apache.shardingsphere.infra.lock.LockDefinition;
21+
import org.apache.shardingsphere.mode.node.path.engine.generator.NodePathGenerator;
22+
import org.apache.shardingsphere.mode.node.path.type.lock.GlobalLockNodePath;
2223

2324
/**
2425
* Global lock definition.
2526
*/
26-
@Getter
2727
public final class GlobalLockDefinition implements LockDefinition {
2828

29-
private static final String KEY_PATTERN = "/lock/global/locks/%s";
30-
31-
private final String lockKey;
29+
private final GlobalLockNodePath nodePath;
3230

3331
public GlobalLockDefinition(final GlobalLock globalLock) {
34-
lockKey = String.format(KEY_PATTERN, globalLock.getName());
32+
nodePath = new GlobalLockNodePath(globalLock.getName());
33+
}
34+
35+
/**
36+
* Get lock key.
37+
*
38+
* @return lock key
39+
*/
40+
public String getLockKey() {
41+
return NodePathGenerator.toPath(nodePath);
3542
}
3643
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.shardingsphere.mode.node.path.type.lock;
19+
20+
import lombok.Getter;
21+
import lombok.RequiredArgsConstructor;
22+
import org.apache.shardingsphere.mode.node.path.NodePath;
23+
import org.apache.shardingsphere.mode.node.path.NodePathEntity;
24+
25+
/**
26+
* Global lock node path.
27+
*/
28+
@NodePathEntity("/lock/global/locks/${name}")
29+
@RequiredArgsConstructor
30+
@Getter
31+
public final class GlobalLockNodePath implements NodePath {
32+
33+
private final String name;
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.shardingsphere.mode.node.path.type.lock;
19+
20+
import org.apache.shardingsphere.mode.node.path.engine.generator.NodePathGenerator;
21+
import org.junit.jupiter.api.Test;
22+
23+
import static org.hamcrest.CoreMatchers.is;
24+
import static org.hamcrest.MatcherAssert.assertThat;
25+
26+
class GlobalLockNodePathTest {
27+
28+
@Test
29+
void assertToPath() {
30+
assertThat(NodePathGenerator.toPath(new GlobalLockNodePath("foo_lock")), is("/lock/global/locks/foo_lock"));
31+
}
32+
}

0 commit comments

Comments
 (0)