Skip to content

Commit

Permalink
#158 Change visibility in Kotlin to public
Browse files Browse the repository at this point in the history
  • Loading branch information
kpavlov authored and kpavlov committed Sep 14, 2024
1 parent e140243 commit 5502a5d
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ public abstract class AbstractIso8583Connector<
C : ConnectorConfiguration,
B : AbstractBootstrap<B, *>,
M : IsoMessage>
internal constructor(
protected constructor(
configuration: C,
isoMessageFactory: MessageFactory<M>,
messageHandler: CompositeIsoMessageHandler<M> = CompositeIsoMessageHandler()
protected val messageHandler: CompositeIsoMessageHandler<M> = CompositeIsoMessageHandler()
) {

protected val logger: Logger = LoggerFactory.getLogger(javaClass)

internal val messageHandler: CompositeIsoMessageHandler<M>
public val isoMessageFactory: MessageFactory<M> = isoMessageFactory
private val channelRef = AtomicReference<Channel>()
protected val configuration: C = configuration
Expand Down Expand Up @@ -98,9 +97,7 @@ internal constructor(
channelRef.set(channel)
}

// @VisibleForTest
init {
this.messageHandler = messageHandler
if (configuration.shouldAddEchoMessageListener()) {
messageHandler.addListener(EchoMessageListener(isoMessageFactory))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public open class Iso8583Client<T : IsoMessage>(
return connectFuture
}

override fun createBootstrap(): Bootstrap {
public override fun createBootstrap(): Bootstrap {
val b = Bootstrap()
b.group(bossEventLoopGroup)
.channel(NioSocketChannel::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IsoMessage>) :
public class Iso8583Decoder(private val messageFactory: MessageFactory<IsoMessage>) :
ByteToMessageDecoder() {

/**
Expand All @@ -32,10 +32,6 @@ internal class Iso8583Decoder(private val messageFactory: MessageFactory<IsoMess
val bytes = ByteArray(byteBuf.readableBytes())
byteBuf.readBytes(bytes)
val isoMessage = messageFactory.parseMessage(bytes, 0)
if (isoMessage != null) {
out.add(isoMessage)
} else {
throw ParseException("Can't parse ISO8583 message", 0)
}
out.add(isoMessage)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import io.netty.handler.codec.MessageToByteEncoder
import io.netty.util.CharsetUtil

@Sharable
internal class Iso8583Encoder(
public class Iso8583Encoder(
private val lengthHeaderLength: Int,
private val encodeLengthHeaderAsString: Boolean
) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,21 @@ import io.netty.util.CharsetUtil
import java.nio.ByteOrder

/**
* Netty's [LengthFieldBasedFrameDecoder] assumes the frame length header
* is a binary encoded integer.
* This overrides it's frame length decoding to implement the case when
* the frame length header is String encoded.
*
* Netty's [LengthFieldBasedFrameDecoder] assumes the frame length header is a binary encoded
* integer. This overrides it's frame length decoding to implement the case when the frame length
* header is String encoded.
*
* Uses [CharsetUtil.US_ASCII] for decoding
*/
internal open class StringLengthFieldBasedFrameDecoder

/**
* @param maxFrameLength the maximum length of the frame. If the length of the frame is
* greater than this value, `TooLongFrameException` will be
* thrown.
* @param lengthFieldOffset the offset of the length field
* @param lengthFieldLength the length of the length field
* @param lengthAdjustment the compensation value to add to the value of the length field
*
* @param maxFrameLength the maximum length of the frame. If the length of the frame is greater than
* this value, `TooLongFrameException` will be thrown.
* @param lengthFieldOffset the offset of the length field
* @param lengthFieldLength the length of the length field
* @param lengthAdjustment the compensation value to add to the value of the length field
* @param initialBytesToStrip the number of first bytes to strip out from the decoded frame
* @see LengthFieldBasedFrameDecoder
*/
constructor(
public open class StringLengthFieldBasedFrameDecoder(
maxFrameLength: Int,
lengthFieldOffset: Int,
lengthFieldLength: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ import io.netty.channel.ChannelInboundHandlerAdapter
import org.slf4j.LoggerFactory
import java.util.concurrent.CopyOnWriteArrayList

/**
* Handles [IsoMessage] s with chain of [IsoMessageListener]s.
*/
/** Handles [IsoMessage] s with chain of [IsoMessageListener]s. */
@Sharable
internal class CompositeIsoMessageHandler<T : IsoMessage> @JvmOverloads constructor(
public open class CompositeIsoMessageHandler<T : IsoMessage> @JvmOverloads constructor(
private val failOnError: Boolean = true
) : ChannelInboundHandlerAdapter() {

Expand All @@ -21,7 +19,7 @@ internal class CompositeIsoMessageHandler<T : IsoMessage> @JvmOverloads construc
private val messageListeners: MutableList<IsoMessageListener<T>> = 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) {
Expand All @@ -36,7 +34,7 @@ internal class CompositeIsoMessageHandler<T : IsoMessage> @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
Expand All @@ -57,7 +55,7 @@ internal class CompositeIsoMessageHandler<T : IsoMessage> @JvmOverloads construc
}

@Suppress("TooGenericExceptionCaught")
private fun handleWithMessageListener(
protected fun handleWithMessageListener(
messageListener: IsoMessageListener<T>,
isoMessage: T,
ctx: ChannelHandlerContext
Expand All @@ -83,18 +81,18 @@ internal class CompositeIsoMessageHandler<T : IsoMessage> @JvmOverloads construc
return true
}

fun addListener(listener: IsoMessageListener<T>) {
public fun addListener(listener: IsoMessageListener<T>) {
messageListeners.add(listener)
}

@SafeVarargs
fun addListeners(vararg listeners: IsoMessageListener<T>) {
public fun addListeners(vararg listeners: IsoMessageListener<T>) {
for (listener in listeners) {
addListener(listener)
}
}

fun removeListener(listener: IsoMessageListener<T>) {
public fun removeListener(listener: IsoMessageListener<T>) {
messageListeners.remove(listener)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import com.github.kpavlov.jreactive8583.iso.MessageFactory
import com.solab.iso8583.IsoMessage
import io.netty.channel.ChannelHandlerContext

internal class EchoMessageListener<T : IsoMessage>(
public open class EchoMessageListener<T : IsoMessage>(
private val isoMessageFactory: MessageFactory<T>
) : IsoMessageListener<T> {

override fun applies(isoMessage: T): Boolean {
public override fun applies(isoMessage: T): Boolean {
return isoMessage.type and MessageClass.NETWORK_MANAGEMENT.value != 0
}

Expand All @@ -20,7 +20,7 @@ internal class EchoMessageListener<T : IsoMessage>(
* @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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(
public open class IdleEventHandler<T>(
private val isoMessageFactory: MessageFactory<T>
) : 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)
) {
Expand All @@ -26,7 +26,7 @@ internal class IdleEventHandler<T>(
}
}

private fun createHeartbeatMessage(): T {
protected fun createHeartbeatMessage(): T {
return isoMessageFactory.newMessage(
MessageClass.NETWORK_MANAGEMENT,
MessageFunction.REQUEST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import io.netty.handler.timeout.IdleStateHandler
public open class Iso8583ChannelInitializer<T : Channel,
B : AbstractBootstrap<*, *>,
C : ConnectorConfiguration>
internal constructor(
public constructor(
private val configuration: C,
private val configurer: ConnectorConfigurer<C, B>?,
private val workerGroup: EventLoopGroup,
Expand Down Expand Up @@ -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<IsoMessage>): Iso8583Decoder {
protected fun createIso8583Decoder(messageFactory: MessageFactory<IsoMessage>): Iso8583Decoder {
return Iso8583Decoder(messageFactory)
}

private fun createLoggingHandler(configuration: C): ChannelHandler {
protected fun createLoggingHandler(configuration: C): ChannelHandler {
return IsoMessageLoggingHandler(
LogLevel.DEBUG,
configuration.logSensitiveData(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -111,7 +111,7 @@ internal class IsoMessageLoggingHandler(
return sb.toString()
}

private fun getFormattedValue(field: IsoValue<Any>, i: Int): CharArray {
protected fun getFormattedValue(field: IsoValue<Any>, i: Int): CharArray {
return if (printSensitiveData) {
field.toString().toCharArray()
} else {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public open class Iso8583Server<T : IsoMessage>(
).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"))
Expand All @@ -56,7 +56,7 @@ public open class Iso8583Server<T : IsoMessage>(
return bootstrap
}

override fun shutdown() {
public override fun shutdown() {
stop()
super.shutdown()
}
Expand Down

0 comments on commit 5502a5d

Please sign in to comment.