Skip to content

Commit bd96ced

Browse files
committed
#25 polish
1 parent c460ac2 commit bd96ced

36 files changed

+121
-119
lines changed

pom.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
159159
<version>4.0.1</version>
160160
</dependency>
161161
<dependency>
162-
<groupId>com.sun.grizzly</groupId>
163-
<artifactId>grizzly-servlet-webserver</artifactId>
164-
<version>1.9.65</version>
162+
<groupId>org.glassfish.grizzly</groupId>
163+
<artifactId>grizzly-http-servlet-server</artifactId>
164+
<version>2.4.4</version>
165165
<scope>test</scope>
166166
</dependency>
167167
<dependency>
@@ -209,10 +209,11 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
209209
<plugin>
210210
<groupId>com.qulice</groupId>
211211
<artifactId>qulice-maven-plugin</artifactId>
212-
<version>0.16.2</version>
212+
<version>0.22.0</version>
213213
<configuration>
214214
<excludes combine.children="append">
215215
<exclude>findbugs:.*</exclude>
216+
<exclude>duplicatefinder:.*</exclude>
216217
</excludes>
217218
</configuration>
218219
</plugin>

src/main/java/co/stateful/Atomic.java

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright (c) 2014-2023, stateful.co
33
* All rights reserved.
44
*
@@ -61,8 +61,6 @@
6161
* {@link java.util.concurrent.Executors#callable(Runnable)}. If you
6262
* want to avoid checked exceptions, use {@link #callQuietly()}.
6363
*
64-
* @author Yegor Bugayenko (yegor@tpc2.com)
65-
* @version $Id$
6664
* @since 0.6
6765
* @param <T> Type of result
6866
* @see <a href="http://www.yegor256.com/2014/05/18/cloud-autoincrement-counters.html">Atomic Counters at Stateful.co</a>
@@ -143,14 +141,11 @@ public Atomic(final Callable<T> clbl, final Lock lck, final String lbl,
143141
@Override
144142
public T call() throws Exception {
145143
final Thread hook = new Thread(
146-
new Runnable() {
147-
@Override
148-
public void run() {
149-
try {
150-
Atomic.this.lock.unlock(Atomic.this.label);
151-
} catch (final IOException ex) {
152-
throw new IllegalStateException(ex);
153-
}
144+
() -> {
145+
try {
146+
this.lock.unlock(this.label);
147+
} catch (final IOException ex) {
148+
throw new IllegalStateException(ex);
154149
}
155150
}
156151
);
@@ -162,7 +157,6 @@ public void run() {
162157
if (age > this.max) {
163158
throw new IllegalStateException(
164159
Logger.format(
165-
// @checkstyle LineLength (1 line)
166160
"lock \"%s\" is stale (%d failed attempts in %[ms]s, which is over %[ms]s)",
167161
this.lock, attempt, age, this.max
168162
)
@@ -173,13 +167,11 @@ public void run() {
173167
TimeUnit.MINUTES.toMillis(1L),
174168
Math.abs(
175169
100L + (long) Atomic.RANDOM.nextInt(100)
176-
// @checkstyle MagicNumber (1 line)
177170
+ (long) StrictMath.pow(5.0d, (double) attempt + 1.0d)
178171
)
179172
);
180173
Logger.info(
181174
this,
182-
// @checkstyle LineLength (1 line)
183175
"lock \"%s\" is occupied for %[ms]s already, attempt #%d in %[ms]s",
184176
this.lock, age, attempt, delay
185177
);
@@ -193,12 +185,13 @@ public void run() {
193185
this.lock.unlock(this.label);
194186
}
195187
Runtime.getRuntime().removeShutdownHook(hook);
196-
Logger.info(
197-
this,
198-
// @checkstyle LineLength (1 line)
199-
"\"%s\" took %[ms]s after %d attempt(s)",
200-
this.lock, System.currentTimeMillis() - start, attempt + 1L
201-
);
188+
if (Logger.isInfoEnabled(this)) {
189+
Logger.info(
190+
this,
191+
"\"%s\" took %[ms]s after %d attempt(s)",
192+
this.lock, System.currentTimeMillis() - start, attempt + 1L
193+
);
194+
}
202195
}
203196
}
204197

src/main/java/co/stateful/Counter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright (c) 2014-2023, stateful.co
33
* All rights reserved.
44
*

src/main/java/co/stateful/Counters.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright (c) 2014-2023, stateful.co
33
* All rights reserved.
44
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright (c) 2014-2023, stateful.co
33
* All rights reserved.
44
*

src/main/java/co/stateful/Locks.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright (c) 2014-2023, stateful.co
33
* All rights reserved.
44
*

src/main/java/co/stateful/RtCounter.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright (c) 2014-2023, stateful.co
33
* All rights reserved.
44
*
@@ -87,11 +87,13 @@ public void set(final long value) throws IOException {
8787
.fetch()
8888
.as(RestResponse.class)
8989
.assertStatus(HttpURLConnection.HTTP_OK);
90-
Logger.info(
91-
this, "counter \"%s\" set to %d in %[ms]s",
92-
this.label, value,
93-
System.currentTimeMillis() - start
94-
);
90+
if (Logger.isInfoEnabled(this)) {
91+
Logger.info(
92+
this, "counter \"%s\" set to %d in %[ms]s",
93+
this.label, value,
94+
System.currentTimeMillis() - start
95+
);
96+
}
9597
}
9698

9799
@Override
@@ -106,11 +108,13 @@ public long incrementAndGet(final long delta) throws IOException {
106108
.assertStatus(HttpURLConnection.HTTP_OK)
107109
.body()
108110
);
109-
Logger.info(
110-
this, "counter \"%s\" incremented by %d to %d in %[ms]s",
111-
this.label, delta, value,
112-
System.currentTimeMillis() - start
113-
);
111+
if (Logger.isInfoEnabled(this)) {
112+
Logger.info(
113+
this, "counter \"%s\" incremented by %d to %d in %[ms]s",
114+
this.label, delta, value,
115+
System.currentTimeMillis() - start
116+
);
117+
}
114118
return value;
115119
}
116120

src/main/java/co/stateful/RtCounters.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright (c) 2014-2023, stateful.co
33
* All rights reserved.
44
*
@@ -88,10 +88,12 @@ public Counter create(final String name) throws IOException {
8888
.fetch()
8989
.as(RestResponse.class)
9090
.assertStatus(HttpURLConnection.HTTP_SEE_OTHER);
91-
Logger.info(
92-
this, "counter \"%s\" created in %[ms]s",
93-
name, System.currentTimeMillis() - start
94-
);
91+
if (Logger.isInfoEnabled(this)) {
92+
Logger.info(
93+
this, "counter \"%s\" created in %[ms]s",
94+
name, System.currentTimeMillis() - start
95+
);
96+
}
9597
return this.get(name);
9698
}
9799

@@ -113,10 +115,12 @@ public void delete(final String name) throws IOException {
113115
.fetch()
114116
.as(RestResponse.class)
115117
.assertStatus(HttpURLConnection.HTTP_SEE_OTHER);
116-
Logger.info(
117-
this, "counter \"%s\" deleted in %[ms]s",
118-
name, System.currentTimeMillis() - start
119-
);
118+
if (Logger.isInfoEnabled(this)) {
119+
Logger.info(
120+
this, "counter \"%s\" deleted in %[ms]s",
121+
name, System.currentTimeMillis() - start
122+
);
123+
}
120124
}
121125

122126
@Override

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

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright (c) 2014-2023, stateful.co
33
* All rights reserved.
44
*
@@ -86,12 +86,14 @@ public String label() throws IOException {
8686
.method(Request.GET)
8787
.fetch()
8888
.body();
89-
Logger.info(
90-
this, "label of \"%s\" retrieved in %[ms]s: \"%s\"",
91-
this.lck,
92-
System.currentTimeMillis() - start,
93-
label
94-
);
89+
if (Logger.isInfoEnabled(this)) {
90+
Logger.info(
91+
this, "label of \"%s\" retrieved in %[ms]s: \"%s\"",
92+
this.lck,
93+
System.currentTimeMillis() - start,
94+
label
95+
);
96+
}
9597
return label;
9698
}
9799

@@ -104,12 +106,14 @@ public boolean lock(final String label) throws IOException {
104106
.method(Request.POST)
105107
.fetch();
106108
final boolean locked = rsp.status() == HttpURLConnection.HTTP_SEE_OTHER;
107-
Logger.info(
108-
this, "lock of \"%s\" is %B in %[ms]s: %s",
109-
this.lck, locked,
110-
System.currentTimeMillis() - start,
111-
rsp.body()
112-
);
109+
if (Logger.isInfoEnabled(this)) {
110+
Logger.info(
111+
this, "lock of \"%s\" is %B in %[ms]s: %s",
112+
this.lck, locked,
113+
System.currentTimeMillis() - start,
114+
rsp.body()
115+
);
116+
}
113117
return locked;
114118
}
115119

@@ -123,11 +127,13 @@ public boolean unlock(final String label) throws IOException {
123127
.fetch();
124128
final boolean unlocked =
125129
rsp.status() == HttpURLConnection.HTTP_SEE_OTHER;
126-
Logger.info(
127-
this, "unlock of \"%s\" is %B in %[ms]s",
128-
this.lck, unlocked,
129-
System.currentTimeMillis() - start
130-
);
130+
if (Logger.isInfoEnabled(this)) {
131+
Logger.info(
132+
this, "unlock of \"%s\" is %B in %[ms]s",
133+
this.lck, unlocked,
134+
System.currentTimeMillis() - start
135+
);
136+
}
131137
return unlocked;
132138
}
133139

src/main/java/co/stateful/RtLocks.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright (c) 2014-2023, stateful.co
33
* All rights reserved.
44
*

0 commit comments

Comments
 (0)