Tabnine Logo
ZkClient.newChildWatcher
Code IndexAdd Tabnine to your IDE (free)

How to use
newChildWatcher
method
in
me.hao0.antares.common.zk.ZkClient

Best Java code snippets using me.hao0.antares.common.zk.ZkClient.newChildWatcher (Showing top 5 results out of 315)

origin: ihaolin/antares

/**
 * new a watcher of path child
 * @param path the parent path
 * @param listener a listener
 * NOTE:
 *   Only watch first level children, not recursive
 */
public ChildWatcher newChildWatcher(String path, ChildListener listener) {
  return newChildWatcher(path, listener, Boolean.TRUE);
}
origin: ihaolin/antares

private void listenOnServerChanged() {
  zk.newChildWatcher(ZkPaths.SERVERS, new ChildListener() {
    @Override
    protected void onAdd(String path, byte[] data) {
      String server = ZkPaths.lastNode(path);
      client.addHttpServer(server);
      log.info("The server({}) joined.", server);
    }
    @Override
    protected void onDelete(String path) {
      String server = ZkPaths.lastNode(path);
      client.removeHttpServer(server);
      log.info("The server({}) left.", server);
    }
  });
}
origin: ihaolin/antares

@Override
public void doStart(){
  // watching the alive servers
  watcher = zk.client().newChildWatcher(ZkPaths.SERVERS, new ChildListener() {
    @Override
    protected void onAdd(String path, byte[] data) {
      String server = ZkPaths.lastNode(path);
      if (!alives.contains(server)){
        alives.add(server);
        notifyListeners(server, true);
        Logs.info("The server ({}) is joined.", server);
      }
    }
    @Override
    protected void onDelete(String path) {
      String server = ZkPaths.lastNode(path);
      if(alives.remove(server)){
        notifyListeners(server, false);
        Logs.warn("The server ({}) is left.", server);
      }
    }
  });
}
origin: ihaolin/antares

@Override
public void doStart() {
  // listen app's clients change
  watcher = zk.client().newChildWatcher(ZkPaths.pathOfAppClients(appName), new ChildListener() {
    @Override
    protected void onAdd(String path, byte[] data) {
      // not started, or has shutdown
      // prevent multiple redundant notifies before started
      if (!started || shutdowned) {
        return;
      }
      String client = ZkPaths.lastNode(path);
      if (alives.contains(client)){
        return;
      }
      alives.add(client);
      onClientChanged(appName, client, true);
      Logs.info("The app({})'s client({}) joined.", appName, client);
    }
    @Override
    protected void onDelete(String path) {
      String client = ZkPaths.lastNode(path);
      alives.remove(client);
      onClientChanged(appName, client, false);
      Logs.info("The app({})'s client({}) left.", appName, client);
    }
  });
}
origin: ihaolin/antares

@Override
public void doStart() {
  String appName = client.getAppName();
  String jobClass = getJobClass();
  String jobInstancesNodePath = ZkPaths.pathOfJobInstances(appName, jobClass);
  this.watcher = client.getZk().newChildWatcher(jobInstancesNodePath, new ChildListener() {
    @Override
    protected void onAdd(String path, byte[] data) {
      // fired a new job instance
      String instanceId = ZkPaths.lastNode(path);
      if (Strings.isNullOrEmpty(instanceId)) return;
      // execute the job
      client.getJobExecutor().execute(Long.valueOf(instanceId), ZkJob.this);
    }
  });
}
me.hao0.antares.common.zkZkClientnewChildWatcher

Javadoc

new a watcher of path child

Popular methods of ZkClient

  • checkExists
    Check the path exists or not
  • createEphemeral
    Create an ephemeral path
  • gets
    Get the children of the path
  • mkdirs
    Make directories if necessary
  • newClient
    Create a client instance
  • update
  • acquireLeader
    Acquire the leadership
  • create
    Create an persistent path
  • deleteIfExists
    Delete the node if the node exists
  • getString
    get the node data as string
  • newLock
    lock the path
  • newNodeWatcher
    new a node watcher
  • newLock,
  • newNodeWatcher,
  • shutdown,
  • <init>,
  • client,
  • createEphemeralSequential,
  • createIfNotExists,
  • createSequential,
  • delete

Popular in Java

  • Running tasks concurrently on multiple threads
  • getExternalFilesDir (Context)
  • getContentResolver (Context)
  • setScale (BigDecimal)
  • FileInputStream (java.io)
    An input stream that reads bytes from a file. File file = ...finally if (in != null) in.clos
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • String (java.lang)
  • ServerSocket (java.net)
    This class represents a server-side socket that waits for incoming client connections. A ServerSocke
  • Timestamp (java.sql)
    A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now