private static void shutdownSensei() { try { broker.shutdown(); } catch (Throwable t) { } try { httpRestSenseiService.shutdown(); } catch (Throwable t) { } try { node1.shutdown(); } catch (Throwable t) { } try { httpServer1.stop(); } catch (Throwable t) { } try { node2.shutdown(); } catch (Throwable t) { } try { httpServer2.stop(); } catch (Throwable t) { } try { networkClient.shutdown(); } catch (Throwable t) { } try { clusterClient.shutdown(); } catch (Throwable t) { } rmrf(new File(IndexDir)); }
@Override public void destroy() { if (_senseiServer != null) { _senseiServer.shutdown(); } super.destroy(); }
@Override public void init(ServletConfig config) throws ServletException { ServletContext ctx = config.getServletContext(); String confDirName = ctx.getInitParameter(SenseiConfigServletContextListener.SENSEI_CONF_DIR_PARAM); if (confDirName == null) { throw new ServletException( "configuration not specified, " + SenseiConfigServletContextListener.SENSEI_CONF_DIR_PARAM + " not set"); } SenseiServerBuilder builder; try { builder = new SenseiServerBuilder(new File(confDirName), null); ctx.setAttribute("sensei.search.configuration", builder.getConfiguration()); ctx.setAttribute("sensei.search.version.comparator", builder.getVersionComparator()); SenseiPluginRegistry pluginRegistry = builder.getPluginRegistry(); PartitionedLoadBalancerFactory<String> routerFactory = pluginRegistry.getBeanByFullPrefix( SenseiConfParams.SERVER_SEARCH_ROUTER_FACTORY, PartitionedLoadBalancerFactory.class); if (routerFactory == null) { routerFactory = new SenseiPartitionedLoadBalancerFactory(50); } ctx.setAttribute("sensei.search.router.factory", routerFactory); _senseiServer = builder.buildServer(); _senseiServer.start(true); super.init(config); } catch (Exception e) { throw new ServletException(e.getMessage(), e); } }
public static void main(String[] args) throws Exception { if (args.length < 1) { System.out.println(help()); System.exit(1); } File confDir = null; try { confDir = new File(args[0]); } catch (Exception e) { System.out.println(help()); System.exit(1); } boolean available = true; for (int i = 1; i < args.length; i++) { if (args[i] != null) { if (AVAILABLE.equalsIgnoreCase(args[i])) { available = true; } if (UNAVAILABLE.equalsIgnoreCase(args[i])) { available = false; } } } /*File extDir = new File(confDir,"ext"); if (extDir.exists()){ logger.info("loading extension jars..."); loadJars(extDir); logger.info("finished loading extension jars"); }*/ SenseiServerBuilder senseiServerBuilder = new SenseiServerBuilder(confDir, null); final SenseiServer server = senseiServerBuilder.buildServer(); final Server jettyServer = senseiServerBuilder.buildHttpRestServer(); /*final HttpAdaptor httpAdaptor = senseiServerBuilder.buildJMXAdaptor(); final ObjectName httpAdaptorName = new ObjectName("mx4j:class=mx4j.tools.adaptor.http.HttpAdaptor,id=1"); if (httpAdaptor!=null){ try{ server.mbeanServer.registerMBean(httpAdaptor, httpAdaptorName); server.mbeanServer.invoke(httpAdaptorName, "start", null, null); httpAdaptor.setProcessor(new XSLTProcessor()); logger.info("http adaptor started on port: "+httpAdaptor.getPort()); } catch(Exception e){ logger.error(e.getMessage(),e); } } */ Runtime.getRuntime() .addShutdownHook( new Thread() { @Override public void run() { try { server.setAvailable(false); jettyServer.stop(); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { try { server.shutdown(); } finally { /*try{ if (httpAdaptor!=null){ httpAdaptor.stop(); server.mbeanServer.invoke(httpAdaptorName, "stop", null, null); server.mbeanServer.unregisterMBean(httpAdaptorName); logger.info("http adaptor shutdown"); } } catch(Exception e){ logger.error(e.getMessage(),e); }*/ } } } }); server.start(available); jettyServer.start(); }
/** Will start the new Sensei instance once per process */ public static synchronized void start(String confDir1, String confDir2) { if (started) { logger.warn("The server had been already started"); return; } try { JmxSenseiMBeanServer.registerCustomMBeanServer(); ConfDir1 = new File(SenseiStarter.class.getClassLoader().getResource(confDir1).toURI()); ConfDir2 = new File(SenseiStarter.class.getClassLoader().getResource(confDir2).toURI()); org.apache.log4j.PropertyConfigurator.configure("resources/log4j.properties"); loadFromSpringContext(); boolean removeSuccessful = rmrf(new File(IndexDir)); if (!removeSuccessful) { throw new IllegalStateException("The index dir " + IndexDir + " coulnd't be purged"); } SenseiServerBuilder senseiServerBuilder1 = null; senseiServerBuilder1 = new SenseiServerBuilder(ConfDir1, null); node1 = senseiServerBuilder1.buildServer(); httpServer1 = senseiServerBuilder1.buildHttpRestServer(); logger.info("Node 1 created."); SenseiServerBuilder senseiServerBuilder2 = null; senseiServerBuilder2 = new SenseiServerBuilder(ConfDir2, null); node2 = senseiServerBuilder2.buildServer(); httpServer2 = senseiServerBuilder2.buildHttpRestServer(); logger.info("Node 2 created."); broker = null; try { broker = new SenseiBroker(networkClient, clusterClient, loadBalancerFactory); broker.setTimeoutMillis(0); mapReduceBroker = new MapReduceBroker(networkClient, clusterClient, loadBalancerFactory); broker.setTimeoutMillis(0); } catch (NorbertException ne) { logger.info("shutting down cluster...", ne); clusterClient.shutdown(); throw ne; } httpRestSenseiService = new HttpRestSenseiServiceImpl("http", "localhost", 8079, "/sensei"); logger.info("Cluster client started"); Runtime.getRuntime() .addShutdownHook( new Thread() { @Override public void run() { shutdownSensei(); } }); node1.start(true); httpServer1.start(); logger.info("Node 1 started"); node2.start(true); httpServer2.start(); logger.info("Node 2 started"); SenseiUrl = new URL("http://localhost:8079/sensei"); waitTillServerStarts(); } catch (Throwable ex) { logger.error("Could not start the sensei", ex); throw new RuntimeException(ex); } finally { started = true; } }