In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How to call Java API to create a basic Zookerper, for this problem, this article details the corresponding analysis and solution, hoping to help more friends who want to solve this problem find a simpler and easier way.
Here's how to invoke the Java API to create a basic Zookerper session instance
import java.util.concurrent.CountDownLatch;import org.apache.zookeeper.WatchedEvent;import org. apache.zookeeper.Watcher;import org. apache.zookeeper.Watcher.Event.KeeperState;import org.apache.zookeeper.Zookeeper;public class zookeeper_simple_usage implements Watcher { private static CountDownLatch connectedSemaphore = new CountDownLatch(1); public static void main (String[] args) throws Exception{ ZooKeeper zookeeper = new ZooKeeper("202.201.13.55:2100", 5000, new zookeeper_simple_usage()); System.out.println(zookeeper.getState()); try{ connectedSemaphore.await(); } catch (InterruptedException e){} System.out.println("ZooKeeper session established. "); } public void process(WatchedEvent event) { System.out.println("Received watched evnet: " + event); if (KeeperState.SyncConnected == event.getState()) { connectedSemaphore.countDown(); } }}
The process method in WatchedEvent must be overloaded.
execution result
Received watched evnet: WatchedEvent state:SyncConnected type:None path:nullZooKeeper session established.
Four packages need to be added to Build Path
zookerper-3.4.6.jar
log4j-1.2.14.jar
slf4j-api-1.7.12.jar
slf4j-simple-1.7.12.jar
Otherwise, you will report a class not found.
About how to call Java API to create a basic Zookerper question answer to share here, I hope the above content can be of some help to everyone, if you still have a lot of doubts not solved, you can pay attention to the industry information channel to learn more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.