File tree 3 files changed +79
-6
lines changed
core/src/main/java/org/apache/shardingsphere/mode/lock/global
main/java/org/apache/shardingsphere/mode/node/path/type/lock
test/java/org/apache/shardingsphere/mode/node/path/type/lock
3 files changed +79
-6
lines changed Original file line number Diff line number Diff line change 17
17
18
18
package org .apache .shardingsphere .mode .lock .global ;
19
19
20
- import lombok .Getter ;
21
20
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 ;
22
23
23
24
/**
24
25
* Global lock definition.
25
26
*/
26
- @ Getter
27
27
public final class GlobalLockDefinition implements LockDefinition {
28
28
29
- private static final String KEY_PATTERN = "/lock/global/locks/%s" ;
30
-
31
- private final String lockKey ;
29
+ private final GlobalLockNodePath nodePath ;
32
30
33
31
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 );
35
42
}
36
43
}
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments