gpt4 book ai didi

io.vertx.servicediscovery.backend.zookeeper.ZookeeperBackendService类的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 10:53:30 26 4
gpt4 key购买 nike

本文整理了Java中io.vertx.servicediscovery.backend.zookeeper.ZookeeperBackendService类的一些代码示例,展示了ZookeeperBackendService类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZookeeperBackendService类的具体详情如下:
包路径:io.vertx.servicediscovery.backend.zookeeper.ZookeeperBackendService
类名称:ZookeeperBackendService

ZookeeperBackendService介绍

暂无

代码示例

代码示例来源:origin: io.vertx/vertx-service-discovery-backend-zookeeper

@Override
protected ServiceDiscoveryBackend createBackend() {
 ZookeeperBackendService backend = new ZookeeperBackendService();
 backend.init(vertx, new JsonObject()
   .put("connection",  server.getConnectString())
   .put("baseSleepTimeBetweenRetries",  10)
   .put("connectionTimeoutMs",  1000));
 return backend;
}

代码示例来源:origin: vert-x3/vertx-service-discovery

Context context = Vertx.currentContext();
ensureConnected(x -> {
 if (x.failed()) {
  resultHandler.handle(Future.failedFuture(x.cause()));
 } else {
  getRecordById(context, uuid, record -> {
   if (record == null) {
    resultHandler.handle(Future.failedFuture("Unknown registration " + uuid));
       .deletingChildrenIfNeeded()
       .inBackground((curatorFramework, curatorEvent)
         -> callback(context, record, resultHandler, curatorEvent))
       .forPath(getPath(uuid));
    } catch (Exception e) {
     resultHandler.handle(Future.failedFuture(e));

代码示例来源:origin: vert-x3/vertx-service-discovery

@Override
public void remove(Record record, Handler<AsyncResult<Record>> resultHandler) {
 Objects.requireNonNull(record.getRegistration(), "No registration id in the record");
 remove(record.getRegistration(), resultHandler);
}

代码示例来源:origin: vert-x3/vertx-service-discovery

private void getRecordById(Context context, String uuid, Handler<Record> handler) {
 ensureConnected(x -> {
  if (x.failed()) {
   handler.handle(null);
  } else {
   try {
    client.getData()
      .inBackground((curatorFramework, curatorEvent)
        -> runOnContextIfPossible(context, () -> {
       if (curatorEvent.getResultCode() == KeeperException.Code.OK.intValue()) {
        JsonObject json
          = new JsonObject(new String(curatorEvent.getData(), CHARSET));
        handler.handle(new Record(json));
       } else {
        handler.handle(null);
       }
      }))
      .forPath(getPath(uuid));
   } catch (Exception e) {
    handler.handle(null);
   }
  }
 });
}

代码示例来源:origin: vert-x3/vertx-service-discovery

@Override
public void store(Record record, Handler<AsyncResult<Record>> resultHandler) {
 if (record.getRegistration() != null) {
  resultHandler.handle(Future.failedFuture("The record has already been registered"));
  return;
 }
 String uuid = UUID.randomUUID().toString();
 record.setRegistration(uuid);
 String content = record.toJson().encode();
 Context context = Vertx.currentContext();
 ensureConnected(x -> {
  if (x.failed()) {
   resultHandler.handle(Future.failedFuture(x.cause()));
  } else {
   try {
    client.create()
      .creatingParentsIfNeeded()
      .withMode(ephemeral ? CreateMode.EPHEMERAL : CreateMode.PERSISTENT)
      .inBackground((curatorFramework, curatorEvent)
        -> callback(context, record, resultHandler, curatorEvent))
      .withUnhandledErrorListener((s, throwable)
        -> resultHandler.handle(Future.failedFuture(throwable)))
      .forPath(getPath(record.getRegistration()), content.getBytes(CHARSET));
   } catch (Exception e) {
    resultHandler.handle(Future.failedFuture(e));
   }
  }
 });
}

代码示例来源:origin: vert-x3/vertx-service-discovery

@Override
public void getRecords(Handler<AsyncResult<List<Record>>> resultHandler) {
 Context context = Vertx.currentContext();
 ensureConnected(
   x -> {
    if (x.failed()) {
         for (String child : children) {
          Future<Record> future = Future.future();
          getRecord(child, future.completer());
          futures.add(future);
             ar -> runOnContextIfPossible(context, () -> {
              if (ar.failed()) {
               resultHandler.handle(Future.failedFuture(ar.cause()));

代码示例来源:origin: vert-x3/vertx-service-discovery

private void callback(Context context, Record record, Handler<AsyncResult<Record>> resultHandler, CuratorEvent curatorEvent) {
 runOnContextIfPossible(context, () -> {
  if (curatorEvent.getResultCode() == KeeperException.Code.OK.intValue()) {
   resultHandler.handle(Future.succeededFuture(record));
  } else {
   KeeperException.Code code =
     KeeperException.Code.get(curatorEvent.getResultCode());
   resultHandler.handle(Future.failedFuture(KeeperException.create(code)));
  }
 });
}

代码示例来源:origin: vert-x3/vertx-service-discovery

@Override
public void update(Record record, Handler<AsyncResult<Void>> resultHandler) {
 Objects.requireNonNull(record.getRegistration(), "No registration id in the record");
 Context context = Vertx.currentContext();
 ensureConnected(x -> {
  if (x.failed()) {
   resultHandler.handle(Future.failedFuture(x.cause()));
  } else {
   try {
    client.setData()
      .inBackground((framework, event)
        -> runOnContextIfPossible(context, () -> {
       if (event.getResultCode() == KeeperException.Code.OK.intValue()) {
        resultHandler.handle(Future.succeededFuture());
       } else {
        KeeperException.Code code = KeeperException.Code.get(event.getResultCode());
        resultHandler.handle(Future.failedFuture(KeeperException.create(code)));
       }
      }))
      .withUnhandledErrorListener((message, e) -> resultHandler.handle(Future.failedFuture(e)))
      .forPath(getPath(record.getRegistration()),
        record.toJson().encode().getBytes(CHARSET));
   } catch (Exception e) {
    resultHandler.handle(Future.failedFuture(e));
   }
  }
 });
}

代码示例来源:origin: vert-x3/vertx-service-discovery

Context context = Vertx.currentContext();
ensureConnected(x -> {
 if (x.failed()) {
  handler.handle(Future.failedFuture(x.cause()));
   client.getData()
     .inBackground((fmk, curatorEvent)
       -> runOnContextIfPossible(context, () -> {
      if (curatorEvent.getResultCode() == KeeperException.Code.OK.intValue()) {
       JsonObject json
     .forPath(getPath(uuid));
  } catch (Exception e) {
   handler.handle(Future.failedFuture(e));

代码示例来源:origin: io.vertx/vertx-service-discovery-backend-zookeeper

@Override
 protected ServiceDiscoveryBackend createBackend() {
  ZookeeperBackendService backend = new ZookeeperBackendService();
  backend.init(vertx, new JsonObject()
    .put("connection", server.getConnectString())
    .put("ephemeral", true)
    .put("guaranteed", true)
    .put("basePath", "/services/my-backend")
  );
  return backend;
 }
}

代码示例来源:origin: vert-x3/vertx-service-discovery

@Override
 protected ServiceDiscoveryBackend createBackend() {
  ZookeeperBackendService backend = new ZookeeperBackendService();
  backend.init(vertx, new JsonObject()
    .put("connection", server.getConnectString())
    .put("ephemeral", true)
    .put("guaranteed", true)
    .put("basePath", "/services/my-backend")
  );
  return backend;
 }
}

代码示例来源:origin: vert-x3/vertx-service-discovery

@Override
protected ServiceDiscoveryBackend createBackend() {
 ZookeeperBackendService backend = new ZookeeperBackendService();
 backend.init(vertx, new JsonObject()
   .put("connection",  server.getConnectString())
   .put("baseSleepTimeBetweenRetries",  10)
   .put("connectionTimeoutMs",  1000));
 return backend;
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com