Skip to content

Commit

Permalink
spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
Saphri committed Nov 19, 2024
1 parent 0614d75 commit 44ea2c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ public final class NatsJetStreamLock extends AbstractSimpleLock {

private final NatsJetStreamLockProvider natsJetStreamLockProvider;

protected NatsJetStreamLock(@NonNull LockConfiguration lockConfiguration, @NonNull NatsJetStreamLockProvider natsJetStreamLockProvider) {
protected NatsJetStreamLock(
@NonNull LockConfiguration lockConfiguration,
@NonNull NatsJetStreamLockProvider natsJetStreamLockProvider) {
super(lockConfiguration);
this.natsJetStreamLockProvider = natsJetStreamLockProvider;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package net.javacrumbs.shedlock.provider.nats.jetstream;

import static net.javacrumbs.shedlock.core.ClockProvider.now;

import io.nats.client.Connection;
import io.nats.client.JetStreamApiException;
import io.nats.client.api.KeyValueConfiguration;

import static net.javacrumbs.shedlock.core.ClockProvider.now;

import java.io.IOException;
import java.time.Duration;
import java.util.Optional;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import net.javacrumbs.shedlock.core.LockConfiguration;
import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.core.SimpleLock;
Expand All @@ -29,7 +27,7 @@
public class NatsJetStreamLockProvider implements LockProvider, AutoCloseable {

private final Logger log = LoggerFactory.getLogger(NatsJetStreamLockProvider.class);

private final ScheduledExecutorService unlockScheduler = Executors.newSingleThreadScheduledExecutor();

private final Connection connection;
Expand Down Expand Up @@ -66,11 +64,7 @@ public Optional<SimpleLock> lock(@NonNull LockConfiguration lockConfiguration) {
.name(bucketName)
.ttl(lockTime)
.build());
connection
.keyValue(bucketName)
.create(
"LOCKED",
"ShedLock internal value. Do not touch.".getBytes());
connection.keyValue(bucketName).create("LOCKED", "ShedLock internal value. Do not touch.".getBytes());

log.debug("Acquired lock for bucketName: {}", bucketName);

Expand Down Expand Up @@ -131,8 +125,7 @@ private Runnable catchExceptions(Runnable runnable) {
public void close() {
unlockScheduler.shutdown();
try {
if (!unlockScheduler.awaitTermination(
Duration.ofSeconds(2).toMillis(), TimeUnit.MILLISECONDS)) {
if (!unlockScheduler.awaitTermination(Duration.ofSeconds(2).toMillis(), TimeUnit.MILLISECONDS)) {
unlockScheduler.shutdownNow();
}
} catch (InterruptedException ignored) {
Expand Down

0 comments on commit 44ea2c5

Please sign in to comment.