File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,8 +24,8 @@ dependencies {
2424 // implementation 'org.springframework.boot:spring-boot-starter-jdbc'
2525 implementation ' org.springframework.boot:spring-boot-starter-web'
2626 implementation ' org.springframework.boot:spring-boot-starter-actuator'
27- implementation ' org.springframework.boot:spring-boot-starter-data-jdbc' // management stuff
28- runtimeOnly ' org.postgresql:postgresql'
27+ // implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'// management stuff
28+ // runtimeOnly 'org.postgresql:postgresql'
2929 testImplementation ' org.springframework.boot:spring-boot-starter-test'
3030 testRuntimeOnly ' org.junit.platform:junit-platform-launcher'
3131
Original file line number Diff line number Diff line change @@ -11,8 +11,7 @@ import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence
1111
1212class MqttCallbackClient : MqttCallback {
1313
14- private val trackStore = InMemoryTrackStore ()
15- private val dataProvider = DataProvider (trackStore)
14+ private val dataProvider = DataProvider ()
1615
1716 private var mqttClient: MqttClient = MqttClient (
1817 " tcp://${MqttEnv .URL } :${MqttEnv .PORT } " ,
@@ -30,13 +29,22 @@ class MqttCallbackClient : MqttCallback {
3029 connectionTimeout = 10
3130 }
3231
32+ init {
33+ Thread (
34+ MqttDefibrillator (this ),
35+ " mqtt-defibrillator"
36+ ).start()
37+ }
38+
3339 fun connect () {
3440 Logging .log.info(" mqtt: connecting..." )
3541 mqttClient.connect(mqttOptions)
3642 mqttClient.subscribe(MqttEnv .LISTEN_TOPIC )
3743 Logging .log.info(" mqtt: connected to ${MqttEnv .hostString} with id ${MqttEnv .clientId} " )
3844 }
3945
46+ val isConnected get() = mqttClient.isConnected
47+
4048 override fun connectionLost (cause : Throwable ? ) {
4149 Logging .log.warn(" mqtt: connection lost, reconnecting..." , cause)
4250 connect()
Original file line number Diff line number Diff line change 1+ package gent.zeus.guitar.mqtt
2+
3+ import gent.zeus.guitar.Logging
4+ import org.apache.juli.logging.Log
5+ import org.springframework.boot.ApplicationArguments
6+ import org.springframework.boot.ApplicationRunner
7+ import org.springframework.scheduling.config.Task
8+ import java.net.ConnectException
9+
10+
11+ const val SLEEP_TIME : Long = 1000 * 30 * 1
12+
13+ /* *
14+ * checks every few minutes if mqtt connection is dead and revives it if necessary
15+ */
16+ class MqttDefibrillator (val client : MqttCallbackClient ) : Runnable {
17+
18+ override fun run () {
19+ Logging .log.info(" defibrillator: looking for dead mqtt connections..." )
20+
21+ while (true ) {
22+ Thread .sleep(SLEEP_TIME )
23+
24+ if (! client.isConnected) {
25+ Logging .log.info(" defibrillator: dead mqtt connection found!! :O reviving..." )
26+ try {
27+ client.connect()
28+ } catch (_: Exception ) {
29+ Logging .log.info(" defibrillator: could not connect, trying again in ${SLEEP_TIME / 1000 } seconds" )
30+ }
31+ }
32+ }
33+ }
34+ }
File renamed without changes.
Original file line number Diff line number Diff line change 1- create table guitar (
2- spotifyId varchar ,
3-
1+ create table tracks (
2+ spotifyId varchar primary key ,
3+ name varchar ,
4+ album varchar ,
45)
You can’t perform that action at this time.
0 commit comments