Skip to content

Commit e9f7e07

Browse files
author
Yegor Bugayenko
committed
#22 Lock.label()
1 parent 1409ee5 commit e9f7e07

4 files changed

Lines changed: 40 additions & 0 deletions

File tree

src/main/java/co/stateful/Lock.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ public interface Lock {
4949
*/
5050
String name();
5151

52+
/**
53+
* Read label (or empty text if lock doesn't exist).
54+
* @return Label of this lock (if the lock exists), or empty string
55+
* @throws IOException If any problem inside
56+
* @since 0.15
57+
*/
58+
String label() throws IOException;
59+
5260
/**
5361
* Lock with label.
5462
* @param label Label to attach

src/main/java/co/stateful/RtLock.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,23 @@ public String name() {
8080
return this.lck;
8181
}
8282

83+
@Override
84+
public String label() throws IOException {
85+
final long start = System.currentTimeMillis();
86+
final String label = this.front("label")
87+
.uri().queryParam("name", this.lck).back()
88+
.method(Request.GET)
89+
.fetch()
90+
.body();
91+
Logger.info(
92+
this, "label of \"%s\" retrieved in %[ms]s: \"%s\"",
93+
this.lck,
94+
System.currentTimeMillis() - start,
95+
label
96+
);
97+
return label;
98+
}
99+
83100
@Override
84101
public boolean lock(final String label) throws IOException {
85102
final long start = System.currentTimeMillis();

src/main/java/co/stateful/mock/MkLock.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ public String name() {
5353
return this.getClass().getName();
5454
}
5555

56+
@Override
57+
public String label() {
58+
return "label";
59+
}
60+
5661
@Override
5762
public boolean lock(final String label) {
5863
return true;

src/main/java/co/stateful/retry/ReLock.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ public String name() {
7575
return this.origin.name();
7676
}
7777

78+
@Override
79+
@RetryOnFailure
80+
(
81+
verbose = false, attempts = Tv.TWENTY,
82+
delay = Tv.TWENTY, unit = TimeUnit.SECONDS
83+
)
84+
public String label() throws IOException {
85+
return this.origin.label();
86+
}
87+
7888
@Override
7989
@RetryOnFailure
8090
(

0 commit comments

Comments
 (0)