Example usage for org.apache.hadoop.ipc RPC getProxy

List of usage examples for org.apache.hadoop.ipc RPC getProxy

Introduction

In this page you can find the example usage for org.apache.hadoop.ipc RPC getProxy.

Prototype

public static <T> T getProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, Configuration conf,
        SocketFactory factory) throws IOException 

Source Link

Document

Construct a client-side proxy object that implements the named protocol, talking to a server at the named address.

Usage

From source file:com.chinamobile.bcbsp.client.BSPJobClient.java

License:Apache License

/**
 * Ensure fresh jobSubmitClient./*from   www. ja v a  2 s  .  co  m*/
 */
public void ensureFreshjJobSubmitClient() {
    try {
        if (bspzk != null) {
            Stat s = null;
            int count = 0;
            int max = 3;
            while (s == null && count < max) {
                count++;
                Thread.sleep(500);
                s = bspzk.exists(Constants.BSPCONTROLLER_LEADER, true);
            }
            if (s != null) {
                String controllerAddr = getData(Constants.BSPCONTROLLER_LEADER);
                InetSocketAddress newAddr = NetUtils.createSocketAddr(controllerAddr);
                if (this.bspControllerAddr == null || !this.bspControllerAddr.equals(newAddr)) {
                    this.bspControllerAddr = newAddr;
                    // establish connection to new BspController again
                    conf.set("ipc.client.connect.max.retries", "0");
                    this.jobSubmitClient = (JobSubmissionProtocol) RPC.getProxy(JobSubmissionProtocol.class,
                            BSPRPCProtocolVersion.versionID, bspControllerAddr, conf,
                            NetUtils.getSocketFactory(conf, JobSubmissionProtocol.class));
                    LOG.info("Now  connected to " + this.bspControllerAddr.toString());
                }
            }
        }
    } catch (Exception e) {
        // LOG.warn("lost connection to  " + this.bspControllerAddr.toString());
        // LOG.error("[ensureFreshjJobSubmitClient]", e);
        throw new RuntimeException("lost connection to bspControllerAddr ", e);
    }
}

From source file:org.cstor.cproc.cloudComputingFramework.CProcFramework.java

License:Apache License

public static void main(String argv[]) throws Exception {

    LOG.info("CProcFramework  version for hadoop-0.20.2-patch : 32");

    //GCThreadGC//from w w w .  j a  v a  2 s  . c om
    Thread th = new Thread(new GCThread());
    th.start();

    //LOG.info("CProcFramework [NameNode IP:Port]");
    StringUtils.startupShutdownMessage(CProcFramework.class, argv, LOG);
    //hdfs-site.xml,core-site.xml
    CProcConfiguration cprocConf = CProcConfiguration.getCProcConfiguration();
    RpcConfiguration rpcConf = RpcConfiguration.getRpcConfiguration();
    setParamToRpcConf(cprocConf, rpcConf);

    CProcFramework cpf = null;
    ClientProtocol nameNode = null;
    ClientDatanodeProtocol dataNode = null;
    InetSocketAddress dataNodeAddr = null;
    InetSocketAddress nameNodeAddr = null;
    try {

        boolean isNN = true;

        //LOG.info("conf.get(\"fs.default.name\") == " + conf.get("cProc.name.") );
        //wzt ??? ?? net0 192.168.139.21 9000
        if (argv.length >= 3) {
            network = argv[0];
            namenodeAddress = argv[1];
            port = argv[2];
        } else {

            LOG.info("CProcFramework [network adapter] [namenode Address]");
            System.exit(0);

        }
        LOG.info("network = " + network);

        try {
            nameNodeAddr = NetUtils.createSocketAddr(namenodeAddress);
        } catch (IllegalArgumentException e) {
            //nameNodeAddr = NetUtils.createSocketAddr(argv[0]);
        }

        LOG.info("NameNodeAddr = " + nameNodeAddr);

        //-----------------------get all DN and get conf of NN----------------------------------

        ArrayList<String> DNIP = new ArrayList<String>();

        // Configuration confInFunc = new Configuration();

        nameNode = (ClientProtocol) RPC.getProxy(ClientProtocol.class, ClientProtocol.versionID, nameNodeAddr,
                rpcConf, NetUtils.getSocketFactory(rpcConf, ClientProtocol.class));

        DatanodeDescriptor[] dds = nameNode.getAllDatanode();

        // LOG.info("==========");
        for (DatanodeDescriptor dd : dds) {
            LOG.info(dd.getHost());
            //LOG.info(dd.getHostName());
            //LOG.info(dd.getDatanodeReport());
            DNIP.add(dd.getHost());
        }
        //LOG.info("==========");
        //conf = nameNode.getConfiguration();
        setParamToCprocConf(nameNode.getConfiguration(), rpcConf);

        LOG.info("getHostIP.getLocalIP() = " + getHostIPcProc.getLocalIP(network));

        //-----------------------if this node is a DN get conf----------------------------------

        if (DNIP.contains(getHostIPcProc.getLocalIP(network))) {
            dataNodeAddr = NetUtils
                    .createSocketAddr("127.0.0.1:" + rpcConf.get("dfs.datanode.ipc.address").split(":")[1]);

            dataNode = (ClientDatanodeProtocol) RPC.getProxy(ClientDatanodeProtocol.class,
                    ClientDatanodeProtocol.versionID, dataNodeAddr, rpcConf,
                    NetUtils.getSocketFactory(rpcConf, ClientDatanodeProtocol.class));

            //conf = dataNode.getConfiguration();
            LOG.info("This is DataNode!!");
            isNN = false;
        } else {
            LOG.info("This is NameNode!!");
            isNN = true;
        }

        cpf = createCProcFramework(nameNode, dataNode, cprocConf, rpcConf, isNN, nameNodeAddr);

        cpf.waitForStop();

    } catch (Throwable e) {
        LOG.error(StringUtils.stringifyException(e));
        System.exit(-1);
    } finally {
        //20131210RPC
        //          if(nameNode != null){
        //             RPC.stopProxy(nameNode);
        //          }
        //          if(dataNode != null){
        //             RPC.stopProxy(dataNode);
        //          }
    }
}