Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Commit

Permalink
#105: minor improvements to logging
Browse files Browse the repository at this point in the history
  • Loading branch information
danhaywood committed Mar 5, 2019
1 parent 0eeb659 commit b0e9bc8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,29 @@ public class TryCatch {
private static final Logger LOG = LoggerFactory.getLogger(TryCatch.class);

public static final int MAX_ATTEMPTS = 5;
public static final long SLEEP_MILLIS = 1000L;

public interface Backoff {
void backoff(int attempt);

class Default implements Backoff {

private final long sleepMillis;

public Default() {
this(SLEEP_MILLIS);
}

public Default(final long sleepMillis) {
this.sleepMillis = sleepMillis;
}
@Override
public void backoff(final int attempt) {
sleep(attempt * 1000L);
sleep(attempt * sleepMillis);
}

/**
* protected for convenience of any subclass.
* for convenience of any subclass.
*/
protected static void sleep(final long sleepForMillis) {
final long t1 = System.currentTimeMillis() + sleepForMillis;
Expand All @@ -42,7 +52,7 @@ protected static void sleep(final long sleepForMillis) {

@Override
public String toString() {
return "default backoff (1s, 2s, 3s, 4s, 5s)";
return "backoff for (attempt x " + sleepMillis + ") ms";
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,10 @@ public void init() {
ensureSet(this.bucket, "bucket");
ensureSet(this.instance, "instance");

final TryCatch.Backoff backoff = new TryCatch.Backoff.Default() {
@Override
public void backoff(final int attempt) {
sleep(attempt * backoffSleepMillis);
}
};
final TryCatch.Backoff backoff = new TryCatch.Backoff.Default(backoffSleepMillis);

tryCatch = new TryCatch(backoffNumAttempts, backoff) {
@Override
protected Logger getLog() { return LOG; }
@Override protected Logger getLog() { return LOG; }
};

minioClient = newMinioClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,10 @@ public void init() {
ensureSet(this.accessKey, "accessKey");
ensureSet(this.secretKey, "secretKey");

final TryCatch.Backoff backoff = new TryCatch.Backoff.Default() {
@Override
public void backoff(final int attempt) {
sleep(attempt * backoffSleepMillis);
}
};
final TryCatch.Backoff backoff = new TryCatch.Backoff.Default(backoffSleepMillis);

tryCatch = new TryCatch(backoffNumAttempts, backoff) {
@Override
protected Logger getLog() { return LOG; }
@Override protected Logger getLog() { return LOG; }
};
minioClient = newMinioClient();
}
Expand All @@ -109,10 +103,9 @@ private static void ensureSet(final String field, final String fieldName) {
}
}


/**
* @param url
* @throws if url cannot be parsed to extract bucketName and objectName
* @throws RuntimeException if url cannot be parsed to extract bucketName and objectName
*/
public void check(final String url) {
ParsedUrl.of(url);
Expand Down

0 comments on commit b0e9bc8

Please sign in to comment.