Class Plc4XS7Protocol

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelDuplexHandler
io.netty.handler.codec.MessageToMessageCodec<INBOUND_IN,​OUTBOUND_IN>
org.apache.plc4x.java.base.PlcMessageToMessageCodec<S7Message,​PlcRequestContainer>
org.apache.plc4x.java.s7.netty.Plc4XS7Protocol
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler, io.netty.channel.ChannelOutboundHandler

public class Plc4XS7Protocol
extends PlcMessageToMessageCodec<S7Message,​PlcRequestContainer>
This layer transforms between PlcRequestContainers S7Messages. And stores all "in-flight" requests in an internal structure (requests).

While sending a request, a S7RequestMessage is generated and send downstream (to the S7Protocol.

When a S7ResponseMessage is received it takes the existing request container from its Map and finishes the PlcRequestContainers future with the PlcResponse.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler

    io.netty.channel.ChannelHandler.Sharable
  • Constructor Summary

    Constructors 
    Constructor Description
    Plc4XS7Protocol()  
  • Method Summary

    Modifier and Type Method Description
    protected void decode​(io.netty.channel.ChannelHandlerContext ctx, S7Message msg, List<Object> out)  
    protected void encode​(io.netty.channel.ChannelHandlerContext ctx, PlcRequestContainer msg, List<Object> out)  
    void exceptionCaught​(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)
    When receiving an error inside the pipeline, we have to find out which PlcRequestContainer correlates needs to be notified about the problem.
    static int getUDIntAt​(byte[] buffer, int pos)  
    void userEventTriggered​(io.netty.channel.ChannelHandlerContext ctx, Object evt)
    If this protocol layer catches an S7ConnectedEvent from the protocol layer beneath, the connection establishment is finished.

    Methods inherited from class org.apache.plc4x.java.base.PlcMessageToMessageCodec

    getPrevChannelHandler

    Methods inherited from class io.netty.handler.codec.MessageToMessageCodec

    acceptInboundMessage, acceptOutboundMessage, channelRead, write

    Methods inherited from class io.netty.channel.ChannelDuplexHandler

    bind, close, connect, deregister, disconnect, flush, read

    Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter

    channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged

    Methods inherited from class io.netty.channel.ChannelHandlerAdapter

    ensureNotSharable, handlerAdded, handlerRemoved, isSharable

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.netty.channel.ChannelHandler

    handlerAdded, handlerRemoved
  • Constructor Details

  • Method Details

    • userEventTriggered

      public void userEventTriggered​(io.netty.channel.ChannelHandlerContext ctx, Object evt) throws Exception
      If this protocol layer catches an S7ConnectedEvent from the protocol layer beneath, the connection establishment is finished.
      Specified by:
      userEventTriggered in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      userEventTriggered in class io.netty.channel.ChannelInboundHandlerAdapter
      Parameters:
      ctx - the current protocol layers context
      evt - the event
      Throws:
      Exception - throws an exception if something goes wrong internally
    • exceptionCaught

      public void exceptionCaught​(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) throws Exception
      When receiving an error inside the pipeline, we have to find out which PlcRequestContainer correlates needs to be notified about the problem. If a container is found, we can relay the exception to that by calling completeExceptionally and passing in the exception.
      Specified by:
      exceptionCaught in interface io.netty.channel.ChannelHandler
      Specified by:
      exceptionCaught in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      exceptionCaught in class io.netty.channel.ChannelInboundHandlerAdapter
      Parameters:
      ctx - the current protocol layers context
      cause - the exception that was caught
      Throws:
      Exception - throws an exception if something goes wrong internally
    • encode

      protected void encode​(io.netty.channel.ChannelHandlerContext ctx, PlcRequestContainer msg, List<Object> out) throws PlcException
      Specified by:
      encode in class io.netty.handler.codec.MessageToMessageCodec<S7Message,​PlcRequestContainer>
      Throws:
      PlcException
    • decode

      protected void decode​(io.netty.channel.ChannelHandlerContext ctx, S7Message msg, List<Object> out) throws PlcException
      Specified by:
      decode in class io.netty.handler.codec.MessageToMessageCodec<S7Message,​PlcRequestContainer>
      Throws:
      PlcException
    • getUDIntAt

      public static int getUDIntAt​(byte[] buffer, int pos)