本文整理汇总了Java中org.apache.curator.framework.recipes.nodes.PersistentNode.start方法的典型用法代码示例。如果您正苦于以下问题:Java PersistentNode.start方法的具体用法?Java PersistentNode.start怎么用?Java PersistentNode.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.curator.framework.recipes.nodes.PersistentNode
的用法示例。
在下文中一共展示了PersistentNode.start方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registry
import org.apache.curator.framework.recipes.nodes.PersistentNode; //导入方法依赖的package包/类
@Override
public void registry(RegistryConfig registryConfig) {
registryConfig.setRegistry(registry);
try {
String nodeName = registryConfig.getServerInfo().toString();
Map<String, PersistentNode> appKeyServers = nodeNames.computeIfAbsent(registryConfig.getAppKey(), (key) -> new ConcurrentHashMap<>());
if (appKeyServers.get(nodeName) != null) {
log.error("server registry exists: " + nodeName);
throw new TRpcRegistryException("server registry exists for key:" + nodeName);
}
String nodeValue = registryConfig.toJsonString();
PersistentNode node = new PersistentNode(client, CreateMode.EPHEMERAL, true, ZkConstant.SERVICES_DIR + registryConfig.getAppKey() + "/" + nodeName, nodeValue.getBytes());
node.start();
node.waitForInitialCreate(3, TimeUnit.SECONDS);
appKeyServers.put(nodeName, node);
String actualPath = node.getActualPath();
log.info("registry to zookeeper, node: " + actualPath + " value: " + nodeValue);
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else {
log.error("registry error", e);
}
}
}
示例2: advertise
import org.apache.curator.framework.recipes.nodes.PersistentNode; //导入方法依赖的package包/类
void advertise(
Closer closer,
InetSocketAddress endpoint,
Map<String, InetSocketAddress> additionalEndpoints)
throws AdvertiseException, InterruptedException {
byte[] nodeData = serializeAdvertisement(endpoint, additionalEndpoints);
PersistentNode persistentNode =
new PersistentNode(
client,
CreateMode.EPHEMERAL_SEQUENTIAL,
// TODO(John Sirois): Enable GUID protection once clients are updated to support
// its effects on group member node naming. We get nodes like:
// 4f5f98c4-8e71-41e3-8c8d-1c9a1f5f5df9-member_000000001
// Clients expect member_ is the prefix and are not prepared for the GUID.
false /* GUID protection */,
ZKPaths.makePath(groupPath, memberToken),
nodeData);
persistentNode.start();
closer.register(persistentNode);
// NB: This blocks on initial server set node population to emulate legacy
// SingletonService.LeaderControl.advertise (Group.join) behavior. Asynchronous
// population is an option though, we simply need to remove this wait.
if (!persistentNode.waitForInitialCreate(Long.MAX_VALUE, TimeUnit.DAYS)) {
throw new AdvertiseException("Timed out waiting for leader advertisement.");
}
}
示例3: registerHost
import org.apache.curator.framework.recipes.nodes.PersistentNode; //导入方法依赖的package包/类
/**
* Register Host to cluster.
*
* @param host Host to be part of cluster.
*/
@Override
@Synchronized
public void registerHost(Host host) {
Preconditions.checkNotNull(host, "host");
Exceptions.checkArgument(!entryMap.containsKey(host), "host", "host is already registered to cluster.");
String hostPath = ZKPaths.makePath(getPathPrefix(), host.toString());
PersistentNode node = new PersistentNode(client, CreateMode.EPHEMERAL, false, hostPath,
SerializationUtils.serialize(host));
node.start(); //start creation of ephemeral node in background.
entryMap.put(host, node);
}
示例4: doStart
import org.apache.curator.framework.recipes.nodes.PersistentNode; //导入方法依赖的package包/类
@Override
protected void doStart() throws Exception {
CuratorFramework client = zkClient.get();
if(client.checkExists().forPath(serverPath) != null){
byte []data = client.getData().forPath(serverPath);
throw new IllegalStateException("server already exist:" + new String(data));
}
persistentNode = new PersistentNode(zkClient.get(), CreateMode.EPHEMERAL, false, serverPath, Codec.DEFAULT.encodeAsBytes(getClusterInfo()));
persistentNode.start();
}
示例5: doStart
import org.apache.curator.framework.recipes.nodes.PersistentNode; //导入方法依赖的package包/类
protected void doStart() throws Exception {
int i = startingId;
while (this.id == -1) {
String lockPath = ZKPaths.makePath(locksBasePath, String.valueOf(i));
String memberPath = ZKPaths.makePath(membersBasePath, String.valueOf(i));
log.trace("Acquiring mutex for member {} via lock path {}", i, lockPath);
InterProcessMutex mutex = new InterProcessMutex(this.client, lockPath);
mutex.acquire();
log.debug("Acquired mutex for member {} via lock path {}", i, lockPath);
try {
Stat stat = client.checkExists().creatingParentContainersIfNeeded().forPath(memberPath);
if (stat == null) {
log.debug("Claiming container id {} via member path {}", i, memberPath);
try {
//no peer has this node yet, grab it:
pen = new PersistentNode(client, CreateMode.EPHEMERAL, false, memberPath, payload);
pen.start();
pen.waitForInitialCreate(30000, TimeUnit.SECONDS);
this.id = i;
log.info("Claimed container id {} via member path {}", i, memberPath);
return;
} catch (InterruptedException e) {
CloseableUtils.closeQuietly(pen);
ThreadUtils.checkInterrupted(e);
Throwables.propagate(e);
}
}
} finally {
mutex.release();
log.debug("Released mutex for member {} via lock path {}", i, lockPath);
}
i++;
}
}
示例6: testNode
import org.apache.curator.framework.recipes.nodes.PersistentNode; //导入方法依赖的package包/类
@Test
public void testNode() throws IOException{
String path = "/" + getTestName();
PersistentNode persistentNode = new PersistentNode(client, CreateMode.EPHEMERAL, false, path, "123456".getBytes());
persistentNode.start();
waitForAnyKeyToExit();
persistentNode.close();
}