<commit_before>package gateway

import (
	"fmt"
	MQTT "git.eclipse.org/gitroot/paho/org.eclipse.paho.mqtt.golang.git"
	"os"
)

type AggGate struct {
	udpListener
	mqttclient *MQTT.MqttClient
	stopsig    chan os.Signal
}

func NewAggGate(opts *MQTT.ClientOptions, stopsig chan os.Signal, port int) *AggGate {
	listener := udpListener{
		port,
	}
	client := MQTT.NewClient(opts)
	ag := &AggGate{
		listener,
		client,
		stopsig,
	}
	return ag
}

func (ag *AggGate) Start() {
	go ag.awaitStop()
	fmt.Println("Aggregating Gateway is starting")
	ag.mqttclient.Start()
	fmt.Println("Aggregating Gateway is started")
	ag.listen()
}

// This does NOT WORK on Windows using Cygwin, however
// it does work using cmd.exe
func (ag *AggGate) awaitStop() {
	<-ag.stopsig
	fmt.Println("Aggregating Gateway is stopping")

	fmt.Println("Aggregating Gateway is stopped")

	// TODO: cleanly close down other goroutines

	os.Exit(0)
}<commit_msg>stop on failure to connect to mqtt-broker<commit_after>package gateway

import (
	"fmt"
	MQTT "git.eclipse.org/gitroot/paho/org.eclipse.paho.mqtt.golang.git"
	"os"
)

type AggGate struct {
	udpListener
	mqttclient *MQTT.MqttClient
	stopsig    chan os.Signal
}

func NewAggGate(opts *MQTT.ClientOptions, stopsig chan os.Signal, port int) *AggGate {
	listener := udpListener{
		port,
	}
	client := MQTT.NewClient(opts)
	ag := &AggGate{
		listener,
		client,
		stopsig,
	}
	return ag
}

func (ag *AggGate) Start() {
	go ag.awaitStop()
	fmt.Println("Aggregating Gateway is starting")
	_, err := ag.mqttclient.Start()
	if err != nil {
		fmt.Println("Aggregating Gateway failed to start")
		fmt.Println(err)
		os.Exit(1)
	}
	fmt.Println("Aggregating Gateway is started")
	ag.listen()
}

// This does NOT WORK on Windows using Cygwin, however
// it does work using cmd.exe
func (ag *AggGate) awaitStop() {
	<-ag.stopsig
	fmt.Println("Aggregating Gateway is stopping")
	ag.mqttclient.Disconnect(1000)
	fmt.Println("Aggregating Gateway is stopped")

	// TODO: cleanly close down other goroutines

	os.Exit(0)
}
{'fraction_non_alphanumeric': 0.1227810650887574, 'fraction_numerical': 0.0034516765285996054, 'mean_word_length': 4.149746192893401, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2925846', 'n_tokens_mistral': 811, 'n_tokens_neox': 758, 'n_words': 192}