Skip to content

Commit

Permalink
Konvert to Kotlin (#115)
Browse files Browse the repository at this point in the history
* Konvert to Kotlin
  • Loading branch information
kpavlov authored Aug 6, 2020
1 parent 6391c84 commit e830472
Show file tree
Hide file tree
Showing 28 changed files with 88 additions and 99 deletions.
6 changes: 4 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
<j8583.version>1.17.0</j8583.version>
<junit.version>5.6.2</junit.version>
<kotlin.version>1.3.72</kotlin.version>
<mockito.version>3.4.3</mockito.version>
<mockito.version>3.4.6</mockito.version>
<netty.version>4.1.51.Final</netty.version>
<slf4j.version>1.7.30</slf4j.version>
<spring.version>5.2.7.RELEASE</spring.version>
<spring.version>5.2.8.RELEASE</spring.version>
</properties>

<description>ISO8583 protocol client and server Netty connectors.</description>
Expand Down Expand Up @@ -196,6 +196,8 @@
</dependencyManagement>

<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import io.netty.channel.nio.NioEventLoopGroup
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.lang.Boolean.parseBoolean
import java.net.SocketAddress
import java.util.concurrent.atomic.AtomicReference

abstract class AbstractIso8583Connector<
Expand All @@ -32,9 +31,8 @@ protected constructor(
val messageHandler: CompositeIsoMessageHandler<M>
val isoMessageFactory: MessageFactory<M>
private val channelRef = AtomicReference<Channel>()
protected val configuration: C
protected val configuration: C = configuration
var configurer: ConnectorConfigurer<C, B>? = null
lateinit var socketAddress: SocketAddress
protected lateinit var bossEventLoopGroup: EventLoopGroup
private set
protected lateinit var workerEventLoopGroup: EventLoopGroup
Expand Down Expand Up @@ -94,15 +92,14 @@ protected constructor(
return group
}

protected var channel: Channel
protected var channel: Channel?
get() = channelRef.get()
protected set(channel) {
channelRef.set(channel)
}

// @VisibleForTest
init {
this.configuration = configuration
this.isoMessageFactory = isoMessageFactory
this.messageHandler = messageHandler
if (configuration.shouldAddEchoMessageListener()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ abstract class ConnectorConfiguration protected constructor(b: Builder<*>) {
}

@Suppress("UNCHECKED_CAST")
protected open class Builder<B : Builder<B>> {
open class Builder<B : Builder<B>> {
var addLoggingHandler = false
var addEchoMessageListener = false
var logFieldDescription = true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
@file:JvmName("ClientConfiguration")

package com.github.kpavlov.jreactive8583.client

import com.github.kpavlov.jreactive8583.ConnectorConfiguration

open class ClientConfiguration(
builder: Builder
) : ConnectorConfiguration(builder) {

/**
* Client reconnect interval in milliseconds.
*
* @return interval between reconnects, in milliseconds.
*/
val reconnectInterval: Int = builder.reconnectInterval

companion object {

/**
* Default client reconnect interval in milliseconds.
*/
const val DEFAULT_RECONNECT_INTERVAL = 100

@JvmStatic
fun newBuilder(): Builder = Builder()

@Suppress("unused")
@JvmStatic
fun getDefault(): ClientConfiguration = newBuilder().build()
}

@Suppress("unused")
data class Builder(
var reconnectInterval: Int = DEFAULT_RECONNECT_INTERVAL
) : ConnectorConfiguration.Builder<Builder>() {

fun reconnectInterval(reconnectInterval: Int) =
apply { this.reconnectInterval = reconnectInterval }

fun build() = ClientConfiguration(this)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,15 @@ import java.net.InetSocketAddress
import java.net.SocketAddress
import java.util.concurrent.TimeUnit

open class Iso8583Client<T : IsoMessage> :
AbstractIso8583Connector<ClientConfiguration, Bootstrap, T> {
open class Iso8583Client<T : IsoMessage>(
private var socketAddress: SocketAddress,
config: ClientConfiguration,
isoMessageFactory: MessageFactory<T>
) :
AbstractIso8583Connector<ClientConfiguration, Bootstrap, T>(config, isoMessageFactory) {

private lateinit var reconnectOnCloseListener: ReconnectOnCloseListener

constructor(
socketAddress: SocketAddress,
config: ClientConfiguration,
isoMessageFactory: MessageFactory<T>
) : super(config, isoMessageFactory) {
this.socketAddress = socketAddress
}

/**
* Connects synchronously to remote address.
*
Expand Down Expand Up @@ -121,7 +117,7 @@ open class Iso8583Client<T : IsoMessage> :
reconnectOnCloseListener.requestDisconnect()
val channel = channel
logger.info("Closing connection to {}", socketAddress)
return channel.close()
return channel?.close()
}

@Throws(InterruptedException::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package com.github.kpavlov.jreactive8583.iso
*
* @see [](https://en.wikipedia.org/wiki/ISO_8583.Message_type_indicator_)
) */
@Suppress("unused")
enum class ISO8583Version
/**
* @param value A first digit in Message type indicator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package com.github.kpavlov.jreactive8583.iso
*
* @see [](https://en.wikipedia.org/wiki/ISO_8583.Message_type_indicator_)
) */
@Suppress("unused")
enum class MessageClass(val value: Int) {
/**
* x1xx Authorization message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

package com.github.kpavlov.jreactive8583.iso

@Suppress("unused")
enum class MessageFunction(val value: Int) {
/**
* xx0x Request Request from acquirer to issuer to carry out an action; issuer may accept or reject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

package com.github.kpavlov.jreactive8583.iso

@Suppress("unused")
enum class MessageOrigin(val value: Int) {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ class IdleEventHandler(

override fun userEventTriggered(ctx: ChannelHandlerContext, evt: Any) {
if (evt is IdleStateEvent) {
val e = evt
if (e.state() == IdleState.READER_IDLE || e.state() == IdleState.ALL_IDLE) {
if (evt.state() == IdleState.READER_IDLE || evt.state() == IdleState.ALL_IDLE) {
val echoMessage = createEchoMessage()
ctx.write(echoMessage)
ctx.flush()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import io.netty.handler.codec.LengthFieldBasedFrameDecoder
import io.netty.handler.logging.LogLevel
import io.netty.handler.timeout.IdleStateHandler

class Iso8583ChannelInitializer<T : Channel,
open class Iso8583ChannelInitializer<T : Channel,
B : AbstractBootstrap<*, *>,
C : ConnectorConfiguration>
constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ open class Iso8583Server<T : IsoMessage>(
messageFactory: MessageFactory<T>
) : AbstractIso8583Connector<ServerConfiguration, ServerBootstrap, T>(config, messageFactory) {

init {
socketAddress = InetSocketAddress(port)
}
private var socketAddress = InetSocketAddress(port)

@Throws(InterruptedException::class)
fun start() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@file:JvmName("ServerConfiguration")

package com.github.kpavlov.jreactive8583.server

import com.github.kpavlov.jreactive8583.ConnectorConfiguration

@SuppressWarnings("WeakerAccess")
class ServerConfiguration(
builder: Builder
) : ConnectorConfiguration(builder) {

companion object {
@JvmStatic
fun newBuilder(): Builder = Builder()

@Suppress("unused")
@JvmStatic
fun getDefault(): ServerConfiguration = newBuilder().build()
}

class Builder : ConnectorConfiguration.Builder<Builder>() {
fun build() = ServerConfiguration(this)
}
}

0 comments on commit e830472

Please sign in to comment.