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

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

Introduction

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

Prototype

public static void setProtocolEngine(Configuration conf, Class<?> protocol, Class<?> engine) 

Source Link

Document

Set a protocol to use a non-default RpcEngine.

Usage

From source file:backup.datanode.DataNodeBackupServicePlugin.java

License:Apache License

@Override
public void start(Object service) {
    DataNode datanode = (DataNode) service;
    Configuration conf = getConf();
    RPC.setProtocolEngine(conf, DataNodeBackupRPC.class, WritableRpcEngine.class);
    // This object is created here so that it's lifecycle follows the datanode
    try {/*  w ww . j  a  v  a  2s. co m*/
        backupProcessor = SingletonManager.getManager(DataNodeBackupProcessor.class).getInstance(datanode,
                () -> new DataNodeBackupProcessor(conf, datanode));
        restoreProcessor = SingletonManager.getManager(DataNodeRestoreProcessor.class).getInstance(datanode,
                () -> new DataNodeRestoreProcessor(conf, datanode));

        DataNodeBackupRPCImpl backupRPCImpl = new DataNodeBackupRPCImpl(backupProcessor, restoreProcessor);

        InetSocketAddress listenerAddress = datanode.ipcServer.getListenerAddress();
        int ipcPort = listenerAddress.getPort();
        String bindAddress = listenerAddress.getAddress().getHostAddress();
        int port = conf.getInt(DFS_BACKUP_DATANODE_RPC_PORT_KEY, DFS_BACKUP_DATANODE_RPC_PORT_DEFAULT);
        if (port == 0) {
            port = ipcPort + 1;
        }
        server = new RPC.Builder(conf).setBindAddress(bindAddress).setPort(port).setInstance(backupRPCImpl)
                .setProtocol(DataNodeBackupRPC.class).build();
        ServiceAuthorizationManager serviceAuthorizationManager = server.getServiceAuthorizationManager();
        serviceAuthorizationManager.refresh(conf, new BackupPolicyProvider());
        server.start();

        LOG.info("DataNode Backup RPC listening on {}", port);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.github.hdl.tensorflow.yarn.app.api.impl.pb.client.TensorFlowClusterPBClientImpl.java

License:Apache License

public TensorFlowClusterPBClientImpl(long clientVersion, InetSocketAddress addr, Configuration conf)
        throws IOException {
    RPC.setProtocolEngine(conf, TensorFlowClusterPB.class, ProtobufRpcEngine.class);
    proxy = (TensorFlowClusterPB) RPC.getProxy(TensorFlowClusterPB.class, clientVersion, addr, conf);
}

From source file:com.intel.hadoopRPCBenchmark.HadoopRPCBenchmarkEngine.java

License:Apache License

private void startRPCServer() throws IOException {
    RPC.setProtocolEngine(conf, BenchmarkEngineProtocolPB.class, ProtobufRpcEngine.class);

    BenchmarkEngineProtocolServerSideTranslatorPB benchmarkEngineProtocolServerTranslator = new BenchmarkEngineProtocolServerSideTranslatorPB(
            new BenchmarkEngineProtocolImpl());
    BlockingService clientNNPbService = BenchmarkEngineProtocolProtos.BenchmarkEngineProtocolService
            .newReflectiveBlockingService(benchmarkEngineProtocolServerTranslator);

    server = new RPC.Builder(conf).setProtocol(BenchmarkEngineProtocolPB.class).setInstance(clientNNPbService)
            .setBindAddress(ADDRESS).setPort(0).setSecretManager(sm).setNumHandlers(10).build();
    server.start();/*from  w ww  . ja v a2s .  c  o  m*/
}

From source file:com.intel.hadoopRPCBenchmark.protocol.BenchmarkEngineProtocolClientSideTranslatorPB.java

License:Apache License

public BenchmarkEngineProtocolClientSideTranslatorPB(InetSocketAddress nameNodeAddr, Configuration conf)
        throws IOException {
    RPC.setProtocolEngine(conf, BenchmarkEngineProtocolPB.class, ProtobufRpcEngine.class);
    UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
    rpcProxy = RPC.getProxy(BenchmarkEngineProtocolPB.class,
            RPC.getProtocolVersion(BenchmarkEngineProtocolPB.class), nameNodeAddr, ugi, conf,
            NetUtils.getSocketFactory(conf, BenchmarkEngineProtocolPB.class));
}

From source file:io.hops.util.impl.pb.client.GroupMembershipPBClientImpl.java

License:Apache License

public GroupMembershipPBClientImpl(long clientVersion, InetSocketAddress addr, Configuration conf)
        throws IOException {
    RPC.setProtocolEngine(conf, GroupMembershipPB.class, ProtobufRpcEngine.class);
    proxy = (GroupMembershipPB) RPC.getProxy(GroupMembershipPB.class, clientVersion, addr, conf);
}

From source file:me.haohui.libhdfspp.TestRpcEngine.java

License:Apache License

@BeforeClass
public static void setUp() throws IOException {
    conf = new Configuration();
    conf.setInt(CommonConfigurationKeys.IPC_MAXIMUM_DATA_LENGTH, 1024);
    // Set RPC engine to protobuf RPC engine
    RPC.setProtocolEngine(conf, TestRpcService.class, ProtobufRpcEngine.class);

    // Create server side implementation
    PBServerImpl serverImpl = new PBServerImpl();
    BlockingService service = TestRpcServiceProtos.TestProtobufRpcProto
            .newReflectiveBlockingService(serverImpl);

    // Get RPC server for server side implementation
    server = new RPC.Builder(conf).setProtocol(TestRpcService.class).setInstance(service)
            .setBindAddress(ADDRESS).setPort(PORT).build();
    addr = NetUtils.getConnectAddress(server);
    server.start();/*from  w ww  . j a  va 2s  .co m*/
    executor.start();
}

From source file:org.apache.hoya.yarn.appmaster.rpc.RpcBinder.java

License:Apache License

/**
 * Add the protobuf engine to the configuration. Harmless and inexpensive
 * if repeated/*from  w ww.j  a v  a 2s.  com*/
 * @param conf configuration to patch
 * @return the protocol class
 */
public static Class<HoyaClusterProtocolPB> registerHoyaAPI(Configuration conf) {
    Class<HoyaClusterProtocolPB> hoyaClusterAPIClass = HoyaClusterProtocolPB.class;
    RPC.setProtocolEngine(conf, hoyaClusterAPIClass, ProtobufRpcEngine.class);

    //quick sanity check here
    assert verifyBondedToProtobuf(conf, hoyaClusterAPIClass);

    return hoyaClusterAPIClass;
}

From source file:org.apache.ratis.hadooprpc.Proxy.java

License:Apache License

public static <PROTOCOL> PROTOCOL getProxy(Class<PROTOCOL> clazz, String addressStr, Configuration conf)
        throws IOException {
    RPC.setProtocolEngine(conf, clazz, ProtobufRpcEngineShaded.class);
    return RPC.getProxy(clazz, RPC.getProtocolVersion(clazz),
            org.apache.ratis.util.NetUtils.createSocketAddr(addressStr), UserGroupInformation.getCurrentUser(),
            conf, NetUtils.getSocketFactory(conf, clazz));
}

From source file:org.apache.ratis.hadooprpc.server.HadoopRpcService.java

License:Apache License

private static RPC.Server newRpcServer(RaftServerProtocol serverProtocol, final Configuration conf)
        throws IOException {
    final int handlerCount = HadoopConfigKeys.Ipc.handlers(conf);
    final InetSocketAddress address = HadoopConfigKeys.Ipc.address(conf);

    final BlockingService service = RaftServerProtocolService
            .newReflectiveBlockingService(new RaftServerProtocolServerSideTranslatorPB(serverProtocol));
    RPC.setProtocolEngine(conf, RaftServerProtocolPB.class, ProtobufRpcEngineShaded.class);
    return new RPC.Builder(conf).setProtocol(RaftServerProtocolPB.class).setInstance(service)
            .setBindAddress(address.getHostName()).setPort(address.getPort()).setNumHandlers(handlerCount)
            .setVerbose(false).build();/*www. ja v  a 2s.  c  o m*/
}

From source file:org.apache.ratis.hadooprpc.server.HadoopRpcService.java

License:Apache License

private void addRaftClientProtocol(RaftClientProtocol clientProtocol, Configuration conf) {
    final Class<?> protocol = RaftClientProtocolPB.class;
    RPC.setProtocolEngine(conf, protocol, ProtobufRpcEngineShaded.class);

    final BlockingService service = RaftClientProtocolService
            .newReflectiveBlockingService(new RaftClientProtocolServerSideTranslatorPB(clientProtocol));
    ipcServer.addProtocol(RPC.RpcKind.RPC_PROTOCOL_BUFFER, protocol, service);
}