From c0df7c2f0f77e63cf47494440881bbdb28ad7769 Mon Sep 17 00:00:00 2001 From: kpavlov <{ID}+{username}@users.noreply.github.com> Date: Sat, 14 Sep 2024 12:59:47 +0300 Subject: [PATCH] #158 Change visibility in Kotlin to public --- .../jreactive8583/AbstractIso8583Connector.kt | 7 ++--- .../client/ClientConfiguration.kt | 2 +- .../jreactive8583/client/Iso8583Client.kt | 2 +- .../netty/codec/Iso8583Decoder.kt | 8 ++---- .../netty/codec/Iso8583Encoder.kt | 2 +- .../StringLengthFieldBasedFrameDecoder.kt | 26 +++++++------------ .../pipeline/CompositeIsoMessageHandler.kt | 18 ++++++------- .../netty/pipeline/EchoMessageListener.kt | 6 ++--- .../netty/pipeline/IdleEventHandler.kt | 6 ++--- .../pipeline/Iso8583ChannelInitializer.kt | 10 +++---- .../pipeline/IsoMessageLoggingHandler.kt | 12 ++++----- .../netty/pipeline/ParseExceptionHandler.kt | 2 +- .../pipeline/ReconnectOnCloseListener.kt | 11 ++++---- .../jreactive8583/server/Iso8583Server.kt | 4 +-- 14 files changed, 51 insertions(+), 65 deletions(-) diff --git a/src/main/kotlin/com/github/kpavlov/jreactive8583/AbstractIso8583Connector.kt b/src/main/kotlin/com/github/kpavlov/jreactive8583/AbstractIso8583Connector.kt index f26e297d..1bb47f70 100644 --- a/src/main/kotlin/com/github/kpavlov/jreactive8583/AbstractIso8583Connector.kt +++ b/src/main/kotlin/com/github/kpavlov/jreactive8583/AbstractIso8583Connector.kt @@ -20,15 +20,14 @@ public abstract class AbstractIso8583Connector< C : ConnectorConfiguration, B : AbstractBootstrap, M : IsoMessage> -internal constructor( +protected constructor( configuration: C, isoMessageFactory: MessageFactory, - messageHandler: CompositeIsoMessageHandler = CompositeIsoMessageHandler() + protected val messageHandler: CompositeIsoMessageHandler = CompositeIsoMessageHandler() ) { protected val logger: Logger = LoggerFactory.getLogger(javaClass) - internal val messageHandler: CompositeIsoMessageHandler public val isoMessageFactory: MessageFactory = isoMessageFactory private val channelRef = AtomicReference() protected val configuration: C = configuration @@ -98,9 +97,7 @@ internal constructor( channelRef.set(channel) } - // @VisibleForTest init { - this.messageHandler = messageHandler if (configuration.shouldAddEchoMessageListener()) { messageHandler.addListener(EchoMessageListener(isoMessageFactory)) } diff --git a/src/main/kotlin/com/github/kpavlov/jreactive8583/client/ClientConfiguration.kt b/src/main/kotlin/com/github/kpavlov/jreactive8583/client/ClientConfiguration.kt index be629f44..bdf36843 100644 --- a/src/main/kotlin/com/github/kpavlov/jreactive8583/client/ClientConfiguration.kt +++ b/src/main/kotlin/com/github/kpavlov/jreactive8583/client/ClientConfiguration.kt @@ -13,7 +13,7 @@ public open class ClientConfiguration( * * @return interval between reconnects, in milliseconds. */ - internal val reconnectInterval: Int = builder.reconnectInterval + public val reconnectInterval: Int = builder.reconnectInterval public companion object { diff --git a/src/main/kotlin/com/github/kpavlov/jreactive8583/client/Iso8583Client.kt b/src/main/kotlin/com/github/kpavlov/jreactive8583/client/Iso8583Client.kt index 57976dd6..f0855c5d 100644 --- a/src/main/kotlin/com/github/kpavlov/jreactive8583/client/Iso8583Client.kt +++ b/src/main/kotlin/com/github/kpavlov/jreactive8583/client/Iso8583Client.kt @@ -89,7 +89,7 @@ public open class Iso8583Client( return connectFuture } - override fun createBootstrap(): Bootstrap { + public override fun createBootstrap(): Bootstrap { val b = Bootstrap() b.group(bossEventLoopGroup) .channel(NioSocketChannel::class.java) diff --git a/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/codec/Iso8583Decoder.kt b/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/codec/Iso8583Decoder.kt index f937edd2..b5d02fc2 100644 --- a/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/codec/Iso8583Decoder.kt +++ b/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/codec/Iso8583Decoder.kt @@ -9,7 +9,7 @@ import io.netty.channel.ChannelHandlerContext import io.netty.handler.codec.ByteToMessageDecoder import java.text.ParseException -internal class Iso8583Decoder(private val messageFactory: MessageFactory) : +public class Iso8583Decoder(private val messageFactory: MessageFactory) : ByteToMessageDecoder() { /** @@ -32,10 +32,6 @@ internal class Iso8583Decoder(private val messageFactory: MessageFactory @JvmOverloads constructor( +public open class CompositeIsoMessageHandler @JvmOverloads constructor( private val failOnError: Boolean = true ) : ChannelInboundHandlerAdapter() { @@ -21,7 +19,7 @@ internal class CompositeIsoMessageHandler @JvmOverloads construc private val messageListeners: MutableList> = CopyOnWriteArrayList() @Throws(Exception::class) - override fun channelRead(ctx: ChannelHandlerContext, msg: Any) { + public override fun channelRead(ctx: ChannelHandlerContext, msg: Any) { val isoMessage = try { msg as? T } catch (e: ClassCastException) { @@ -36,7 +34,7 @@ internal class CompositeIsoMessageHandler @JvmOverloads construc super.channelRead(ctx, msg) } - private fun doHandleMessage(ctx: ChannelHandlerContext, isoMessage: T) { + protected fun doHandleMessage(ctx: ChannelHandlerContext, isoMessage: T) { var applyNextListener = true val size = messageListeners.size var i = 0 @@ -57,7 +55,7 @@ internal class CompositeIsoMessageHandler @JvmOverloads construc } @Suppress("TooGenericExceptionCaught") - private fun handleWithMessageListener( + protected fun handleWithMessageListener( messageListener: IsoMessageListener, isoMessage: T, ctx: ChannelHandlerContext @@ -83,18 +81,18 @@ internal class CompositeIsoMessageHandler @JvmOverloads construc return true } - fun addListener(listener: IsoMessageListener) { + public fun addListener(listener: IsoMessageListener) { messageListeners.add(listener) } @SafeVarargs - fun addListeners(vararg listeners: IsoMessageListener) { + public fun addListeners(vararg listeners: IsoMessageListener) { for (listener in listeners) { addListener(listener) } } - fun removeListener(listener: IsoMessageListener) { + public fun removeListener(listener: IsoMessageListener) { messageListeners.remove(listener) } } diff --git a/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/EchoMessageListener.kt b/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/EchoMessageListener.kt index 742dded0..2acd465d 100644 --- a/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/EchoMessageListener.kt +++ b/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/EchoMessageListener.kt @@ -6,11 +6,11 @@ import com.github.kpavlov.jreactive8583.iso.MessageFactory import com.solab.iso8583.IsoMessage import io.netty.channel.ChannelHandlerContext -internal class EchoMessageListener( +public open class EchoMessageListener( private val isoMessageFactory: MessageFactory ) : IsoMessageListener { - override fun applies(isoMessage: T): Boolean { + public override fun applies(isoMessage: T): Boolean { return isoMessage.type and MessageClass.NETWORK_MANAGEMENT.value != 0 } @@ -20,7 +20,7 @@ internal class EchoMessageListener( * @param isoMessage a message to handle * @return `false` - message should not be handled by any other handler. */ - override fun onMessage(ctx: ChannelHandlerContext, isoMessage: T): Boolean { + public override fun onMessage(ctx: ChannelHandlerContext, isoMessage: T): Boolean { val echoResponse: IsoMessage = isoMessageFactory.createResponse(isoMessage) ctx.writeAndFlush(echoResponse) return false diff --git a/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/IdleEventHandler.kt b/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/IdleEventHandler.kt index edbaf51b..cf9d5adb 100644 --- a/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/IdleEventHandler.kt +++ b/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/IdleEventHandler.kt @@ -12,11 +12,11 @@ import io.netty.handler.timeout.IdleStateEvent * IdleEventHandler sends heartbeats (administrative messages) when channel becomes idle, * i.e. `IdleStateEvent` is received. */ -internal class IdleEventHandler( +public open class IdleEventHandler( private val isoMessageFactory: MessageFactory ) : ChannelInboundHandlerAdapter() { - override fun userEventTriggered(ctx: ChannelHandlerContext, evt: Any) { + public override fun userEventTriggered(ctx: ChannelHandlerContext, evt: Any) { if (evt is IdleStateEvent && (evt.state() == IdleState.READER_IDLE || evt.state() == IdleState.ALL_IDLE) ) { @@ -26,7 +26,7 @@ internal class IdleEventHandler( } } - private fun createHeartbeatMessage(): T { + protected fun createHeartbeatMessage(): T { return isoMessageFactory.newMessage( MessageClass.NETWORK_MANAGEMENT, MessageFunction.REQUEST diff --git a/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/Iso8583ChannelInitializer.kt b/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/Iso8583ChannelInitializer.kt index 43519692..2caa36e3 100644 --- a/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/Iso8583ChannelInitializer.kt +++ b/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/Iso8583ChannelInitializer.kt @@ -34,7 +34,7 @@ import io.netty.handler.timeout.IdleStateHandler public open class Iso8583ChannelInitializer, C : ConnectorConfiguration> -internal constructor( +public constructor( private val configuration: C, private val configurer: ConnectorConfigurer?, private val workerGroup: EventLoopGroup, @@ -79,22 +79,22 @@ internal constructor( return isoMessageFactory } - private fun createParseExceptionHandler(): ChannelHandler { + protected fun createParseExceptionHandler(): ChannelHandler { return ParseExceptionHandler(isoMessageFactory, true) } - private fun createIso8583Encoder(configuration: C): Iso8583Encoder { + protected fun createIso8583Encoder(configuration: C): Iso8583Encoder { return Iso8583Encoder( configuration.frameLengthFieldLength, configuration.encodeFrameLengthAsString() ) } - private fun createIso8583Decoder(messageFactory: MessageFactory): Iso8583Decoder { + protected fun createIso8583Decoder(messageFactory: MessageFactory): Iso8583Decoder { return Iso8583Decoder(messageFactory) } - private fun createLoggingHandler(configuration: C): ChannelHandler { + protected fun createLoggingHandler(configuration: C): ChannelHandler { return IsoMessageLoggingHandler( LogLevel.DEBUG, configuration.logSensitiveData(), diff --git a/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/IsoMessageLoggingHandler.kt b/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/IsoMessageLoggingHandler.kt index 1bfad3be..7a3c8328 100644 --- a/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/IsoMessageLoggingHandler.kt +++ b/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/IsoMessageLoggingHandler.kt @@ -18,20 +18,20 @@ import java.lang.Integer.parseInt * sensitive cardholder data will be printed masked. */ @Sharable -internal class IsoMessageLoggingHandler( +public open class IsoMessageLoggingHandler( level: LogLevel, private val printSensitiveData: Boolean, private val printFieldDescriptions: Boolean, private val maskedFields: IntArray = DEFAULT_MASKED_FIELDS ) : LoggingHandler(level) { - companion object { + public companion object { private const val MASK_CHAR = '*' private val MASKED_VALUE = "***".toCharArray() @JvmField - val DEFAULT_MASKED_FIELDS = intArrayOf( + public val DEFAULT_MASKED_FIELDS: IntArray = intArrayOf( 34, // PAN extended 35, // track 2 36, // track 3 @@ -88,7 +88,7 @@ internal class IsoMessageLoggingHandler( } } - private fun formatIsoMessage(m: IsoMessage): String { + protected fun formatIsoMessage(m: IsoMessage): String { val sb = StringBuilder() if (printSensitiveData) { sb.append("Message: ").append(m.debugString()).append("\n") @@ -111,7 +111,7 @@ internal class IsoMessageLoggingHandler( return sb.toString() } - private fun getFormattedValue(field: IsoValue, i: Int): CharArray { + protected fun getFormattedValue(field: IsoValue, i: Int): CharArray { return if (printSensitiveData) { field.toString().toCharArray() } else { @@ -123,7 +123,7 @@ internal class IsoMessageLoggingHandler( } } - private fun maskPAN(fullPan: String): CharArray { + protected fun maskPAN(fullPan: String): CharArray { val maskedPan = fullPan.toCharArray() @Suppress("MagicNumber") for (i in 6 until maskedPan.size - 4) { diff --git a/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/ParseExceptionHandler.kt b/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/ParseExceptionHandler.kt index fd887e5e..1bd13185 100644 --- a/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/ParseExceptionHandler.kt +++ b/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/ParseExceptionHandler.kt @@ -23,7 +23,7 @@ public open class ParseExceptionHandler( ) : ChannelInboundHandlerAdapter() { @Deprecated("Deprecated in Java") @Throws(Exception::class) - override fun exceptionCaught( + public override fun exceptionCaught( ctx: ChannelHandlerContext, cause: Throwable ) { diff --git a/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/ReconnectOnCloseListener.kt b/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/ReconnectOnCloseListener.kt index 1c523c18..8286b9cd 100644 --- a/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/ReconnectOnCloseListener.kt +++ b/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/ReconnectOnCloseListener.kt @@ -9,29 +9,30 @@ import java.util.concurrent.ScheduledExecutorService import java.util.concurrent.TimeUnit import java.util.concurrent.atomic.AtomicBoolean -internal class ReconnectOnCloseListener( +public open class ReconnectOnCloseListener( private val client: Iso8583Client<*>, private val reconnectInterval: Int, private val executorService: ScheduledExecutorService ) : ChannelFutureListener { private val logger = LoggerFactory.getLogger(ReconnectOnCloseListener::class.java) private val disconnectRequested = AtomicBoolean(false) - fun requestReconnect() { + + public fun requestReconnect() { disconnectRequested.set(false) } - fun requestDisconnect() { + public fun requestDisconnect() { disconnectRequested.set(true) } - override fun operationComplete(future: ChannelFuture) { + public override fun operationComplete(future: ChannelFuture) { val channel = future.channel() logger.debug("Client connection was closed to {}", channel.remoteAddress()) channel.disconnect() scheduleReconnect() } - fun scheduleReconnect() { + public fun scheduleReconnect() { if (!disconnectRequested.get()) { logger.trace("Failed to connect. Will try again in {} millis", reconnectInterval) executorService.schedule( diff --git a/src/main/kotlin/com/github/kpavlov/jreactive8583/server/Iso8583Server.kt b/src/main/kotlin/com/github/kpavlov/jreactive8583/server/Iso8583Server.kt index 6fde5ed0..daffc442 100644 --- a/src/main/kotlin/com/github/kpavlov/jreactive8583/server/Iso8583Server.kt +++ b/src/main/kotlin/com/github/kpavlov/jreactive8583/server/Iso8583Server.kt @@ -32,7 +32,7 @@ public open class Iso8583Server( ).sync().await() } - override fun createBootstrap(): ServerBootstrap { + public override fun createBootstrap(): ServerBootstrap { val bootstrap = ServerBootstrap() val tcpNoDelay = java.lang.Boolean.parseBoolean(System.getProperty("nfs.rpc.tcp.nodelay", "true")) @@ -56,7 +56,7 @@ public open class Iso8583Server( return bootstrap } - override fun shutdown() { + public override fun shutdown() { stop() super.shutdown() }