public SenseiServer buildServer() throws ConfigurationException { int port = _senseiConf.getInt(SERVER_PORT); JmxSenseiMBeanServer.registerCustomMBeanServer(); ClusterClient clusterClient = buildClusterClient(); NetworkServer networkServer = buildNetworkServer(_senseiConf, clusterClient); SenseiCore core = buildCore(); List<AbstractSenseiCoreService<AbstractSenseiRequest, AbstractSenseiResult>> svcList = (List) pluginRegistry.resolveBeansByListKey( SENSEI_PLUGIN_SVCS, AbstractSenseiCoreService.class); return new SenseiServer(port, networkServer, clusterClient, core, svcList, pluginRegistry); }
/** 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; } }