ITPub博客

首页 > 大数据 > Hadoop > 迷失的RPC.getServer方法

迷失的RPC.getServer方法

原创 Hadoop 作者:William茌 时间:2015-10-09 20:09:23 0 删除 编辑
今天学习了有关RPC的有关知识,RPC(remote procedure call)是一种远程过程调用协议,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议。RPC是hadoop构建的基础。在学习的过程中有一个问题困扰了我快一天了,我并没有解决,因此就打算把这个问题放弃,在本文中记录一下。
在网上的一些资料中,我看到他们构建RPC Server端的时候写着这样的代码:

点击(此处)折叠或打开

  1. public class MyServer {
  2.     public static int PORT = 5432;
  3.     public static String IPAddress = "127.0.0.1";

  4.     public static void main(String[] args) throws Exception {
  5.         MyProxy proxy = new MyProxy();
  6.         final Server server = RPC.getServer(proxy, IPAddress, PORT, new Configuration());//困扰我的代码
  7.         server.start();
  8.     }
  9. }
对我产生困扰的是第7行代码,在hadoop1.x中有关RPC的代码中我确实找到了RPC.getServer这个方法。但是在我使用的hadoop2.4.0中我只找到了:

点击(此处)折叠或打开

  1. /**
  2.    * Construct a server for a protocol implementation instance.
  3.    *
  4.    * @param protocol the class of protocol to use
  5.    * @param instance the instance of protocol whose methods will be called
  6.    * @param conf the configuration to use
  7.    * @param bindAddress the address to bind on to listen for connection
  8.    * @param port the port to listen for connections on
  9.    * @param numHandlers the number of method handler threads to run
  10.    * @param numReaders the number of reader threads to run
  11.    * @param queueSizePerHandler the size of the queue per hander thread
  12.    * @param verbose whether each call should be logged
  13.    * @param secretManager The secret manager to use to validate incoming requests.
  14.    * @param portRangeConfig A config parameter that can be used to restrict
  15.    * the range of ports used when port is 0 (an ephemeral port)
  16.    * @return The Server instance
  17.    * @throws IOException on any error
  18.    */
  19.   RPC.Server getServer(Class<?> protocol, Object instance, String bindAddress,
  20.                        int port, int numHandlers, int numReaders,
  21.                        int queueSizePerHandler, boolean verbose,
  22.                        Configuration conf,
  23.                        SecretManager<? extends TokenIdentifier> secretManager,
  24.                        String portRangeConfig
  25.                        ) throws IOException;

  26.   
我并没有看明白这里的东西,测试代码没有写成功,希望路过的大神可以教我在hadoop2.x中构建RPC Server端。


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29876573/viewspace-1813631/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-09-14

  • 博文量
    25
  • 访问量
    49653