Permalink
Browse files

Expose Sensei broker and cluster services through a servlet context a…

…ttribute
  • Loading branch information...
1 parent 591f265 commit ecc2899f20d61e84610bc9bdb5716168425410a5 @santip santip committed Feb 15, 2013
@@ -28,6 +28,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -111,6 +112,7 @@
import com.senseidb.search.req.AbstractSenseiRequest;
import com.senseidb.search.req.AbstractSenseiResult;
import com.senseidb.search.req.SenseiSystemInfo;
+import com.senseidb.servlet.AbstractSenseiClientServlet;
import com.senseidb.servlet.DefaultSenseiJSONServlet;
import com.senseidb.servlet.SenseiConfigServletContextListener;
import com.senseidb.servlet.SenseiHttpInvokerServiceServlet;
@@ -223,6 +225,7 @@ public Server buildHttpRestServer() throws Exception {
//}
//senseiApp.setInitParams(initParam);
senseiApp.setAttribute("sensei.search.configuration", _senseiConf);
+ senseiApp.setAttribute("sensei.broker.export", new AbstractSenseiClientServlet.SenseiBrokerExport());
senseiApp.setAttribute(SenseiConfigServletContextListener.SENSEI_CONF_PLUGIN_REGISTRY, pluginRegistry);
senseiApp.setAttribute("sensei.search.version.comparator", _gateway.getVersionComparator());
@@ -45,7 +45,6 @@
import com.browseengine.bobo.api.BrowseSelection;
import com.linkedin.norbert.javacompat.cluster.ClusterClient;
-import com.linkedin.norbert.javacompat.cluster.ZooKeeperClusterClient;
import com.linkedin.norbert.javacompat.network.NetworkClientConfig;
import com.senseidb.bql.parsers.BQLCompiler;
import com.senseidb.cluster.client.SenseiNetworkClient;
@@ -107,6 +106,13 @@ public void init(ServletConfig config) throws ServletException {
}
logger.info("Connecting to cluster: " + brokerConfig.getClusterName() +" ...");
_clusterClient.awaitConnectionUninterruptibly();
+
+ SenseiBrokerExport export = (SenseiBrokerExport)config.getServletContext().getAttribute("sensei.broker.export");
+ export.broker = _senseiBroker;
+ export.sysBroker = _senseiSysBroker;
+ export.networkClient = _networkClient;
+ export.clusterClient = _clusterClient;
+ export.servlet = this;
int count = 0;
while (true)
@@ -142,6 +148,7 @@ public void init(ServletConfig config) throws ServletException {
}
}
}
+ export.facetInfo = _facetInfoMap;
logger.info("Cluster: "+ brokerConfig.getClusterName() +" successfully connected ");
}
@@ -664,4 +671,13 @@ public void destroy() {
super.destroy();
}
}
+
+ public static class SenseiBrokerExport {
+ public AbstractSenseiClientServlet servlet;
+ public ClusterClient clusterClient;
+ public SenseiNetworkClient networkClient;
+ public SenseiSysBroker sysBroker;
+ public SenseiBroker broker;
+ public Map<String, String[]> facetInfo;
+ }
}

0 comments on commit ecc2899

Please sign in to comment.