package com.sensei.search.client.servlet;

import java.util.Comparator;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import com.sensei.search.cluster.routing.SenseiLoadBalancerFactory;

import org.apache.commons.configuration.Configuration;

public class ZookeeperConfigurableServlet extends HttpServlet {
  
  /**
   * 
   */
  private static final long serialVersionUID = 1L;
  protected String zkurl;
  protected String clusterName;
  protected int zkTimeout;
  protected int connectTimeoutMillis;
  protected int writeTimeoutMillis;
  protected int maxConnectionsPerNode;
  protected int staleRequestTimeoutMins;
  protected int staleRequestCleanupFrequencyMins;
  protected SenseiLoadBalancerFactory loadBalancerFactory;
  protected Comparator<String> versionComparator;

  @Override
  public void init(ServletConfig config) throws ServletException {
    super.init(config);
    
    ServletContext ctx = config.getServletContext();
    
    Configuration senseConf = (Configuration)ctx.getAttribute(SenseiConfigServletContextListener.SENSEI_CONF_OBJ);
      
    zkurl = senseConf.getString(SenseiConfigServletContextListener.SENSEI_CONF_ZKURL);
    clusterName = senseConf.getString(SenseiConfigServletContextListener.SENSEI_CONF_CLUSTER_NAME);
    zkTimeout = senseConf.getInt(SenseiConfigServletContextListener.SENSEI_CONF_ZKTIMEOUT,10000);
    connectTimeoutMillis = senseConf.getInt(SenseiConfigServletContextListener.SENSEI_CONF_NC_CONN_TIMEOUT, 1000);
    writeTimeoutMillis = senseConf.getInt(SenseiConfigServletContextListener.SENSEI_CONF_NC_WRITE_TIMEOUT, 150);
    maxConnectionsPerNode = senseConf.getInt(SenseiConfigServletContextListener.SENSEI_CONF_NC_MAX_CONN_PER_NODE, 5);
    staleRequestTimeoutMins = senseConf.getInt(SenseiConfigServletContextListener.SENSEI_CONF_NC_STALE_TIMEOUT_MINS, 10);
    staleRequestCleanupFrequencyMins = senseConf.getInt(SenseiConfigServletContextListener.SENSEI_CONF_NC_STALE_CLEANUP_FREQ_MINS, 10);

    versionComparator = (Comparator<String>)ctx.getAttribute(SenseiConfigServletContextListener.SENSEI_CONF_VERSION_COMPARATOR);
    loadBalancerFactory = (SenseiLoadBalancerFactory)ctx.getAttribute(
        SenseiConfigServletContextListener.SENSEI_CONF_ROUTER_FACTORY);
  }
}

@@ -1063,24 +1063,25 @@
 ration sense
+i
 Conf = (Conf
@@ -1175,21 +1175,86 @@
     
-zkurl =
+StringBuilder zkUrlBuilder = new StringBuilder();%0A    for(String part :
  sense
+i
 Conf
@@ -1255,32 +1255,37 @@
 eiConf.getString
+Array
 (SenseiConfigSer
@@ -1322,16 +1322,169 @@
 F_ZKURL)
+)%0A    %7B%0A      if (zkUrlBuilder.length() %3E 0)%0A        zkUrlBuilder.append(',');%0A      zkUrlBuilder.append(part);%0A    %7D%0A    zkurl = zkUrlBuilder.toString()
 ;%0A    cl
@@ -1492,32 +1492,33 @@
 sterName = sense
+i
 Conf.getString(S
@@ -1591,32 +1591,33 @@
 kTimeout = sense
+i
 Conf.getInt(Sens
@@ -1701,32 +1701,33 @@
 utMillis = sense
+i
 Conf.getInt(Sens
@@ -1815,32 +1815,33 @@
 utMillis = sense
+i
 Conf.getInt(Sens
@@ -1932,32 +1932,33 @@
 sPerNode = sense
+i
 Conf.getInt(Sens
@@ -2053,32 +2053,33 @@
 eoutMins = sense
+i
 Conf.getInt(Sens
@@ -2193,16 +2193,17 @@
  = sense
+i
 Conf.get

Fix zkUrl sensei rest api broker.