<commit_before>package quilt.config.subscription.service.amqp;

import io.vertx.core.Vertx;
import io.vertx.proton.ProtonConnection;
import io.vertx.proton.ProtonSender;
import io.vertx.proton.ProtonServer;
import io.vertx.proton.ProtonSession;
import quilt.config.subscription.service.model.ConfigMapDatabase;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * AMQP server endpoint that handles connections to the service and propagates config for a config map specified
 * as the address to which the client wants to receive.
 *
 * @author lulf
 */
public class AMQPServer {
    private static final Logger log = Logger.getLogger(AMQPServer.class.getName());

    private final ConfigMapDatabase database;
    private final ProtonServer server;
    private final String hostname;
    private final int port;

    public AMQPServer(String hostname, int port, ConfigMapDatabase database)
    {
        this.hostname = hostname;
        this.port = port;
        this.database = database;
        this.server = ProtonServer.create(Vertx.vertx());

        server.connectHandler(this::connectHandler);
    }

    private void connectHandler(ProtonConnection connection) {
        connection.setContainer("server");
        connection.openHandler(conn -> {
            log.log(Level.INFO, "Connection opened");
        }).closeHandler(conn -> {
            connection.close();
            connection.disconnect();
            log.log(Level.INFO, "Connection closed");
        }).disconnectHandler(protonConnection -> {
            connection.disconnect();
            log.log(Level.INFO, "Disconnected");
        }).open();

        connection.sessionOpenHandler(ProtonSession::open);
        connection.senderOpenHandler(this::senderOpenHandler);
    }

    private void senderOpenHandler(ProtonSender sender) {
        sender.setSource(sender.getRemoteSource());
        sender.open();
        database.subscribe(sender.getRemoteSource().getAddress(), new AMQPConfigSubscriber(sender));
    }

    public void run() {
        log.log(Level.INFO, String.format("Starting server on %s:%d", hostname, port));
        server.listen(port, hostname);
    }

    public int port() {
        return server.actualPort();
    }

    public void close() {
        server.close();
    }
}<commit_msg>Close vertx on shutdown<commit_after>package quilt.config.subscription.service.amqp;

import io.vertx.core.Vertx;
import io.vertx.proton.ProtonConnection;
import io.vertx.proton.ProtonSender;
import io.vertx.proton.ProtonServer;
import io.vertx.proton.ProtonSession;
import quilt.config.subscription.service.model.ConfigMapDatabase;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * AMQP server endpoint that handles connections to the service and propagates config for a config map specified
 * as the address to which the client wants to receive.
 *
 * @author lulf
 */
public class AMQPServer {
    private static final Logger log = Logger.getLogger(AMQPServer.class.getName());

    private final Vertx vertx = Vertx.vertx();
    private final ConfigMapDatabase database;
    private final ProtonServer server;
    private final String hostname;
    private final int port;

    public AMQPServer(String hostname, int port, ConfigMapDatabase database)
    {
        this.hostname = hostname;
        this.port = port;
        this.database = database;
        this.server = ProtonServer.create(vertx);

        server.connectHandler(this::connectHandler);
    }

    private void connectHandler(ProtonConnection connection) {
        connection.setContainer("server");
        connection.openHandler(conn -> {
            log.log(Level.INFO, "Connection opened");
        }).closeHandler(conn -> {
            connection.close();
            connection.disconnect();
            log.log(Level.INFO, "Connection closed");
        }).disconnectHandler(protonConnection -> {
            connection.disconnect();
            log.log(Level.INFO, "Disconnected");
        }).open();

        connection.sessionOpenHandler(ProtonSession::open);
        connection.senderOpenHandler(this::senderOpenHandler);
    }

    private void senderOpenHandler(ProtonSender sender) {
        sender.setSource(sender.getRemoteSource());
        sender.open();
        database.subscribe(sender.getRemoteSource().getAddress(), new AMQPConfigSubscriber(sender));
    }

    public void run() {
        log.log(Level.INFO, String.format("Starting server on %s:%d", hostname, port));
        server.listen(port, hostname);
    }

    public int port() {
        return server.actualPort();
    }

    public void close() {
        server.close();
        vertx.close();
    }
}
{'fraction_non_alphanumeric': 0.10784313725490197, 'fraction_numerical': 0.0, 'mean_word_length': 3.1239015817223197, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2015852', 'n_tokens_mistral': 1277, 'n_tokens_neox': 1252, 'n_words': 289}