Skip to content

Commit a48724d

Browse files
kpavlovkpavlov
andauthored
Refactor for concise Kotlin code style, compile under JDK 23 (#191)
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>
1 parent cd23d84 commit a48724d

28 files changed

Lines changed: 568 additions & 480 deletions

.github/workflows/gradle.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ jobs:
2222
runs-on: ubuntu-latest
2323

2424
strategy:
25+
fail-fast: false
2526
matrix:
26-
java: [ '17', '21', '22' ]
27+
java: [ '17', '21', '23' ]
2728

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

build.gradle.kts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,20 @@ kotlin {
5252
freeCompilerArgs.addAll(
5353
"-Xjvm-default=all",
5454
"-Xjsr305=strict",
55-
"-Xexplicit-api=strict"
55+
"-Xexplicit-api=strict",
5656
)
5757
}
5858
}
5959

6060
tasks.test {
6161
useJUnitPlatform()
6262
testLogging {
63-
events = setOf(
64-
TestLogEvent.PASSED,
65-
TestLogEvent.SKIPPED,
66-
TestLogEvent.FAILED
67-
)
63+
events =
64+
setOf(
65+
TestLogEvent.PASSED,
66+
TestLogEvent.SKIPPED,
67+
TestLogEvent.FAILED,
68+
)
6869
}
6970
}
7071

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

78+
tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
79+
jvmTarget = "17"
80+
}
81+
7782
tasks.assemble {
7883
dependsOn(dokkaJavadocJar)
7984
}
@@ -82,7 +87,7 @@ tasks.jar {
8287
manifest {
8388
attributes(
8489
"Implementation-Title" to project.name,
85-
"Implementation-Version" to project.version
90+
"Implementation-Version" to project.version,
8691
)
8792
}
8893
}

gradle/wrapper/gradle-wrapper.jar

42.4 KB
Binary file not shown.

src/main/kotlin/com/github/kpavlov/jreactive8583/AbstractIso8583Connector.kt

Lines changed: 70 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -19,87 +19,86 @@ import java.util.concurrent.atomic.AtomicReference
1919
public abstract class AbstractIso8583Connector<
2020
C : ConnectorConfiguration,
2121
B : AbstractBootstrap<B, *>,
22-
M : IsoMessage>
23-
protected constructor(
24-
configuration: C,
25-
isoMessageFactory: MessageFactory<M>,
26-
protected val messageHandler: CompositeIsoMessageHandler<M> = CompositeIsoMessageHandler()
27-
) {
22+
M : IsoMessage,
23+
>
24+
protected constructor(
25+
configuration: C,
26+
isoMessageFactory: MessageFactory<M>,
27+
protected val messageHandler: CompositeIsoMessageHandler<M> = CompositeIsoMessageHandler(),
28+
) {
29+
protected val logger: Logger = LoggerFactory.getLogger(javaClass)
2830

29-
protected val logger: Logger = LoggerFactory.getLogger(javaClass)
31+
public val isoMessageFactory: MessageFactory<M> = isoMessageFactory
32+
private val channelRef = AtomicReference<Channel>()
33+
protected val configuration: C = configuration
34+
public var configurer: ConnectorConfigurer<C, B>? = null
35+
protected lateinit var bossEventLoopGroup: EventLoopGroup
36+
private set
37+
protected lateinit var workerEventLoopGroup: EventLoopGroup
38+
protected lateinit var bootstrap: B
3039

31-
public val isoMessageFactory: MessageFactory<M> = isoMessageFactory
32-
private val channelRef = AtomicReference<Channel>()
33-
protected val configuration: C = configuration
34-
public var configurer: ConnectorConfigurer<C, B>? = null
35-
protected lateinit var bossEventLoopGroup: EventLoopGroup
36-
private set
37-
protected lateinit var workerEventLoopGroup: EventLoopGroup
38-
protected lateinit var bootstrap: B
39-
40-
public fun addMessageListener(handler: IsoMessageListener<M>) {
41-
messageHandler.addListener(handler)
42-
}
43-
44-
public fun removeMessageListener(handler: IsoMessageListener<M>) {
45-
messageHandler.removeListener(handler)
46-
}
40+
public fun addMessageListener(handler: IsoMessageListener<M>) {
41+
messageHandler.addListener(handler)
42+
}
4743

48-
/**
49-
* Making connector ready to create a connection / bind to port.
50-
* Creates a Bootstrap
51-
*
52-
* @see AbstractBootstrap
53-
*/
54-
public fun init() {
55-
logger.info("Initializing")
56-
bossEventLoopGroup = createBossEventLoopGroup()
57-
workerEventLoopGroup = createWorkerEventLoopGroup()
58-
bootstrap = createBootstrap()
59-
}
44+
public fun removeMessageListener(handler: IsoMessageListener<M>) {
45+
messageHandler.removeListener(handler)
46+
}
6047

61-
public open fun shutdown() {
62-
workerEventLoopGroup.shutdownGracefully()
63-
bossEventLoopGroup.shutdownGracefully()
64-
}
48+
/**
49+
* Making connector ready to create a connection / bind to port.
50+
* Creates a Bootstrap
51+
*
52+
* @see AbstractBootstrap
53+
*/
54+
public fun init() {
55+
logger.info("Initializing")
56+
bossEventLoopGroup = createBossEventLoopGroup()
57+
workerEventLoopGroup = createWorkerEventLoopGroup()
58+
bootstrap = createBootstrap()
59+
}
6560

66-
protected fun configureBootstrap(bootstrap: B) {
67-
bootstrap.option(
68-
ChannelOption.TCP_NODELAY,
69-
parseBoolean(
70-
System.getProperty(
71-
"nfs.rpc.tcp.nodelay", "true"
72-
)
73-
)
74-
)
75-
.option(ChannelOption.AUTO_READ, true)
76-
configurer?.configureBootstrap(bootstrap, configuration)
77-
}
61+
public open fun shutdown() {
62+
workerEventLoopGroup.shutdownGracefully()
63+
bossEventLoopGroup.shutdownGracefully()
64+
}
7865

79-
protected abstract fun createBootstrap(): B
66+
protected fun configureBootstrap(bootstrap: B) {
67+
bootstrap
68+
.option(
69+
ChannelOption.TCP_NODELAY,
70+
parseBoolean(
71+
System.getProperty(
72+
"nfs.rpc.tcp.nodelay",
73+
"true",
74+
),
75+
),
76+
).option(ChannelOption.AUTO_READ, true)
77+
configurer?.configureBootstrap(bootstrap, configuration)
78+
}
8079

81-
protected fun createBossEventLoopGroup(): EventLoopGroup {
82-
return NioEventLoopGroup()
83-
}
80+
protected abstract fun createBootstrap(): B
8481

85-
protected fun createWorkerEventLoopGroup(): EventLoopGroup {
86-
val group = NioEventLoopGroup(configuration.workerThreadsCount)
87-
logger.debug(
88-
"Created worker EventLoopGroup with {} executor threads",
89-
group.executorCount()
90-
)
91-
return group
92-
}
82+
protected fun createBossEventLoopGroup(): EventLoopGroup = NioEventLoopGroup()
9383

94-
protected var channel: Channel?
95-
get() = channelRef.get()
96-
protected set(channel) {
97-
channelRef.set(channel)
84+
protected fun createWorkerEventLoopGroup(): EventLoopGroup {
85+
val group = NioEventLoopGroup(configuration.workerThreadsCount)
86+
logger.debug(
87+
"Created worker EventLoopGroup with {} executor threads",
88+
group.executorCount(),
89+
)
90+
return group
9891
}
9992

100-
init {
101-
if (configuration.shouldAddEchoMessageListener()) {
102-
messageHandler.addListener(EchoMessageListener(isoMessageFactory))
93+
protected var channel: Channel?
94+
get() = channelRef.get()
95+
protected set(channel) {
96+
channelRef.set(channel)
97+
}
98+
99+
init {
100+
if (configuration.shouldAddEchoMessageListener()) {
101+
messageHandler.addListener(EchoMessageListener(isoMessageFactory))
102+
}
103103
}
104104
}
105-
}

0 commit comments

Comments
 (0)