@@ -19,87 +19,86 @@ import java.util.concurrent.atomic.AtomicReference
1919public 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