Skip to content

Commit

Permalink
add NotificationCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
EddeCCC committed Jul 1, 2024
1 parent 0c7b196 commit 6be5251
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public AgentBuilder extend(AgentBuilder agentBuilder, ConfigProperties config) {

boolean successful = NotificationManager.sendStartNotification(SERVER_URL);
if (successful) log.info("Successfully notified configuration server about start");
else log.info("Could not notify configuration server about start");

return agentBuilder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
import org.apache.hc.core5.concurrent.FutureCallback;
import org.apache.hc.core5.http.HttpResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import rocks.inspectit.gepard.agent.notify.http.HttpClientHolder;
import rocks.inspectit.gepard.agent.notify.http.NotificationCallback;
import rocks.inspectit.gepard.agent.notify.http.NotificationFactory;

/** This manager should notify the configuration server about the agent itself and its status. */
Expand Down Expand Up @@ -56,7 +58,8 @@ private static boolean doSend(SimpleHttpRequest request)
if (Objects.isNull(request)) return false;

CloseableHttpAsyncClient client = HttpClientHolder.getClient();
Future<SimpleHttpResponse> future = client.execute(request, null);
FutureCallback<SimpleHttpResponse> callback = new NotificationCallback();
Future<SimpleHttpResponse> future = client.execute(request, callback);

HttpResponse response = future.get();
return Objects.nonNull(response) && 200 == response.getCode();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package rocks.inspectit.gepard.agent.notify.http;

import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
import org.apache.hc.core5.concurrent.FutureCallback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/** Callback for notifications to the configuration server. Currently, only used for logging. */
public class NotificationCallback implements FutureCallback<SimpleHttpResponse> {
private static final Logger log = LoggerFactory.getLogger(NotificationCallback.class);

@Override
public void completed(SimpleHttpResponse result) {
log.info("Notified configuration server and received status code {}", result.getCode());
}

@Override
public void failed(Exception ex) {
log.error("Failed to notify configuration server", ex);
}

@Override
public void cancelled() {
log.info("Cancelled notification to configuration server");
}
}

0 comments on commit 6be5251

Please sign in to comment.