示例#1
0
 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));
 }
示例#2
0
  private static void waitTillServerStarts() throws Exception {

    SenseiRequest req = new SenseiRequest();
    SenseiResult res = null;
    int count = 0;
    do {
      Thread.sleep(500);
      res = broker.browse(req);
      System.out.println("" + res.getNumHits() + " loaded...");
      ++count;
    } while (count < 20 && res.getNumHits() < 15000);
  }
示例#3
0
  /** 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;
    }
  }