org.apache.hadoop.ipc.Client.ConnectionId Java Examples

The following examples show how to use org.apache.hadoop.ipc.Client.ConnectionId. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestSaslRPC.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testPingInterval() throws Exception {
  Configuration newConf = new Configuration(conf);
  newConf.set(SERVER_PRINCIPAL_KEY, SERVER_PRINCIPAL_1);
  conf.setInt(CommonConfigurationKeys.IPC_PING_INTERVAL_KEY,
      CommonConfigurationKeys.IPC_PING_INTERVAL_DEFAULT);

  // set doPing to true
  newConf.setBoolean(CommonConfigurationKeys.IPC_CLIENT_PING_KEY, true);
  ConnectionId remoteId = ConnectionId.getConnectionId(
      new InetSocketAddress(0), TestSaslProtocol.class, null, 0, newConf);
  assertEquals(CommonConfigurationKeys.IPC_PING_INTERVAL_DEFAULT,
      remoteId.getPingInterval());
  // set doPing to false
  newConf.setBoolean(CommonConfigurationKeys.IPC_CLIENT_PING_KEY, false);
  remoteId = ConnectionId.getConnectionId(
      new InetSocketAddress(0), TestSaslProtocol.class, null, 0, newConf);
  assertEquals(0, remoteId.getPingInterval());
}
 
Example #2
Source File: TestSaslRPC.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testPingInterval() throws Exception {
  Configuration newConf = new Configuration(conf);
  newConf.set(SERVER_PRINCIPAL_KEY, SERVER_PRINCIPAL_1);
  conf.setInt(CommonConfigurationKeys.IPC_PING_INTERVAL_KEY,
      CommonConfigurationKeys.IPC_PING_INTERVAL_DEFAULT);

  // set doPing to true
  newConf.setBoolean(CommonConfigurationKeys.IPC_CLIENT_PING_KEY, true);
  ConnectionId remoteId = ConnectionId.getConnectionId(
      new InetSocketAddress(0), TestSaslProtocol.class, null, 0, newConf);
  assertEquals(CommonConfigurationKeys.IPC_PING_INTERVAL_DEFAULT,
      remoteId.getPingInterval());
  // set doPing to false
  newConf.setBoolean(CommonConfigurationKeys.IPC_CLIENT_PING_KEY, false);
  remoteId = ConnectionId.getConnectionId(
      new InetSocketAddress(0), TestSaslProtocol.class, null, 0, newConf);
  assertEquals(0, remoteId.getPingInterval());
}
 
Example #3
Source File: ProtobufRpcEngine.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * This constructor takes a connectionId, instead of creating a new one.
 */
private Invoker(Class<?> protocol, Client.ConnectionId connId,
    Configuration conf, SocketFactory factory) {
  this.remoteId = connId;
  this.client = CLIENTS.getClient(conf, factory, RpcResponseWrapper.class);
  this.protocolName = RPC.getProtocolName(protocol);
  this.clientProtocolVersion = RPC
      .getProtocolVersion(protocol);
}
 
Example #4
Source File: ProtobufRpcEngineShaded.java    From ratis with Apache License 2.0 5 votes vote down vote up
/**
 * This constructor takes a connectionId, instead of creating a new one.
 */
private Invoker(Class<?> protocol, Client.ConnectionId connId,
    Configuration conf, SocketFactory factory) {
  this.remoteId = connId;
  this.client = CLIENTS.getClient(conf, factory, RpcResponseWrapper.class);
  this.protocolName = RPC.getProtocolName(protocol);
  this.clientProtocolVersion = RPC
      .getProtocolVersion(protocol);
}
 
Example #5
Source File: ProtobufRpcEngine.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public ProtocolProxy<ProtocolMetaInfoPB> getProtocolMetaInfoProxy(
    ConnectionId connId, Configuration conf, SocketFactory factory)
    throws IOException {
  Class<ProtocolMetaInfoPB> protocol = ProtocolMetaInfoPB.class;
  return new ProtocolProxy<ProtocolMetaInfoPB>(protocol,
      (ProtocolMetaInfoPB) Proxy.newProxyInstance(protocol.getClassLoader(),
          new Class[] { protocol }, new Invoker(protocol, connId, conf,
              factory)), false);
}
 
Example #6
Source File: ProtobufRpcEngine.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private Invoker(Class<?> protocol, InetSocketAddress addr,
    UserGroupInformation ticket, Configuration conf, SocketFactory factory,
    int rpcTimeout, RetryPolicy connectionRetryPolicy,
    AtomicBoolean fallbackToSimpleAuth) throws IOException {
  this(protocol, Client.ConnectionId.getConnectionId(
      addr, protocol, ticket, rpcTimeout, connectionRetryPolicy, conf),
      conf, factory);
  this.fallbackToSimpleAuth = fallbackToSimpleAuth;
}
 
Example #7
Source File: ProtobufRpcEngine.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * This constructor takes a connectionId, instead of creating a new one.
 */
private Invoker(Class<?> protocol, Client.ConnectionId connId,
    Configuration conf, SocketFactory factory) {
  this.remoteId = connId;
  this.client = CLIENTS.getClient(conf, factory, RpcResponseWrapper.class);
  this.protocolName = RPC.getProtocolName(protocol);
  this.clientProtocolVersion = RPC
      .getProtocolVersion(protocol);
}
 
Example #8
Source File: ProtobufRpcEngineShaded.java    From ratis with Apache License 2.0 5 votes vote down vote up
private Invoker(Class<?> protocol, InetSocketAddress addr,
    UserGroupInformation ticket, Configuration conf, SocketFactory factory,
    int rpcTimeout, RetryPolicy connectionRetryPolicy,
    AtomicBoolean fallbackToSimpleAuth) throws IOException {
  this(protocol, Client.ConnectionId.getConnectionId(
      addr, protocol, ticket, rpcTimeout, connectionRetryPolicy, conf),
      conf, factory);
  this.fallbackToSimpleAuth = fallbackToSimpleAuth;
}
 
Example #9
Source File: ProtobufRpcEngineShaded.java    From ratis with Apache License 2.0 5 votes vote down vote up
@Override
public ProtocolProxy<ProtocolMetaInfoPB> getProtocolMetaInfoProxy(
    ConnectionId connId, Configuration conf, SocketFactory factory)
    throws IOException {
  Class<ProtocolMetaInfoPB> protocol = ProtocolMetaInfoPB.class;
  return new ProtocolProxy<ProtocolMetaInfoPB>(protocol,
      (ProtocolMetaInfoPB) Proxy.newProxyInstance(protocol.getClassLoader(),
          new Class[] { protocol }, new Invoker(protocol, connId, conf,
              factory)), false);
}
 
Example #10
Source File: ProtobufRpcEngine.java    From big-c with Apache License 2.0 5 votes vote down vote up
private Invoker(Class<?> protocol, InetSocketAddress addr,
    UserGroupInformation ticket, Configuration conf, SocketFactory factory,
    int rpcTimeout, RetryPolicy connectionRetryPolicy,
    AtomicBoolean fallbackToSimpleAuth) throws IOException {
  this(protocol, Client.ConnectionId.getConnectionId(
      addr, protocol, ticket, rpcTimeout, connectionRetryPolicy, conf),
      conf, factory);
  this.fallbackToSimpleAuth = fallbackToSimpleAuth;
}
 
Example #11
Source File: RPC.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Return the connection ID of the given object. If the provided object is in
 * fact a protocol translator, we'll get the connection ID of the underlying
 * proxy object.
 * 
 * @param proxy the proxy object to get the connection ID of.
 * @return the connection ID for the provided proxy object.
 */
public static ConnectionId getConnectionIdForProxy(Object proxy) {
  if (proxy instanceof ProtocolTranslator) {
    proxy = ((ProtocolTranslator)proxy).getUnderlyingProxyObject();
  }
  RpcInvocationHandler inv = (RpcInvocationHandler) Proxy
      .getInvocationHandler(proxy);
  return inv.getConnectionId();
}
 
Example #12
Source File: ProtobufRpcEngine.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public ProtocolProxy<ProtocolMetaInfoPB> getProtocolMetaInfoProxy(
    ConnectionId connId, Configuration conf, SocketFactory factory)
    throws IOException {
  Class<ProtocolMetaInfoPB> protocol = ProtocolMetaInfoPB.class;
  return new ProtocolProxy<ProtocolMetaInfoPB>(protocol,
      (ProtocolMetaInfoPB) Proxy.newProxyInstance(protocol.getClassLoader(),
          new Class[] { protocol }, new Invoker(protocol, connId, conf,
              factory)), false);
}
 
Example #13
Source File: WritableRpcEngine.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public Invoker(Class<?> protocol,
               InetSocketAddress address, UserGroupInformation ticket,
               Configuration conf, SocketFactory factory,
               int rpcTimeout, AtomicBoolean fallbackToSimpleAuth)
    throws IOException {
  this.remoteId = Client.ConnectionId.getConnectionId(address, protocol,
      ticket, rpcTimeout, conf);
  this.client = CLIENTS.getClient(conf, factory);
  this.fallbackToSimpleAuth = fallbackToSimpleAuth;
}
 
Example #14
Source File: RPC.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Return the connection ID of the given object. If the provided object is in
 * fact a protocol translator, we'll get the connection ID of the underlying
 * proxy object.
 * 
 * @param proxy the proxy object to get the connection ID of.
 * @return the connection ID for the provided proxy object.
 */
public static ConnectionId getConnectionIdForProxy(Object proxy) {
  if (proxy instanceof ProtocolTranslator) {
    proxy = ((ProtocolTranslator)proxy).getUnderlyingProxyObject();
  }
  RpcInvocationHandler inv = (RpcInvocationHandler) Proxy
      .getInvocationHandler(proxy);
  return inv.getConnectionId();
}
 
Example #15
Source File: WritableRpcEngine.java    From big-c with Apache License 2.0 5 votes vote down vote up
public Invoker(Class<?> protocol,
               InetSocketAddress address, UserGroupInformation ticket,
               Configuration conf, SocketFactory factory,
               int rpcTimeout, AtomicBoolean fallbackToSimpleAuth)
    throws IOException {
  this.remoteId = Client.ConnectionId.getConnectionId(address, protocol,
      ticket, rpcTimeout, conf);
  this.client = CLIENTS.getClient(conf, factory);
  this.fallbackToSimpleAuth = fallbackToSimpleAuth;
}
 
Example #16
Source File: TestSaslRPC.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Test
public void testPerConnectionConf() throws Exception {
  TestTokenSecretManager sm = new TestTokenSecretManager();
  final Server server = new RPC.Builder(conf)
      .setProtocol(TestSaslProtocol.class).setInstance(new TestSaslImpl())
      .setBindAddress(ADDRESS).setPort(0).setNumHandlers(5).setVerbose(true)
      .setSecretManager(sm).build();
  server.start();
  final UserGroupInformation current = UserGroupInformation.getCurrentUser();
  final InetSocketAddress addr = NetUtils.getConnectAddress(server);
  TestTokenIdentifier tokenId = new TestTokenIdentifier(new Text(current
      .getUserName()));
  Token<TestTokenIdentifier> token = new Token<TestTokenIdentifier>(tokenId,
      sm);
  SecurityUtil.setTokenService(token, addr);
  current.addToken(token);

  Configuration newConf = new Configuration(conf);
  newConf.set(CommonConfigurationKeysPublic.
      HADOOP_RPC_SOCKET_FACTORY_CLASS_DEFAULT_KEY, "");

  Client client = null;
  TestSaslProtocol proxy1 = null;
  TestSaslProtocol proxy2 = null;
  TestSaslProtocol proxy3 = null;
  int timeouts[] = {111222, 3333333};
  try {
    newConf.setInt(CommonConfigurationKeysPublic.IPC_CLIENT_CONNECTION_MAXIDLETIME_KEY, timeouts[0]);
    proxy1 = RPC.getProxy(TestSaslProtocol.class,
        TestSaslProtocol.versionID, addr, newConf);
    proxy1.getAuthMethod();
    client = WritableRpcEngine.getClient(newConf);
    Set<ConnectionId> conns = client.getConnectionIds();
    assertEquals("number of connections in cache is wrong", 1, conns.size());
    // same conf, connection should be re-used
    proxy2 = RPC.getProxy(TestSaslProtocol.class,
        TestSaslProtocol.versionID, addr, newConf);
    proxy2.getAuthMethod();
    assertEquals("number of connections in cache is wrong", 1, conns.size());
    // different conf, new connection should be set up
    newConf.setInt(CommonConfigurationKeysPublic.IPC_CLIENT_CONNECTION_MAXIDLETIME_KEY, timeouts[1]);
    proxy3 = RPC.getProxy(TestSaslProtocol.class,
        TestSaslProtocol.versionID, addr, newConf);
    proxy3.getAuthMethod();
    assertEquals("number of connections in cache is wrong", 2, conns.size());
    // now verify the proxies have the correct connection ids and timeouts
    ConnectionId[] connsArray = {
        RPC.getConnectionIdForProxy(proxy1),
        RPC.getConnectionIdForProxy(proxy2),
        RPC.getConnectionIdForProxy(proxy3)
    };
    assertEquals(connsArray[0], connsArray[1]);
    assertEquals(connsArray[0].getMaxIdleTime(), timeouts[0]);
    assertFalse(connsArray[0].equals(connsArray[2]));
    assertNotSame(connsArray[2].getMaxIdleTime(), timeouts[1]);
  } finally {
    server.stop();
    // this is dirty, but clear out connection cache for next run
    if (client != null) {
      client.getConnectionIds().clear();
    }
    if (proxy1 != null) RPC.stopProxy(proxy1);
    if (proxy2 != null) RPC.stopProxy(proxy2);
    if (proxy3 != null) RPC.stopProxy(proxy3);
  }
}
 
Example #17
Source File: RetryInvocationHandler.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override //RpcInvocationHandler
public ConnectionId getConnectionId() {
  return RPC.getConnectionIdForProxy(currentProxy.proxy);
}
 
Example #18
Source File: TestIPC.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override
public ConnectionId getConnectionId() {
  return null;
}
 
Example #19
Source File: WritableRpcEngine.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override
public ProtocolProxy<ProtocolMetaInfoPB> getProtocolMetaInfoProxy(
    ConnectionId connId, Configuration conf, SocketFactory factory)
    throws IOException {
  throw new UnsupportedOperationException("This proxy is not supported");
}
 
Example #20
Source File: TestRPC.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override
public ProtocolProxy<ProtocolMetaInfoPB> getProtocolMetaInfoProxy(
    ConnectionId connId, Configuration conf, SocketFactory factory)
    throws IOException {
  throw new UnsupportedOperationException("This proxy is not supported");
}
 
Example #21
Source File: ProtobufRpcEngineShaded.java    From ratis with Apache License 2.0 4 votes vote down vote up
@Override //RpcInvocationHandler
public ConnectionId getConnectionId() {
  return remoteId;
}
 
Example #22
Source File: ProtobufRpcEngine.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override //RpcInvocationHandler
public ConnectionId getConnectionId() {
  return remoteId;
}
 
Example #23
Source File: WritableRpcEngine.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override
public ConnectionId getConnectionId() {
  return remoteId;
}
 
Example #24
Source File: TestRPC.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
public ProtocolProxy<ProtocolMetaInfoPB> getProtocolMetaInfoProxy(
    ConnectionId connId, Configuration conf, SocketFactory factory)
    throws IOException {
  throw new UnsupportedOperationException("This proxy is not supported");
}
 
Example #25
Source File: TestSaslRPC.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Test
public void testPerConnectionConf() throws Exception {
  TestTokenSecretManager sm = new TestTokenSecretManager();
  final Server server = new RPC.Builder(conf)
      .setProtocol(TestSaslProtocol.class).setInstance(new TestSaslImpl())
      .setBindAddress(ADDRESS).setPort(0).setNumHandlers(5).setVerbose(true)
      .setSecretManager(sm).build();
  server.start();
  final UserGroupInformation current = UserGroupInformation.getCurrentUser();
  final InetSocketAddress addr = NetUtils.getConnectAddress(server);
  TestTokenIdentifier tokenId = new TestTokenIdentifier(new Text(current
      .getUserName()));
  Token<TestTokenIdentifier> token = new Token<TestTokenIdentifier>(tokenId,
      sm);
  SecurityUtil.setTokenService(token, addr);
  current.addToken(token);

  Configuration newConf = new Configuration(conf);
  newConf.set(CommonConfigurationKeysPublic.
      HADOOP_RPC_SOCKET_FACTORY_CLASS_DEFAULT_KEY, "");

  Client client = null;
  TestSaslProtocol proxy1 = null;
  TestSaslProtocol proxy2 = null;
  TestSaslProtocol proxy3 = null;
  int timeouts[] = {111222, 3333333};
  try {
    newConf.setInt(CommonConfigurationKeysPublic.IPC_CLIENT_CONNECTION_MAXIDLETIME_KEY, timeouts[0]);
    proxy1 = RPC.getProxy(TestSaslProtocol.class,
        TestSaslProtocol.versionID, addr, newConf);
    proxy1.getAuthMethod();
    client = WritableRpcEngine.getClient(newConf);
    Set<ConnectionId> conns = client.getConnectionIds();
    assertEquals("number of connections in cache is wrong", 1, conns.size());
    // same conf, connection should be re-used
    proxy2 = RPC.getProxy(TestSaslProtocol.class,
        TestSaslProtocol.versionID, addr, newConf);
    proxy2.getAuthMethod();
    assertEquals("number of connections in cache is wrong", 1, conns.size());
    // different conf, new connection should be set up
    newConf.setInt(CommonConfigurationKeysPublic.IPC_CLIENT_CONNECTION_MAXIDLETIME_KEY, timeouts[1]);
    proxy3 = RPC.getProxy(TestSaslProtocol.class,
        TestSaslProtocol.versionID, addr, newConf);
    proxy3.getAuthMethod();
    assertEquals("number of connections in cache is wrong", 2, conns.size());
    // now verify the proxies have the correct connection ids and timeouts
    ConnectionId[] connsArray = {
        RPC.getConnectionIdForProxy(proxy1),
        RPC.getConnectionIdForProxy(proxy2),
        RPC.getConnectionIdForProxy(proxy3)
    };
    assertEquals(connsArray[0], connsArray[1]);
    assertEquals(connsArray[0].getMaxIdleTime(), timeouts[0]);
    assertFalse(connsArray[0].equals(connsArray[2]));
    assertNotSame(connsArray[2].getMaxIdleTime(), timeouts[1]);
  } finally {
    server.stop();
    // this is dirty, but clear out connection cache for next run
    if (client != null) {
      client.getConnectionIds().clear();
    }
    if (proxy1 != null) RPC.stopProxy(proxy1);
    if (proxy2 != null) RPC.stopProxy(proxy2);
    if (proxy3 != null) RPC.stopProxy(proxy3);
  }
}
 
Example #26
Source File: TestIPC.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
public ConnectionId getConnectionId() {
  return null;
}
 
Example #27
Source File: RetryInvocationHandler.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override //RpcInvocationHandler
public ConnectionId getConnectionId() {
  return RPC.getConnectionIdForProxy(currentProxy.proxy);
}
 
Example #28
Source File: ProtobufRpcEngine.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override //RpcInvocationHandler
public ConnectionId getConnectionId() {
  return remoteId;
}
 
Example #29
Source File: WritableRpcEngine.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
public ProtocolProxy<ProtocolMetaInfoPB> getProtocolMetaInfoProxy(
    ConnectionId connId, Configuration conf, SocketFactory factory)
    throws IOException {
  throw new UnsupportedOperationException("This proxy is not supported");
}
 
Example #30
Source File: WritableRpcEngine.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
public ConnectionId getConnectionId() {
  return remoteId;
}