Skip to content

Commit

Permalink
Refactor for concise Kotlin code style, compile under JDK 23 (#191)
Browse files Browse the repository at this point in the history
Updating the Java versions in the GitHub Actions workflow, enhancing the
readability of constructors and methods, and adding trailing commas for
better diff readability.

---------

Co-authored-by: kpavlov <{ID}+{username}@users.noreply.github.com>
  • Loading branch information
kpavlov and kpavlov authored Oct 28, 2024
1 parent cd23d84 commit a48724d
Show file tree
Hide file tree
Showing 28 changed files with 568 additions and 480 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ jobs:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
java: [ '17', '21', '22' ]
java: [ '17', '21', '23' ]

name: Build under JDK ${{ matrix.Java }}

Expand Down
19 changes: 12 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,20 @@ kotlin {
freeCompilerArgs.addAll(
"-Xjvm-default=all",
"-Xjsr305=strict",
"-Xexplicit-api=strict"
"-Xexplicit-api=strict",
)
}
}

tasks.test {
useJUnitPlatform()
testLogging {
events = setOf(
TestLogEvent.PASSED,
TestLogEvent.SKIPPED,
TestLogEvent.FAILED
)
events =
setOf(
TestLogEvent.PASSED,
TestLogEvent.SKIPPED,
TestLogEvent.FAILED,
)
}
}

Expand All @@ -74,6 +75,10 @@ val dokkaJavadocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
}

tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
jvmTarget = "17"
}

tasks.assemble {
dependsOn(dokkaJavadocJar)
}
Expand All @@ -82,7 +87,7 @@ tasks.jar {
manifest {
attributes(
"Implementation-Title" to project.name,
"Implementation-Version" to project.version
"Implementation-Version" to project.version,
)
}
}
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -19,87 +19,86 @@ import java.util.concurrent.atomic.AtomicReference
public abstract class AbstractIso8583Connector<
C : ConnectorConfiguration,
B : AbstractBootstrap<B, *>,
M : IsoMessage>
protected constructor(
configuration: C,
isoMessageFactory: MessageFactory<M>,
protected val messageHandler: CompositeIsoMessageHandler<M> = CompositeIsoMessageHandler()
) {
M : IsoMessage,
>
protected constructor(
configuration: C,
isoMessageFactory: MessageFactory<M>,
protected val messageHandler: CompositeIsoMessageHandler<M> = CompositeIsoMessageHandler(),
) {
protected val logger: Logger = LoggerFactory.getLogger(javaClass)

protected val logger: Logger = LoggerFactory.getLogger(javaClass)
public val isoMessageFactory: MessageFactory<M> = isoMessageFactory
private val channelRef = AtomicReference<Channel>()
protected val configuration: C = configuration
public var configurer: ConnectorConfigurer<C, B>? = null
protected lateinit var bossEventLoopGroup: EventLoopGroup
private set
protected lateinit var workerEventLoopGroup: EventLoopGroup
protected lateinit var bootstrap: B

public val isoMessageFactory: MessageFactory<M> = isoMessageFactory
private val channelRef = AtomicReference<Channel>()
protected val configuration: C = configuration
public var configurer: ConnectorConfigurer<C, B>? = null
protected lateinit var bossEventLoopGroup: EventLoopGroup
private set
protected lateinit var workerEventLoopGroup: EventLoopGroup
protected lateinit var bootstrap: B

public fun addMessageListener(handler: IsoMessageListener<M>) {
messageHandler.addListener(handler)
}

public fun removeMessageListener(handler: IsoMessageListener<M>) {
messageHandler.removeListener(handler)
}
public fun addMessageListener(handler: IsoMessageListener<M>) {
messageHandler.addListener(handler)
}

/**
* Making connector ready to create a connection / bind to port.
* Creates a Bootstrap
*
* @see AbstractBootstrap
*/
public fun init() {
logger.info("Initializing")
bossEventLoopGroup = createBossEventLoopGroup()
workerEventLoopGroup = createWorkerEventLoopGroup()
bootstrap = createBootstrap()
}
public fun removeMessageListener(handler: IsoMessageListener<M>) {
messageHandler.removeListener(handler)
}

public open fun shutdown() {
workerEventLoopGroup.shutdownGracefully()
bossEventLoopGroup.shutdownGracefully()
}
/**
* Making connector ready to create a connection / bind to port.
* Creates a Bootstrap
*
* @see AbstractBootstrap
*/
public fun init() {
logger.info("Initializing")
bossEventLoopGroup = createBossEventLoopGroup()
workerEventLoopGroup = createWorkerEventLoopGroup()
bootstrap = createBootstrap()
}

protected fun configureBootstrap(bootstrap: B) {
bootstrap.option(
ChannelOption.TCP_NODELAY,
parseBoolean(
System.getProperty(
"nfs.rpc.tcp.nodelay", "true"
)
)
)
.option(ChannelOption.AUTO_READ, true)
configurer?.configureBootstrap(bootstrap, configuration)
}
public open fun shutdown() {
workerEventLoopGroup.shutdownGracefully()
bossEventLoopGroup.shutdownGracefully()
}

protected abstract fun createBootstrap(): B
protected fun configureBootstrap(bootstrap: B) {
bootstrap
.option(
ChannelOption.TCP_NODELAY,
parseBoolean(
System.getProperty(
"nfs.rpc.tcp.nodelay",
"true",
),
),
).option(ChannelOption.AUTO_READ, true)
configurer?.configureBootstrap(bootstrap, configuration)
}

protected fun createBossEventLoopGroup(): EventLoopGroup {
return NioEventLoopGroup()
}
protected abstract fun createBootstrap(): B

protected fun createWorkerEventLoopGroup(): EventLoopGroup {
val group = NioEventLoopGroup(configuration.workerThreadsCount)
logger.debug(
"Created worker EventLoopGroup with {} executor threads",
group.executorCount()
)
return group
}
protected fun createBossEventLoopGroup(): EventLoopGroup = NioEventLoopGroup()

protected var channel: Channel?
get() = channelRef.get()
protected set(channel) {
channelRef.set(channel)
protected fun createWorkerEventLoopGroup(): EventLoopGroup {
val group = NioEventLoopGroup(configuration.workerThreadsCount)
logger.debug(
"Created worker EventLoopGroup with {} executor threads",
group.executorCount(),
)
return group
}

init {
if (configuration.shouldAddEchoMessageListener()) {
messageHandler.addListener(EchoMessageListener(isoMessageFactory))
protected var channel: Channel?
get() = channelRef.get()
protected set(channel) {
channelRef.set(channel)
}

init {
if (configuration.shouldAddEchoMessageListener()) {
messageHandler.addListener(EchoMessageListener(isoMessageFactory))
}
}
}
}
Loading

0 comments on commit a48724d

Please sign in to comment.