Esempio n. 1
0
 public void shutdown() {
   try {
     logger.info("shutting down node...");
     try {
       _core.shutdown();
       _clusterClient.removeNode(_id);
       _clusterClient.shutdown();
       _serverNode = null;
       pluginRegistry.stop();
       _core.getPluggableSearchEngineManager().close();
     } catch (Exception e) {
       logger.warn(e.getMessage());
     } finally {
       if (_networkServer != null) {
         _networkServer.shutdown();
       }
     }
   } catch (Exception e) {
     logger.error(e.getMessage(), e);
   }
 }
Esempio n. 2
0
  public void start(boolean available) throws Exception {
    _core.start();
    //        ClusterClient clusterClient = ClusterClientFactory.newInstance().newZookeeperClient();
    String clusterName = _clusterClient.getServiceName();

    logger.info("Cluster Name: " + clusterName);
    logger.info("Cluster info: " + _clusterClient.toString());

    AbstractSenseiCoreService coreSenseiService = new CoreSenseiServiceImpl(_core);
    AbstractSenseiCoreService sysSenseiCoreService = new SysSenseiCoreServiceImpl(_core);
    // create the zookeeper cluster client
    //    SenseiClusterClientImpl senseiClusterClient = new SenseiClusterClientImpl(clusterName,
    // zookeeperURL, zookeeperTimeout, false);
    SenseiCoreServiceMessageHandler senseiMsgHandler =
        new SenseiCoreServiceMessageHandler(coreSenseiService);
    SenseiCoreServiceMessageHandler senseiSysMsgHandler =
        new SenseiCoreServiceMessageHandler(sysSenseiCoreService);

    _networkServer.registerHandler(senseiMsgHandler, coreSenseiService.getSerializer());
    _networkServer.registerHandler(senseiSysMsgHandler, sysSenseiCoreService.getSerializer());

    _networkServer.registerHandler(senseiMsgHandler, CoreSenseiServiceImpl.JAVA_SERIALIZER);
    _networkServer.registerHandler(senseiSysMsgHandler, SysSenseiCoreServiceImpl.JAVA_SERIALIZER);

    if (_externalSvc != null) {
      for (AbstractSenseiCoreService svc : _externalSvc) {
        _networkServer.registerHandler(
            new SenseiCoreServiceMessageHandler(svc), svc.getSerializer());
      }
    }
    HashSet<Integer> partition = new HashSet<Integer>();
    for (int partId : _partitions) {
      partition.add(partId);
    }

    boolean nodeExists = false;
    try {
      logger.info("waiting to connect to cluster...");
      _clusterClient.awaitConnectionUninterruptibly();
      _serverNode = _clusterClient.getNodeWithId(_id);
      nodeExists = (_serverNode != null);
      if (!nodeExists) {
        String ipAddr = getLocalIpAddress();
        logger.info("Node id : " + _id + " IP address : " + ipAddr);
        _serverNode = _clusterClient.addNode(_id, ipAddr, partition);
        logger.info("added node id: " + _id);
      } else {
        // node exists

      }
    } catch (Exception e) {
      logger.error(e.getMessage(), e);
      throw e;
    }

    try {
      logger.info("binding server ...");
      _networkServer.bind(_id, available);

      // exponential backoff
      Thread.sleep(1000);

      _available = available;
      logger.info("started [markAvailable=" + available + "] ...");
      if (nodeExists) {
        logger.warn("existing node found, will try to overwrite.");
        try {
          // remove node above
          _clusterClient.removeNode(_id);
          _serverNode = null;
        } catch (Exception e) {
          logger.error("problem removing old node: " + e.getMessage(), e);
        }

        String ipAddr = getLocalIpAddress();
        _serverNode = _clusterClient.addNode(_id, ipAddr, partition);
        Thread.sleep(1000);

        logger.info("added node id: " + _id);
      }
    } catch (NetworkingException e) {
      logger.error(e.getMessage(), e);

      try {
        if (!nodeExists) {
          _clusterClient.removeNode(_id);
          _serverNode = null;
        }
      } catch (Exception ex) {
        logger.warn(ex.getMessage());
      } finally {
        try {
          _networkServer.shutdown();
          _networkServer = null;

        } finally {
          _clusterClient.shutdown();
          _clusterClient = null;
        }
      }
      throw e;
    }
    SenseiServerAdminMBean senseiAdminMBean = getAdminMBean();
    StandardMBean bean = new StandardMBean(senseiAdminMBean, SenseiServerAdminMBean.class);
    JmxUtil.registerMBean(bean, "name", "sensei-server-" + _id);
  }