Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
rubengees committed Sep 1, 2024
1 parent edc02d7 commit 0332292
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 126 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[{*.kt,*.kts}]
[*.{kt,kts}]
ktlint_code_style = intellij_idea
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true
16 changes: 8 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import com.vanniktech.maven.publish.SonatypeHost
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
kotlin("jvm") version "1.9.23"
id("org.jetbrains.kotlin.plugin.spring") version "1.9.23"
id("dev.adamko.dokkatoo-html") version "2.2.0"
id("dev.adamko.dokkatoo-javadoc") version "2.2.0"
id("io.gitlab.arturbosch.detekt") version "1.23.5"
id("org.jmailen.kotlinter") version "4.3.0"
kotlin("jvm") version "2.0.20"
id("org.jetbrains.kotlin.plugin.spring") version "2.0.20"
id("dev.adamko.dokkatoo-html") version "2.3.1"
id("dev.adamko.dokkatoo-javadoc") version "2.3.1"
id("io.gitlab.arturbosch.detekt") version "1.23.6"
id("org.jmailen.kotlinter") version "4.4.1"
id("com.adarshr.test-logger") version "4.0.0"
id("com.vanniktech.maven.publish") version "0.29.0"
id("com.github.ben-manes.versions") version "0.51.0"
Expand All @@ -29,7 +29,7 @@ dependencies {

implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core")

implementation(platform("org.springframework.boot:spring-boot-dependencies:3.2.3"))
implementation(platform("org.springframework.boot:spring-boot-dependencies:3.3.3"))
implementation("org.springframework.boot:spring-boot")
compileOnly("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-autoconfigure")
Expand Down Expand Up @@ -160,5 +160,5 @@ mavenPublishing {
}

tasks.withType<Wrapper> {
gradleVersion = "8.6"
gradleVersion = "8.10"
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 5 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down
119 changes: 50 additions & 69 deletions src/main/kotlin/de/smartsquare/starter/mqtt/MqttAutoConfiguration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package de.smartsquare.starter.mqtt
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.hivemq.client.mqtt.MqttClient
import com.hivemq.client.mqtt.MqttClientBuilder
import com.hivemq.client.mqtt.mqtt3.Mqtt3Client
import com.hivemq.client.mqtt.mqtt5.Mqtt5Client
import io.reactivex.Scheduler
Expand Down Expand Up @@ -46,23 +45,20 @@ class MqttAutoConfiguration {
config: MqttProperties,
mqttScheduler: Scheduler,
configurers: List<Mqtt3ClientConfigurer>,
): Mqtt3Client {
val clientBuilder = configureCommon(config, mqttScheduler)
.useMqttVersion3()
.apply {
config.username?.let { username ->
config.password?.let { password ->
simpleAuth()
.username(username)
.password(password.toByteArray())
.applySimpleAuth()
}
) = configureCommon(config, mqttScheduler)
.useMqttVersion3()
.apply {
config.username?.let { username ->
config.password?.let { password ->
simpleAuth()
.username(username)
.password(password.toByteArray())
.applySimpleAuth()
}
}
.apply { configurers.forEach { configurer -> configurer.configure(this) } }

return clientBuilder.build()
}
}
.apply { configurers.forEach { configurer -> configurer.configure(this) } }
.build()

/**
* Returns a configured and ready to use mqtt 5 client.
Expand All @@ -73,47 +69,42 @@ class MqttAutoConfiguration {
config: MqttProperties,
mqttScheduler: Scheduler,
configurers: List<Mqtt5ClientConfigurer>,
): Mqtt5Client {
val clientBuilder = configureCommon(config, mqttScheduler)
.useMqttVersion5()
.apply {
config.username?.let { username ->
config.password?.let { password ->
simpleAuth()
.username(username)
.password(password.toByteArray())
.applySimpleAuth()
}
) = configureCommon(config, mqttScheduler)
.useMqttVersion5()
.apply {
config.username?.let { username ->
config.password?.let { password ->
simpleAuth()
.username(username)
.password(password.toByteArray())
.applySimpleAuth()
}
}
.apply { configurers.forEach { configurer -> configurer.configure(this) } }

return clientBuilder.build()
}

private fun configureCommon(config: MqttProperties, scheduler: Scheduler): MqttClientBuilder {
return MqttClient.builder()
.serverHost(config.host)
.serverPort(config.port)
.automaticReconnectWithDefaultConfig()
.executorConfig()
.applicationScheduler(scheduler)
.applyExecutorConfig()
.addConnectedListener { logger.info("Connected to broker.") }
.addDisconnectedListener {
if (it.reconnector.isReconnect) {
if (logger.isDebugEnabled) {
logger.warn("Disconnected from broker, reconnecting...", it.cause)
} else {
logger.warn("Disconnected from broker, reconnecting...")
}
}
.apply { configurers.forEach { configurer -> configurer.configure(this) } }
.build()

private fun configureCommon(config: MqttProperties, scheduler: Scheduler) = MqttClient.builder()
.serverHost(config.host)
.serverPort(config.port)
.automaticReconnectWithDefaultConfig()
.executorConfig()
.applicationScheduler(scheduler)
.applyExecutorConfig()
.addConnectedListener { logger.info("Connected to broker.") }
.addDisconnectedListener {
if (it.reconnector.isReconnect) {
if (logger.isDebugEnabled) {
logger.warn("Disconnected from broker, reconnecting...", it.cause)
} else {
logger.info("Disconnected from broker.")
logger.warn("Disconnected from broker, reconnecting...")
}
} else {
logger.info("Disconnected from broker.")
}
.apply { if (config.ssl) sslWithDefaultConfig() }
.apply { config.clientId?.also { clientId -> identifier(clientId) } }
}
}
.apply { if (config.ssl) sslWithDefaultConfig() }
.apply { config.clientId?.also { clientId -> identifier(clientId) } }

@Bean
@ConditionalOnProperty("mqtt.shutdown", havingValue = "graceful", matchIfMissing = true)
Expand All @@ -136,23 +127,21 @@ class MqttAutoConfiguration {
*/
@Bean
@ConditionalOnMissingBean
fun fallbackObjectMapper(): ObjectMapper = jacksonObjectMapper().findAndRegisterModules()
fun fallbackObjectMapper() = jacksonObjectMapper().findAndRegisterModules()

@Bean
fun mqttHandler(
collector: MqttSubscriberCollector,
adapter: MqttMessageAdapter,
messageErrorHandler: MqttMessageErrorHandler,
): MqttHandler = MqttHandler(collector, adapter, messageErrorHandler)
) = MqttHandler(collector, adapter, messageErrorHandler)

/**
* Returns a default mqtt message error handler.
*/
@Bean
@ConditionalOnMissingBean
fun mqttMessageErrorHandler(): MqttMessageErrorHandler {
return MqttMessageErrorHandler()
}
fun mqttMessageErrorHandler() = MqttMessageErrorHandler()

@Bean
@ConditionalOnMissingBean
Expand All @@ -162,9 +151,7 @@ class MqttAutoConfiguration {
collector: MqttSubscriberCollector,
handler: MqttHandler,
config: MqttProperties,
): MqttConnector {
return Mqtt3Connector(client, collector, handler, config)
}
): MqttConnector = Mqtt3Connector(client, collector, handler, config)

@Bean
@ConditionalOnMissingBean
Expand All @@ -174,19 +161,13 @@ class MqttAutoConfiguration {
collector: MqttSubscriberCollector,
handler: MqttHandler,
config: MqttProperties,
): MqttConnector {
return Mqtt5Connector(client, collector, handler, config)
}
): MqttConnector = Mqtt5Connector(client, collector, handler, config)

@Bean
@ConditionalOnProperty("mqtt.version", havingValue = "3", matchIfMissing = true)
fun mqtt3Publisher(messageAdapter: MqttMessageAdapter, client: Mqtt3Client): Mqtt3Publisher {
return Mqtt3Publisher(messageAdapter, client)
}
fun mqtt3Publisher(messageAdapter: MqttMessageAdapter, client: Mqtt3Client) = Mqtt3Publisher(messageAdapter, client)

@Bean
@ConditionalOnProperty("mqtt.version", havingValue = "5")
fun mqtt5Publisher(messageAdapter: MqttMessageAdapter, client: Mqtt5Client): Mqtt5Publisher {
return Mqtt5Publisher(messageAdapter, client)
}
fun mqtt5Publisher(messageAdapter: MqttMessageAdapter, client: Mqtt5Client) = Mqtt5Publisher(messageAdapter, client)
}
8 changes: 2 additions & 6 deletions src/main/kotlin/de/smartsquare/starter/mqtt/MqttConnector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@ abstract class MqttConnector : SmartLifecycle {
const val SMART_LIFECYCLE_PHASE = SmartLifecycle.DEFAULT_PHASE - 1024
}

override fun stop() {
throw UnsupportedOperationException("Stop must not be invoked directly")
}
override fun stop() = throw UnsupportedOperationException("Stop must not be invoked directly")

override fun getPhase(): Int {
return SMART_LIFECYCLE_PHASE
}
override fun getPhase() = SMART_LIFECYCLE_PHASE

abstract override fun stop(callback: Runnable)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import java.util.concurrent.ThreadPoolExecutor
*
* This delegates to a [ThreadPoolExecutor] with the number of processors as max threads.
*/
class MqttGracefulExecutor : Executor, SmartLifecycle {
class MqttGracefulExecutor :
Executor,
SmartLifecycle {

private val logger = LoggerFactory.getLogger(this::class.java)

Expand Down Expand Up @@ -40,11 +42,7 @@ class MqttGracefulExecutor : Executor, SmartLifecycle {
}
}

override fun isRunning(): Boolean {
return !delegate.isShutdown
}
override fun isRunning() = !delegate.isShutdown

override fun getPhase(): Int {
return MqttConnector.SMART_LIFECYCLE_PHASE - 512
}
override fun getPhase() = MqttConnector.SMART_LIFECYCLE_PHASE - 512
}
24 changes: 10 additions & 14 deletions src/main/kotlin/de/smartsquare/starter/mqtt/MqttMessageAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,22 @@ open class DefaultMqttMessageAdapter(private val objectMapper: ObjectMapper) : M
/**
* Converts the given [message] into the expected [targetType].
*/
override fun adapt(message: MqttPublishContainer, targetType: Class<*>): Any {
return when {
targetType.isAssignableFrom(MqttTopic::class.java) -> message.topic
targetType.isAssignableFrom(ByteArray::class.java) -> message.payload
targetType.isAssignableFrom(String::class.java) -> message.payload.decodeToString()
targetType.isAssignableFrom(message.value.javaClass) -> message.value
else -> objectMapper.readValue(message.payload, targetType)
}
override fun adapt(message: MqttPublishContainer, targetType: Class<*>) = when {
targetType.isAssignableFrom(MqttTopic::class.java) -> message.topic
targetType.isAssignableFrom(ByteArray::class.java) -> message.payload
targetType.isAssignableFrom(String::class.java) -> message.payload.decodeToString()
targetType.isAssignableFrom(message.value.javaClass) -> message.value
else -> objectMapper.readValue(message.payload, targetType)
}

/**
* Converts the given [payload] into a [ByteArray].
*
* Strings and primitives are converted directly, other types are serialized to json.
*/
override fun adapt(payload: Any): ByteArray {
return when (payload) {
is ByteArray -> payload
is String -> payload.encodeToByteArray()
else -> objectMapper.writeValueAsString(payload).encodeToByteArray()
}
override fun adapt(payload: Any) = when (payload) {
is ByteArray -> payload
is String -> payload.encodeToByteArray()
else -> objectMapper.writeValueAsString(payload).encodeToByteArray()
}
}
Loading

0 comments on commit 0332292

Please sign in to comment.