Skip to content

Commit

Permalink
use single HTTP client instance
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Jan 25, 2024
1 parent 5bd6653 commit 97c91a1
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/main/java/io/cryostat/reports/ReportsServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.cryostat.reports;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.Map;
Expand All @@ -35,13 +36,17 @@

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.quarkus.runtime.ShutdownEvent;
import io.quarkus.runtime.StartupEvent;
import io.smallrye.common.annotation.Blocking;
import io.smallrye.mutiny.Uni;
import io.vertx.ext.web.handler.HttpException;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.event.Observes;
import jakarta.inject.Inject;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.jboss.logging.Logger;
Expand All @@ -57,6 +62,16 @@ class ReportsServiceImpl implements ReportsService {
@Inject InterruptibleReportGenerator reportGenerator;
@Inject Logger logger;

CloseableHttpClient http;

void onStart(@Observes StartupEvent evt) {
this.http = HttpClients.createSystem();
}

void onStop(@Observes ShutdownEvent evt) throws IOException {
this.http.close();
}

@Blocking
@Override
public Uni<Map<String, AnalysisResult>> reportFor(
Expand Down Expand Up @@ -126,8 +141,7 @@ private Future<Map<String, AnalysisResult>> process(

private Future<Map<String, AnalysisResult>> fireRequest(URI uri, InputStream stream) {
var cf = new CompletableFuture<Map<String, AnalysisResult>>();
try (var http = HttpClients.createDefault();
stream) {
try {
var post = new HttpPost(uri.resolve("report"));
var form = MultipartEntityBuilder.create().addBinaryBody("file", stream).build();
post.setEntity(form);
Expand Down

0 comments on commit 97c91a1

Please sign in to comment.