Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mimic2300 committed Jun 2, 2018
1 parent 7676b8b commit ab01514
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface IBotnet {
/**
* Verze Botnetu.
*/
String VERSION = "0.9.2";
String VERSION = "0.9.3";

/**
* Verze REST API pro vHackOS.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ protected final Map<String, Object> sendRequest(IOpcode opcode) {
.getOpcodeValue(), getConfig().getUserName());

int attempts = getBotnet().getConfig().getMaxRequestAttempts(); // maximální počet pokusů
Exception prevException = null;

while (attempts > 0) {
try {
Expand All @@ -79,6 +80,7 @@ protected final Map<String, Object> sendRequest(IOpcode opcode) {
return request.send(this);

} catch (InvalidAccessTokenException e) {
prevException = e;
try {
log.info("Invalid access token. Getting a new...");
Thread.sleep(5000);
Expand All @@ -95,11 +97,20 @@ protected final Map<String, Object> sendRequest(IOpcode opcode) {
} catch (InterruptedException e1) {
break;
}
} catch (ConnectionException e) {
prevException = e;
attempts--;
log.error("Request failed. Remaining attempts: {}", attempts);
try {
Thread.sleep(10000);
} catch (InterruptedException e1) {
break;
}
} catch (InterruptedException e) {
break;
}
}
throw new ConnectionException("Could not send request to server");
throw new ConnectionException(null, "Could not send request to server", prevException);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ protected void initialize() {
}
}

@Override
protected void onStopped() {
scansCountBeforePause = null;
}

@Override
protected void execute() {
counter.incrementAndGet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,15 @@ public final synchronized boolean stop() {
log.info("Waiting for finish...");
executor.shutdownNow();
log.info("Stopped");
onStopped();
return true;
} else {
log.debug("Executor was already stopped");
}
} else if (running) {
log.info("Stopped");
running = false;
onStopped();
return true;
} else {
log.debug("Service is already stopped");
Expand Down Expand Up @@ -156,6 +158,10 @@ protected final void setAutoResetExecutor(boolean autoResetExecutor) {

protected abstract void execute() throws Exception;

protected void onStopped() {
// nic
}

protected final Logger getLog() {
return log;
}
Expand Down Expand Up @@ -253,9 +259,12 @@ public void run() {
try {
execute();
} catch (ConnectionException e) {
stop();
throw e;

} catch (BotnetException e) {
log.error("An unexpected error occurred while processing the service", e);

} catch (Exception e) {
log.error("There was a fatal error while processing the service. The service will be stopped", e);
stop();
Expand Down

0 comments on commit ab01514

Please sign in to comment.