/*
 * Licensed to the University of California, Berkeley under one or more contributor license
 * agreements. See the NOTICE file distributed with this work for additional information regarding
 * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance with the License. You may obtain a
 * copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package tachyon.client.next.block;

import tachyon.conf.TachyonConf;
import tachyon.master.MasterClient;
import tachyon.util.ThreadFactoryUtils;

import java.net.InetSocketAddress;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;

public class BlockMasterClientPool {
  private final BlockingQueue<MasterClient> mClients;
  private final ExecutorService mExecutorService;

  public BlockMasterClientPool(InetSocketAddress masterAddress, TachyonConf conf) {
    // TODO: Get capacity from conf
    mClients = new LinkedBlockingQueue<MasterClient>(10);
    mExecutorService = Executors.newFixedThreadPool(10, ThreadFactoryUtils.build
        ("block-master-heartbeat-%d", true));

    // Initialize Clients
    for(int i = 0; i < mClients.size(); i++) {
      mClients.add(new MasterClient(masterAddress, mExecutorService, conf));
    }
  }

  public MasterClient acquire() throws InterruptedException {
    return mClients.take();
  }

  public void close() {
    // TODO: Consider collecting all the clients and shutting them down
    mExecutorService.shutdown();
  }

  public void release(MasterClient masterClient) {
    mClients.add(masterClient);
  }


}

@@ -1144,16 +1144,175 @@
 Queue;%0A%0A
+/**%0A * Class for managing block master clients. After obtaining a client with Acquire, Release must%0A * be called when the thread is done using the client.%0A */%0A
 public c
@@ -1908,24 +1908,295 @@
 %0A    %7D%0A  %7D%0A%0A
+  /**%0A   * Acquires a %7B@link MasterClient%7D, this operation is blocking if no clients are available.%0A   * @return a MasterClient, guaranteed to be only available to the caller%0A   * @throws InterruptedException if the thread is interrupted while waiting for a client%0A   */%0A
   public Mas
@@ -2270,32 +2270,122 @@
 ts.take();%0A  %7D%0A%0A
+  /**%0A   * Closes the client pool. After this call, the object should be discarded.%0A   */%0A
   public void cl
@@ -2502,16 +2502,295 @@
 );%0A  %7D%0A%0A
+  /**%0A   * Releases a %7B@link MasterClient%7D, this must be called after the thread is done using a client%0A   * obtained by acquire.%0A   * @param masterClient the MasterClient to be released, the client should not be used by the%0A   *                     thread after this call%0A   */%0A
   public
@@ -2868,12 +2868,10 @@
 t);%0A
+
   %7D%0A
-%0A%0A
 %7D%0A

Add javadocs and fix formatting.