<commit_before>package fr.xebia.kouignamann.cloud.mqtt

import org.eclipse.paho.client.mqttv3.*
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence
import org.vertx.groovy.platform.Verticle
import org.vertx.java.core.json.impl.Json

class MqttDataManagementVerticle extends Verticle implements MqttCallback {
    def log

    def client
    MqttConnectOptions options

    def start() {

        log = container.logger

        configure()


        log.info('Start -> Done initialize handler')
    }

    def stop() {
        if(client?.isConnected())
            client?.disconnect()
    }

    def configure() throws MqttException {
        def uri = 'tcp://m10.cloudmqtt.com:10325'
        def clientId = 'cloud-application'

        def persistence = new MemoryPersistence()
        client = new MqttClient(uri, clientId, persistence)

        client.setCallback(this)

        options = new MqttConnectOptions()

        options.setPassword('<PASSWORD>'.getChars())
        options.setUserName('devoxxfr')

        options.setCleanSession(false)

        client?.connect(options)
        log.info "MQTT connected"
        client?.subscribe('fr.xebia.kouignamann.nuc.central.processSingleVote', 2)
        client?.disconnect()
    }



    @Override
    void connectionLost(Throwable throwable) {
        log.info "connectionLost", throwable<commit_msg>Refacto<commit_after>package fr.xebia.kouignamann.cloud.mqtt

import org.eclipse.paho.client.mqttv3.*
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence
import org.vertx.groovy.platform.Verticle
import org.vertx.java.core.json.impl.Json

class MqttDataManagementVerticle extends Verticle implements MqttCallback {
    def log

    def client
    MqttConnectOptions options

    def start() {

        log = container.logger

        configure()


        log.info('Start -> Done initialize handler')
    }

    def stop() {
        if(client?.isConnected())
            client?.disconnect()
    }

    def configure() throws MqttException {
        def uri = 'tcp://m10.cloudmqtt.com:10325'
        def clientId = 'cloud-application'

        def persistence = new MemoryPersistence()
        client = new MqttClient(uri, clientId, persistence)

        client.setCallback(this)

        options = new MqttConnectOptions()

        options.setPassword('<PASSWORD>'.getChars())
        options.setUserName('devoxxfr')

        options.setCleanSession(false)

        client?.connect(options)
        log.info "MQTT connected"
        client?.subscribe('fr.xebia.kouignamann.nuc.central.processSingleVote', 2)

        // ??
        //client?.disconnect()
    }



    @Override
    void connectionLost(Throwable throwable) {
        log.info "connectionLost", throwable
{'fraction_non_alphanumeric': 0.10323518720465286, 'fraction_numerical': 0.007270083605961469, 'mean_word_length': 2.759562841530055, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '2565202', 'n_tokens_mistral': 867, 'n_tokens_neox': 803, 'n_words': 149}