All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkiverse.playpen.LocalPlaypenRecorder Maven / Gradle / Ivy

The newest version!
package io.quarkiverse.playpen;

import java.util.function.Supplier;

import org.jboss.logging.Logger;

import io.quarkiverse.playpen.client.PlaypenConnectionConfig;
import io.quarkus.runtime.ShutdownContext;
import io.quarkus.runtime.annotations.Recorder;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpClientOptions;

@Recorder
public class LocalPlaypenRecorder {
    private static final Logger log = Logger.getLogger(LocalPlaypenRecorder.class);

    static VirtualPlaypenClient client;
    public static PlaypenConnectionConfig config;
    static Vertx vertx;

    public void init(Supplier vertx, ShutdownContext shutdown, PlaypenConnectionConfig c, boolean delayConnect) {
        config = c;
        LocalPlaypenRecorder.vertx = vertx.get();
        if (!delayConnect) {
            startSession(LocalPlaypenRecorder.vertx, c);
            shutdown.addShutdownTask(() -> {
                closeSession();
            });
        }
    }

    public static void startSession() {
        startSession(vertx, config);
    }

    public static void startSession(Vertx vertx, PlaypenConnectionConfig config) {
        client = new VirtualPlaypenClient();
        HttpClientOptions options = new HttpClientOptions();
        options.setDefaultHost(config.host);
        options.setDefaultPort(config.port);
        if (config.ssl) {
            options.setSsl(true).setTrustAll(true);
        }
        client.setCredentials(config.credentials);
        client.setProxyClient(vertx.createHttpClient(options));
        client.vertx = vertx;
        client.initUri(config);
        client.start();
    }

    public static void closeSession() {
        if (client != null)
            client.shutdown();
        client = null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy