當前位置: 首頁>>代碼示例>>Java>>正文


Java RPC類代碼示例

本文整理匯總了Java中org.apache.hadoop.ipc.RPC的典型用法代碼示例。如果您正苦於以下問題:Java RPC類的具體用法?Java RPC怎麽用?Java RPC使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RPC類屬於org.apache.hadoop.ipc包,在下文中一共展示了RPC類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: ZKFCProtocolClientSideTranslatorPB

import org.apache.hadoop.ipc.RPC; //導入依賴的package包/類
public ZKFCProtocolClientSideTranslatorPB(
    InetSocketAddress addr, Configuration conf,
    SocketFactory socketFactory, int timeout) throws IOException {
  RPC.setProtocolEngine(conf, ZKFCProtocolPB.class,
      ProtobufRpcEngine.class);
  rpcProxy = RPC.getProxy(ZKFCProtocolPB.class,
      RPC.getProtocolVersion(ZKFCProtocolPB.class), addr,
      UserGroupInformation.getCurrentUser(), conf, socketFactory, timeout);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:10,代碼來源:ZKFCProtocolClientSideTranslatorPB.java

示例2: HAServiceProtocolClientSideTranslatorPB

import org.apache.hadoop.ipc.RPC; //導入依賴的package包/類
public HAServiceProtocolClientSideTranslatorPB(
    InetSocketAddress addr, Configuration conf,
    SocketFactory socketFactory, int timeout) throws IOException {
  RPC.setProtocolEngine(conf, HAServiceProtocolPB.class,
      ProtobufRpcEngine.class);
  rpcProxy = RPC.getProxy(HAServiceProtocolPB.class,
      RPC.getProtocolVersion(HAServiceProtocolPB.class), addr,
      UserGroupInformation.getCurrentUser(), conf, socketFactory, timeout);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:10,代碼來源:HAServiceProtocolClientSideTranslatorPB.java

示例3: createClientDatanodeProtocolProxy

import org.apache.hadoop.ipc.RPC; //導入依賴的package包/類
static ClientDatanodeProtocolPB createClientDatanodeProtocolProxy(
    InetSocketAddress addr, UserGroupInformation ticket, Configuration conf,
    SocketFactory factory, int socketTimeout) throws IOException {
  RPC.setProtocolEngine(conf, ClientDatanodeProtocolPB.class,
      ProtobufRpcEngine.class);
  return RPC.getProxy(ClientDatanodeProtocolPB.class,
      RPC.getProtocolVersion(ClientDatanodeProtocolPB.class), addr, ticket,
      conf, factory, socketTimeout);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:10,代碼來源:ClientDatanodeProtocolTranslatorPB.java

示例4: testInterDNProtocolTimeout

import org.apache.hadoop.ipc.RPC; //導入依賴的package包/類
/** Test to verify that InterDatanode RPC timesout as expected when
 *  the server DN does not respond.
 */
@Test(expected=SocketTimeoutException.class)
public void testInterDNProtocolTimeout() throws Throwable {
  final Server server = new TestServer(1, true);
  server.start();

  final InetSocketAddress addr = NetUtils.getConnectAddress(server);
  DatanodeID fakeDnId = DFSTestUtil.getLocalDatanodeID(addr.getPort());
  DatanodeInfo dInfo = new DatanodeInfo(fakeDnId);
  InterDatanodeProtocol proxy = null;

  try {
    proxy = DataNode.createInterDataNodeProtocolProxy(
        dInfo, conf, 500, false);
    proxy.initReplicaRecovery(new RecoveringBlock(
        new ExtendedBlock("bpid", 1), null, 100));
    fail ("Expected SocketTimeoutException exception, but did not get.");
  } finally {
    if (proxy != null) {
      RPC.stopProxy(proxy);
    }
    server.stop();
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:27,代碼來源:TestInterDatanodeProtocol.java

示例5: testNamenodeProtocol

import org.apache.hadoop.ipc.RPC; //導入依賴的package包/類
@Test
public void testNamenodeProtocol() throws IOException {
  NamenodeProtocol np =
      NameNodeProxies.createNonHAProxy(conf,
          nnAddress, NamenodeProtocol.class, UserGroupInformation.getCurrentUser(),
          true).getProxy();

  boolean exists = RpcClientUtil.isMethodSupported(np,
      NamenodeProtocolPB.class, RPC.RpcKind.RPC_PROTOCOL_BUFFER,
      RPC.getProtocolVersion(NamenodeProtocolPB.class), "rollEditLog");

  assertTrue(exists);
  exists = RpcClientUtil.isMethodSupported(np,
      NamenodeProtocolPB.class, RPC.RpcKind.RPC_PROTOCOL_BUFFER,
      RPC.getProtocolVersion(NamenodeProtocolPB.class), "bogusMethod");
  assertFalse(exists);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:TestIsMethodSupported.java

示例6: tryGracefulFence

import org.apache.hadoop.ipc.RPC; //導入依賴的package包/類
/**
 * Try to get the HA state of the node at the given address. This
 * function is guaranteed to be "quick" -- ie it has a short timeout
 * and no retries. Its only purpose is to avoid fencing a node that
 * has already restarted.
 */
boolean tryGracefulFence(HAServiceTarget svc) {
  HAServiceProtocol proxy = null;
  try {
    proxy = svc.getProxy(gracefulFenceConf, gracefulFenceTimeout);
    proxy.transitionToStandby(createReqInfo());
    return true;
  } catch (ServiceFailedException sfe) {
    LOG.warn("Unable to gracefully make " + svc + " standby (" +
        sfe.getMessage() + ")");
  } catch (IOException ioe) {
    LOG.warn("Unable to gracefully make " + svc +
        " standby (unable to connect)", ioe);
  } finally {
    if (proxy != null) {
      RPC.stopProxy(proxy);
    }
  }
  return false;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:26,代碼來源:FailoverController.java

示例7: createMockDatanode

import org.apache.hadoop.ipc.RPC; //導入依賴的package包/類
private static Server createMockDatanode(BlockTokenSecretManager sm,
    Token<BlockTokenIdentifier> token, Configuration conf)
    throws IOException, ServiceException {
  ClientDatanodeProtocolPB mockDN = mock(ClientDatanodeProtocolPB.class);

  BlockTokenIdentifier id = sm.createIdentifier();
  id.readFields(new DataInputStream(new ByteArrayInputStream(token
      .getIdentifier())));
  
  doAnswer(new GetLengthAnswer(sm, id)).when(mockDN)
      .getReplicaVisibleLength(any(RpcController.class),
          any(GetReplicaVisibleLengthRequestProto.class));

  RPC.setProtocolEngine(conf, ClientDatanodeProtocolPB.class,
      ProtobufRpcEngine.class);
  BlockingService service = ClientDatanodeProtocolService
      .newReflectiveBlockingService(mockDN);
  return new RPC.Builder(conf).setProtocol(ClientDatanodeProtocolPB.class)
      .setInstance(service).setBindAddress(ADDRESS).setPort(0)
      .setNumHandlers(5).setVerbose(true).setSecretManager(sm).build();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:22,代碼來源:TestBlockToken.java

示例8: cleanUp

import org.apache.hadoop.ipc.RPC; //導入依賴的package包/類
@After
public void cleanUp() {
  if (store != null) {
    store.stop();
    store = null;
  }

  if (service != null) {
    service.stop();
    service = null;
  }

  if (clientSCMProxy != null) {
    RPC.stopProxy(clientSCMProxy);
    clientSCMProxy = null;
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:TestClientSCMProtocolService.java

示例9: serviceStart

import org.apache.hadoop.ipc.RPC; //導入依賴的package包/類
@Override
protected void serviceStart() throws Exception {
  Configuration conf = getConfig();

  Server server;
  try {
    secretMgr = new ClientToAMTokenSecretManager(
        this.appAttemptId, secretKey);
    server =
        new RPC.Builder(conf)
          .setProtocol(CustomProtocol.class)
          .setNumHandlers(1)
          .setSecretManager(secretMgr)
          .setInstance(this).build();
  } catch (Exception e) {
    throw new YarnRuntimeException(e);
  }
  server.start();
  this.address = NetUtils.getConnectAddress(server);
  super.serviceStart();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:22,代碼來源:TestClientToAMTokens.java

示例10: verifyNewVersionToken

import org.apache.hadoop.ipc.RPC; //導入依賴的package包/類
private void verifyNewVersionToken(final Configuration conf, final CustomAM am,
    Token<ClientToAMTokenIdentifier> token, MockRM rm) throws IOException,
    InterruptedException {
  UserGroupInformation ugi;
  ugi = UserGroupInformation.createRemoteUser("me");
  
  Token<ClientToAMTokenIdentifier> newToken = 
      new Token<ClientToAMTokenIdentifier>(
          new ClientToAMTokenIdentifierForTest(token.decodeIdentifier(), "message"),
          am.getClientToAMTokenSecretManager());
  newToken.setService(token.getService());
  
  ugi.addToken(newToken);

  ugi.doAs(new PrivilegedExceptionAction<Void>() {
    @Override
    public Void run() throws Exception {
      CustomProtocol client =
          (CustomProtocol) RPC.getProxy(CustomProtocol.class, 1L, am.address,
            conf);
      client.ping();
      Assert.assertTrue(am.pinged);
      return null;
    }
  });
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:27,代碼來源:TestClientToAMTokens.java

示例11: verifyValidToken

import org.apache.hadoop.ipc.RPC; //導入依賴的package包/類
private void verifyValidToken(final Configuration conf, final CustomAM am,
    Token<ClientToAMTokenIdentifier> token) throws IOException,
    InterruptedException {
  UserGroupInformation ugi;
  ugi = UserGroupInformation.createRemoteUser("me");
  ugi.addToken(token);

  ugi.doAs(new PrivilegedExceptionAction<Void>() {
    @Override
    public Void run() throws Exception {
      CustomProtocol client =
          (CustomProtocol) RPC.getProxy(CustomProtocol.class, 1L, am.address,
            conf);
      client.ping();
      Assert.assertTrue(am.pinged);
      return null;
    }
  });
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:20,代碼來源:TestClientToAMTokens.java

示例12: testRMAuditLoggerWithIP

import org.apache.hadoop.ipc.RPC; //導入依賴的package包/類
/**
 * Test {@link RMAuditLogger} with IP set.
 */
@Test  
public void testRMAuditLoggerWithIP() throws Exception {
  Configuration conf = new Configuration();
  // start the IPC server
  Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class)
      .setInstance(new MyTestRPCServer()).setBindAddress("0.0.0.0")
      .setPort(0).setNumHandlers(5).setVerbose(true).build();
  server.start();

  InetSocketAddress addr = NetUtils.getConnectAddress(server);

  // Make a client connection and test the audit log
  TestProtocol proxy = (TestProtocol)RPC.getProxy(TestProtocol.class,
                         TestProtocol.versionID, addr, conf);
  // Start the testcase
  proxy.ping();

  server.stop();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:23,代碼來源:TestRMAuditLogger.java

示例13: testAuditLoggerWithIP

import org.apache.hadoop.ipc.RPC; //導入依賴的package包/類
/**
 * Test {@link AuditLogger} with IP set.
 */
public void testAuditLoggerWithIP() throws Exception {
  Configuration conf = new Configuration();
  // start the IPC server
  Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class)
          .setInstance(new MyTestRPCServer()).setBindAddress("0.0.0.0")
          .setPort(0).build();
  server.start();

  InetSocketAddress addr = NetUtils.getConnectAddress(server);

  // Make a client connection and test the audit log
  TestProtocol proxy = (TestProtocol)RPC.getProxy(TestProtocol.class,
                         TestProtocol.versionID, addr, conf);
  // Start the testcase
  proxy.ping();

  server.stop();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:22,代碼來源:TestAuditLogger.java

示例14: startAndGetRPCServerAddress

import org.apache.hadoop.ipc.RPC; //導入依賴的package包/類
private InetSocketAddress startAndGetRPCServerAddress(InetSocketAddress serverAddress) {
  Configuration conf = new Configuration();

  try {
    RPC.setProtocolEngine(conf,
        HAServiceProtocolPB.class, ProtobufRpcEngine.class);
    HAServiceProtocolServerSideTranslatorPB haServiceProtocolXlator =
        new HAServiceProtocolServerSideTranslatorPB(new MockHAProtocolImpl());
    BlockingService haPbService = HAServiceProtocolService
        .newReflectiveBlockingService(haServiceProtocolXlator);

    Server server = new RPC.Builder(conf)
        .setProtocol(HAServiceProtocolPB.class)
        .setInstance(haPbService)
        .setBindAddress(serverAddress.getHostName())
        .setPort(serverAddress.getPort()).build();
    server.start();
    return NetUtils.getConnectAddress(server);
  } catch (IOException e) {
    return null;
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:23,代碼來源:DummyHAService.java

示例15: isMethodSupported

import org.apache.hadoop.ipc.RPC; //導入依賴的package包/類
@Override
public boolean isMethodSupported(String methodName) throws IOException {
  return RpcClientUtil
      .isMethodSupported(rpcProxy, RefreshUserMappingsProtocolPB.class,
          RPC.RpcKind.RPC_PROTOCOL_BUFFER,
          RPC.getProtocolVersion(RefreshUserMappingsProtocolPB.class),
          methodName);
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:9,代碼來源:RefreshUserMappingsProtocolClientSideTranslatorPB.java


注:本文中的org.apache.hadoop.ipc.RPC類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。