Skip to content

Commit

Permalink
fix(plc4j/drivers/s7): fix NoSuchElementException when watchdog Chann…
Browse files Browse the repository at this point in the history
…elHandler was not added yet & fix exception "MessageToMessageCodec$1 must produce at least one message." & fix some typos (#1873)

* fix(plc4j/drivers/s7): fix NoSuchElementException when watchdog ChannelHandler was not added yet & fix unnecessary warning in logfile/console due to exception "MessageToMessageCodec$1 must produce at least one message."

* fix(plc4j/drivers/s7): fix some typos

* fix(plc4j/drivers/s7): delete 2 duplicate classes, the used ones are located in org.apache.plc4x.java.s7.readwrite.protocol

* Revert "fix(plc4j/drivers/s7): delete 2 duplicate classes, the used ones are located in org.apache.plc4x.java.s7.readwrite.protocol"

This reverts commit 5b1cc09.

---------

Co-authored-by: Jochen Meierhofer <[email protected]>
  • Loading branch information
jmeierhofer and Jochen Meierhofer authored Nov 11, 2024
1 parent 4860be3 commit 9856bb7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.embedded.EmbeddedChannel;
Expand Down Expand Up @@ -130,9 +131,8 @@ protected void encode(ChannelHandlerContext ctx, ByteBuf outBB, List<Object> lis
if ((embedCtx == null) && (ctx.channel() instanceof EmbeddedChannel)) embedCtx = ctx;
if ((tcpChannel != null) && (embedCtx == ctx)) {
tcpChannel.writeAndFlush(outBB.copy());
} else {
list.add(outBB.copy());
}
list.add(outBB.copy());
}

/*
Expand Down Expand Up @@ -175,9 +175,14 @@ public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exceptio
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
super.userEventTriggered(ctx, evt);
logger.info(LocalTime.now() + " userEventTriggered: " + ctx.name() + " Event: " + evt);

if (evt instanceof ConnectedEvent) {
try {
tcpChannel.pipeline().remove("watchdog");
ChannelHandler watchdog = tcpChannel.pipeline().get("watchdog");
if (watchdog != null) {
tcpChannel.pipeline().remove(watchdog);
}

} catch (Exception ex) {
logger.info(ex.toString());
}
Expand All @@ -199,7 +204,6 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc
if (evt instanceof DisconnectEvent) {
logger.info("DisconnectEvent");
}

}

@Override
Expand Down Expand Up @@ -250,7 +254,6 @@ public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
embededChannel.pipeline().fireUserEventTriggered(new ConnectEvent());
}
}
;


if ((tcpChannel == secondaryChannel) &&
Expand All @@ -265,10 +268,8 @@ public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
embededChannel.pipeline().fireUserEventTriggered(new ConnectEvent());
}
}

}


@Override
public void setEmbededhannel(Channel embeded_channel, PlcConnectionConfiguration configuration) {
final S7Configuration conf = (S7Configuration) configuration;
Expand Down Expand Up @@ -351,5 +352,4 @@ public Channel getTCPChannel() {
return tcpChannel;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public void doSecondaryTcpConnections() {
* The user application must take the measures to make the connection again.
*/
protected void sendChannelDisconectEvent() {
logger.trace("Channels was not created, firing DisconnectEvent Event");
logger.trace("Channel was not created, firing DisconnectEvent Event");
// Send an event to the pipeline telling the Protocol filters what's going on.
channel.pipeline().fireUserEventTriggered(new DisconnectEvent());
}
Expand Down Expand Up @@ -351,7 +351,7 @@ public void run() {

if (primaryChannel != null) {
if (!primaryChannel.isActive()) {
logger.info("Creating prymary connection.");
logger.info("Creating primary connection.");
primaryChannel.eventLoop().shutdownGracefully();
doPrimaryTcpConnections();
} else if (null == secondaryChannel) {
Expand All @@ -364,7 +364,7 @@ public void run() {
}
}
} else {
logger.info("Creating firts prymary connection.");
logger.info("Creating first primary connection.");
doPrimaryTcpConnections();
}

Expand All @@ -384,7 +384,7 @@ public void run() {
}
} else {
if (secondaryChannelFactory != null) {
logger.info("Creating firts secondary connection.");
logger.info("Creating first secondary connection.");
doSecondaryTcpConnections();
}
}
Expand Down

0 comments on commit 9856bb7

Please sign in to comment.