Class RpcProgram

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
org.apache.hadoop.oncrpc.RpcProgram
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler

public abstract class RpcProgram extends io.netty.channel.ChannelInboundHandlerAdapter
Class for writing RPC server programs based on RFC 1050. Extend this class and implement handleInternal(io.netty.channel.ChannelHandlerContext, org.apache.hadoop.oncrpc.RpcInfo) to handle the requests received.
  • Nested Class Summary

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

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

    Fields
    Modifier and Type
    Field
    Description
    protected final boolean
     
    static final int
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    RpcProgram(String program, String host, int port, int progNumber, int lowProgVersion, int highProgVersion, DatagramSocket registrationSocket, boolean allowInsecurePorts)
     
    protected
    RpcProgram(String program, String host, int port, int progNumber, int lowProgVersion, int highProgVersion, DatagramSocket registrationSocket, boolean allowInsecurePorts, int portmapUdpTimeoutMillis)
    Constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg)
     
    boolean
     
    int
     
    int
     
    protected abstract void
    handleInternal(io.netty.channel.ChannelHandlerContext ctx, RpcInfo info)
     
    protected abstract boolean
     
    void
    register(int transport, int boundPort)
    Register this program with the local portmapper.
    protected void
    register(PortmapMapping mapEntry, boolean set)
    Register the program with Portmap or Rpcbind.
    protected static void
    sendRejectedReply(RpcCall call, SocketAddress remoteAddress, io.netty.channel.ChannelHandlerContext ctx)
     
    void
     
    void
     
     
    void
    unregister(int transport, int boundPort)
    Unregister this program with the local portmapper.

    Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter

    channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered

    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, wait, wait, wait

    Methods inherited from interface io.netty.channel.ChannelHandler

    handlerAdded, handlerRemoved
  • Field Details

    • RPCB_PORT

      public static final int RPCB_PORT
      See Also:
    • allowInsecurePorts

      protected final boolean allowInsecurePorts
  • Constructor Details

    • RpcProgram

      protected RpcProgram(String program, String host, int port, int progNumber, int lowProgVersion, int highProgVersion, DatagramSocket registrationSocket, boolean allowInsecurePorts)
    • RpcProgram

      protected RpcProgram(String program, String host, int port, int progNumber, int lowProgVersion, int highProgVersion, DatagramSocket registrationSocket, boolean allowInsecurePorts, int portmapUdpTimeoutMillis)
      Constructor
      Parameters:
      program - program name
      host - host where the Rpc server program is started
      port - port where the Rpc server program is listening to
      progNumber - program number as defined in RFC 1050
      lowProgVersion - lowest version of the specification supported
      highProgVersion - highest version of the specification supported
      registrationSocket - if not null, use this socket to register with portmap daemon
      allowInsecurePorts - true to allow client connections from unprivileged ports, false otherwise
      portmapUdpTimeoutMillis - timeout in milliseconds for RPC connection
  • Method Details

    • register

      public void register(int transport, int boundPort)
      Register this program with the local portmapper.
      Parameters:
      transport - transport layer for port map
      boundPort - port number of bounded RPC program
    • unregister

      public void unregister(int transport, int boundPort)
      Unregister this program with the local portmapper.
      Parameters:
      transport - transport layer for port map
      boundPort - port number of bounded RPC program
    • register

      protected void register(PortmapMapping mapEntry, boolean set)
      Register the program with Portmap or Rpcbind.
      Parameters:
      mapEntry - port map entries
      set - specifies registration or not
    • startDaemons

      public void startDaemons()
    • stopDaemons

      public void stopDaemons()
    • channelRead

      public void channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) throws Exception
      Specified by:
      channelRead in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelRead in class io.netty.channel.ChannelInboundHandlerAdapter
      Throws:
      Exception
    • doPortMonitoring

      public boolean doPortMonitoring(SocketAddress remoteAddress)
    • sendRejectedReply

      protected static void sendRejectedReply(RpcCall call, SocketAddress remoteAddress, io.netty.channel.ChannelHandlerContext ctx)
    • handleInternal

      protected abstract void handleInternal(io.netty.channel.ChannelHandlerContext ctx, RpcInfo info)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • isIdempotent

      protected abstract boolean isIdempotent(RpcCall call)
    • getPort

      public int getPort()
    • getPortmapUdpTimeoutMillis

      @VisibleForTesting public int getPortmapUdpTimeoutMillis()