Java源码示例:org.apache.hadoop.ipc.Client.ConnectionId

示例1
@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());
}
 
示例2
@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());
}
 
示例3
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;
}
 
示例4
@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);
}
 
示例5
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;
}
 
示例6
/**
 * 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);
}
 
示例7
/**
 * 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();
}
 
示例8
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;
}
 
示例9
@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);
}
 
示例10
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;
}
 
示例11
/**
 * 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);
}
 
示例12
/**
 * 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();
}
 
示例13
@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);
}
 
示例14
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;
}
 
示例15
/**
 * 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);
}
 
示例16
@Override
public ConnectionId getConnectionId() {
  return remoteId;
}
 
示例17
@Override
public ProtocolProxy<ProtocolMetaInfoPB> getProtocolMetaInfoProxy(
    ConnectionId connId, Configuration conf, SocketFactory factory)
    throws IOException {
  throw new UnsupportedOperationException("This proxy is not supported");
}
 
示例18
@Override //RpcInvocationHandler
public ConnectionId getConnectionId() {
  return remoteId;
}
 
示例19
@Override //RpcInvocationHandler
public ConnectionId getConnectionId() {
  return RPC.getConnectionIdForProxy(currentProxy.proxy);
}
 
示例20
@Override
public ConnectionId getConnectionId() {
  return null;
}
 
示例21
@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);
  }
}
 
示例22
@Override
public ProtocolProxy<ProtocolMetaInfoPB> getProtocolMetaInfoProxy(
    ConnectionId connId, Configuration conf, SocketFactory factory)
    throws IOException {
  throw new UnsupportedOperationException("This proxy is not supported");
}
 
示例23
@Override
public ConnectionId getConnectionId() {
  return remoteId;
}
 
示例24
@Override
public ProtocolProxy<ProtocolMetaInfoPB> getProtocolMetaInfoProxy(
    ConnectionId connId, Configuration conf, SocketFactory factory)
    throws IOException {
  throw new UnsupportedOperationException("This proxy is not supported");
}
 
示例25
@Override //RpcInvocationHandler
public ConnectionId getConnectionId() {
  return remoteId;
}
 
示例26
@Override //RpcInvocationHandler
public ConnectionId getConnectionId() {
  return RPC.getConnectionIdForProxy(currentProxy.proxy);
}
 
示例27
@Override
public ConnectionId getConnectionId() {
  return null;
}
 
示例28
@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);
  }
}
 
示例29
@Override
public ProtocolProxy<ProtocolMetaInfoPB> getProtocolMetaInfoProxy(
    ConnectionId connId, Configuration conf, SocketFactory factory)
    throws IOException {
  throw new UnsupportedOperationException("This proxy is not supported");
}
 
示例30
@Override //RpcInvocationHandler
public ConnectionId getConnectionId() {
  return remoteId;
}