/**
   * Place the host:port advertisement for the Monitor's Log4j listener in ZooKeeper
   *
   * @param conf configuration for the instance
   * @param instanceId instanceId for the instance
   * @param hostAddress Address that monitor process is bound to
   */
  public static void startLogListener(
      AccumuloConfiguration conf, String instanceId, String hostAddress) {
    try {
      SocketServer server = new SocketServer(conf.getPort(Property.MONITOR_LOG4J_PORT));

      // getLocalPort will return the actual ephemeral port used when '0' was provided.
      String logForwardingAddr = hostAddress + ":" + server.getLocalPort();

      log.debug("Setting monitor log4j log-forwarding address to: " + logForwardingAddr);

      final String path = ZooUtil.getRoot(instanceId) + Constants.ZMONITOR_LOG4J_ADDR;
      final ZooReaderWriter zoo = ZooReaderWriter.getInstance();

      // Delete before we try to re-create in case the previous session hasn't yet expired
      try {
        zoo.delete(path, -1);
      } catch (KeeperException e) {
        // We don't care if the node is already gone
        if (!KeeperException.Code.NONODE.equals(e.code())) {
          throw e;
        }
      }

      zoo.putEphemeralData(path, logForwardingAddr.getBytes(UTF_8));

      new Daemon(server).start();
    } catch (Throwable t) {
      log.info("Unable to start/advertise Log4j listener for log-forwarding to monitor", t);
    }
  }
 @Override
 public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
   if (event.getResultCode() == KeeperException.Code.NONODE.intValue()) {
     createNode();
   } else {
     boolean isEphemeral = event.getStat().getEphemeralOwner() != 0;
     if (isEphemeral != mode.isEphemeral()) {
       log.warn(
           "Existing node ephemeral state doesn't match requested state. Maybe the node was created outside of PersistentNode? "
               + basePath);
     }
   }
 }