Example #1
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;
 }