mirror of
https://github.com/valitydev/jrekt-8583.git
synced 2024-11-06 01:15:18 +00:00
Ft/some changes (#15)
* Changed IdleEventHandler * Added IdleMessageFactory Co-authored-by: Inal Arsanukaev <inalarsanukaev@MacBook-Pro-Inal.local>
This commit is contained in:
parent
5335f67e5e
commit
709d5cb308
2
pom.xml
2
pom.xml
@ -11,7 +11,7 @@
|
||||
|
||||
<groupId>com.rbkmoney.jrekt8583</groupId>
|
||||
<artifactId>netty-iso8583</artifactId>
|
||||
<version>0.2.9</version>
|
||||
<version>0.2.10</version>
|
||||
|
||||
<name>ISO8583 Connector for Netty</name>
|
||||
<description>
|
||||
|
@ -2,7 +2,7 @@ package com.rbkmoney.jrekt8583;
|
||||
|
||||
import com.rbkmoney.jrekt8583.netty.pipeline.CompositeIsoMessageHandler;
|
||||
import com.rbkmoney.jrekt8583.netty.pipeline.EchoMessageListener;
|
||||
import com.rbkmoney.jrekt8583.netty.pipeline.AbstractIdleEventHandler;
|
||||
import com.rbkmoney.jrekt8583.netty.pipeline.IdleEventHandler;
|
||||
import com.rbkmoney.jrekt8583.netty.pipeline.IsoMessageLoggingHandler;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
@ -33,7 +33,7 @@ public abstract class ConnectorConfiguration {
|
||||
private IsoField[] sensitiveDataFields;
|
||||
private boolean logFieldDescription;
|
||||
private final int frameLengthFieldLength;
|
||||
private AbstractIdleEventHandler idleEventHandler;
|
||||
private IdleEventHandler idleEventHandler;
|
||||
|
||||
protected ConnectorConfiguration(final Builder builder) {
|
||||
addLoggingHandler = builder.addLoggingHandler;
|
||||
@ -139,7 +139,7 @@ public abstract class ConnectorConfiguration {
|
||||
* Returns custom IdleEventHandler
|
||||
* @return IdleEventHandler
|
||||
*/
|
||||
public AbstractIdleEventHandler getIdleEventHandler() {
|
||||
public IdleEventHandler getIdleEventHandler() {
|
||||
return idleEventHandler;
|
||||
}
|
||||
|
||||
@ -153,7 +153,7 @@ public abstract class ConnectorConfiguration {
|
||||
private int workerThreadsCount = 0; // use netty default
|
||||
private IsoField[] sensitiveDataFields;
|
||||
private int frameLengthFieldLength = DEFAULT_FRAME_LENGTH_FIELD_LENGTH;
|
||||
private AbstractIdleEventHandler idleEventHandler;
|
||||
private IdleEventHandler idleEventHandler;
|
||||
|
||||
public B addEchoMessageListener() {
|
||||
this.addEchoMessageListener = true;
|
||||
@ -180,7 +180,7 @@ public abstract class ConnectorConfiguration {
|
||||
return (B) this;
|
||||
}
|
||||
|
||||
public B withIdleEventHandler(AbstractIdleEventHandler idleEventHandler) {
|
||||
public B withIdleEventHandler(IdleEventHandler idleEventHandler) {
|
||||
this.idleEventHandler = idleEventHandler;
|
||||
return (B) this;
|
||||
}
|
||||
|
@ -1,27 +1,28 @@
|
||||
package com.rbkmoney.jrekt8583.netty.pipeline;
|
||||
|
||||
import com.solab.iso8583.IsoMessage;
|
||||
import com.solab.iso8583.MessageFactory;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.handler.timeout.IdleState;
|
||||
import io.netty.handler.timeout.IdleStateEvent;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@ChannelHandler.Sharable
|
||||
public abstract class AbstractIdleEventHandler extends ChannelInboundHandlerAdapter {
|
||||
public class IdleEventHandler extends ChannelInboundHandlerAdapter {
|
||||
|
||||
private final IdleMessageFactory idleMessageFactory;
|
||||
|
||||
@Override
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
|
||||
if (evt instanceof IdleStateEvent) {
|
||||
IdleStateEvent e = (IdleStateEvent) evt;
|
||||
if (e.state() == IdleState.READER_IDLE || e.state() == IdleState.ALL_IDLE) {
|
||||
final IsoMessage echoMessage = createEchoMessage();
|
||||
final IsoMessage echoMessage = idleMessageFactory.newMessage();
|
||||
ctx.write(echoMessage);
|
||||
ctx.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract IsoMessage createEchoMessage();
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.rbkmoney.jrekt8583.netty.pipeline;
|
||||
|
||||
import com.solab.iso8583.IsoMessage;
|
||||
|
||||
public interface IdleMessageFactory {
|
||||
IsoMessage newMessage();
|
||||
}
|
@ -42,7 +42,7 @@ public class Iso8583ChannelInitializer<
|
||||
private final Iso8583Encoder isoMessageEncoder;
|
||||
private final ChannelHandler loggingHandler;
|
||||
private final ChannelHandler parseExceptionHandler;
|
||||
private final AbstractIdleEventHandler idleEventHandler;
|
||||
private final IdleEventHandler idleEventHandler;
|
||||
|
||||
public Iso8583ChannelInitializer(
|
||||
C configuration,
|
||||
@ -116,15 +116,11 @@ public class Iso8583ChannelInitializer<
|
||||
}
|
||||
|
||||
|
||||
private AbstractIdleEventHandler createIdleEventHandler(C configuration) {
|
||||
private IdleEventHandler createIdleEventHandler(C configuration) {
|
||||
if (configuration.getIdleEventHandler() != null) {
|
||||
return configuration.getIdleEventHandler();
|
||||
}
|
||||
return new AbstractIdleEventHandler() {
|
||||
@Override
|
||||
protected IsoMessage createEchoMessage() {
|
||||
return isoMessageFactory.newMessage(0x800);
|
||||
}
|
||||
return new IdleEventHandler(() -> isoMessageFactory.newMessage(0x800)) {
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user