Exemple #1
0
  /** Expert: Make multiple, parallel calls to a set of servers. */
  public static Object[] call(
      Method method,
      Object[][] params,
      InetSocketAddress[] addrs,
      UserGroupInformation ticket,
      Configuration conf)
      throws IOException {

    Invocation[] invocations = new Invocation[params.length];
    for (int i = 0; i < params.length; i++) invocations[i] = new Invocation(method, params[i]);
    Client client = CLIENTS.getClient(conf);
    try {
      Writable[] wrappedValues =
          client.call(invocations, addrs, method.getDeclaringClass(), ticket);

      if (method.getReturnType() == Void.TYPE) {
        return null;
      }

      Object[] values = (Object[]) Array.newInstance(method.getReturnType(), wrappedValues.length);
      for (int i = 0; i < values.length; i++)
        if (wrappedValues[i] != null) values[i] = ((ObjectWritable) wrappedValues[i]).get();

      return values;
    } finally {
      CLIENTS.stopClient(client);
    }
  }
Exemple #2
0
 /**
  * Stop a RPC client connection A RPC client is closed only when its reference count becomes
  * zero.
  */
 private void stopClient(Client client) {
   synchronized (this) {
     client.decCount();
     if (client.isZeroReference()) {
       clients.remove(client.getSocketFactory());
     }
   }
   if (client.isZeroReference()) {
     client.stop();
   }
 }
Exemple #3
0
 /**
  * Construct & cache an IPC client with the user-provided SocketFactory if no cached client
  * exists.
  *
  * @param conf Configuration
  * @return an IPC client
  */
 private synchronized Client getClient(Configuration conf, SocketFactory factory) {
   // Construct & cache client.  The configuration is only used for timeout,
   // and Clients have connection pools.  So we can either (a) lose some
   // connection pooling and leak sockets, or (b) use the same timeout for all
   // configurations.  Since the IPC is usually intended globally, not
   // per-job, we choose (a).
   Client client = clients.get(factory);
   if (client == null) {
     client = new Client(ObjectWritable.class, conf, factory);
     clients.put(factory, client);
   } else {
     client.incCount();
   }
   return client;
 }
Exemple #4
0
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
      final boolean logDebug = LOG.isDebugEnabled();
      long startTime = 0;
      if (logDebug) {
        startTime = System.currentTimeMillis();
      }

      ObjectWritable value = null;
      try {
        value =
            (ObjectWritable)
                client.call(
                    new Invocation(method, args), getAddress(), protocol, ticket, rpcTimeout);
      } catch (RemoteException re) {
        throw re;
      } catch (ConnectException ce) {
        needCheckDnsUpdate = true;
        throw ce;
      } catch (NoRouteToHostException nrhe) {
        needCheckDnsUpdate = true;
        throw nrhe;
      } catch (PortUnreachableException pue) {
        needCheckDnsUpdate = true;
        throw pue;
      } catch (UnknownHostException uhe) {
        needCheckDnsUpdate = true;
        throw uhe;
      }
      if (logDebug) {
        long callTime = System.currentTimeMillis() - startTime;
        LOG.debug("Call: " + method.getName() + " " + callTime);
      }
      return value.get();
    }
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
      long startTime = 0;
      if (LOG.isDebugEnabled()) {
        startTime = Time.now();
      }

      ObjectWritable value =
          (ObjectWritable)
              client.call(RPC.RpcKind.RPC_WRITABLE, new Invocation(method, args), remoteId);
      if (LOG.isDebugEnabled()) {
        long callTime = Time.now() - startTime;
        LOG.debug("Call: " + method.getName() + " " + callTime);
      }
      return value.get();
    }