io.vertx.ext.consul.KeyValue.getModifyIndex()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(4.4k)|赞(0)|评价(0)|浏览(93)

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

KeyValue.getModifyIndex介绍

[英]Get the last index that modified this key.
[中]获取修改此键的最后一个索引。

代码示例

代码示例来源:origin: io.vertx/vertx-consul-client

public static void toJson(KeyValue obj, java.util.Map<String, Object> json) {
  json.put("createIndex", obj.getCreateIndex());
  json.put("flags", obj.getFlags());
  if (obj.getKey() != null) {
   json.put("key", obj.getKey());
  }
  json.put("lockIndex", obj.getLockIndex());
  json.put("modifyIndex", obj.getModifyIndex());
  if (obj.getSession() != null) {
   json.put("session", obj.getSession());
  }
  if (obj.getValue() != null) {
   json.put("value", obj.getValue());
  }
 }
}

代码示例来源:origin: io.vertx/vertx-consul-client

@Override
 void wait(long index, Handler<AsyncResult<State<KeyValue>>> handler) {
  BlockingQueryOptions options = new BlockingQueryOptions().setWait(BLOCKING_WAIT).setIndex(index);
  consulClient.getValueWithOptions(key, options, h ->
   handler.handle(h.map(kv -> new State<KeyValue>(kv, kv.getModifyIndex()))));
 }
}

代码示例来源:origin: io.vertx/vertx-consul-client

@Test
public void canGetValueBlocking(TestContext tc) {
 blockingQuery(tc, (key, h) -> ctx.readClient().getValue(key, tc.asyncAssertSuccess(list -> h.handle(list.getModifyIndex()))));
}

代码示例来源:origin: io.vertx/vertx-consul-client

private void createKV(TestContext tc, String key, String value, Handler<Long> resultHandler) {
  ctx.writeClient().putValue(key, value, tc.asyncAssertSuccess(b -> {
   tc.assertTrue(b);
   ctx.readClient().getValue(key, tc.asyncAssertSuccess(pair -> {
    resultHandler.handle(pair.getModifyIndex());
   }));
  }));
 }
}

代码示例来源:origin: io.vertx/vertx-consul-client

private void checkKeyValue(KeyValue expected, KeyValue actual) {
 assertEquals(expected, actual);
 assertEquals(expected.hashCode(), actual.hashCode());
 assertEquals(expected.getKey(), actual.getKey());
 assertEquals(expected.getValue(), actual.getValue());
 assertEquals(expected.getSession(), actual.getSession());
 assertEquals(expected.getCreateIndex(), actual.getCreateIndex());
 assertEquals(expected.getFlags(), actual.getFlags());
 assertEquals(expected.getModifyIndex(), actual.getModifyIndex());
 assertEquals(expected.getLockIndex(), actual.getLockIndex());
}

代码示例来源:origin: io.vertx/vertx-consul-client

@Test
public void checkAndSet(TestContext tc) {
 String key = randomFooBarAlpha();
 ctx.writeClient()
  .putValue(key, randomAlphaString(10), tc.asyncAssertSuccess(b1 -> {
   tc.assertTrue(b1);
   ctx.readClient().getValue(key, tc.asyncAssertSuccess(pair1 -> {
    ctx.writeClient().putValue(key, randomAlphaString(10), tc.asyncAssertSuccess(b2 -> {
     tc.assertTrue(b2);
     ctx.readClient().getValue(key, tc.asyncAssertSuccess(pair2 -> {
      tc.assertTrue(pair1.getModifyIndex() < pair2.getModifyIndex());
      ctx.writeClient().putValueWithOptions(key, randomAlphaString(10), new KeyValueOptions().setCasIndex(pair1.getModifyIndex()), tc.asyncAssertSuccess(b3 -> {
       tc.assertFalse(b3);
       ctx.writeClient().putValueWithOptions(key, randomAlphaString(10), new KeyValueOptions().setCasIndex(pair2.getModifyIndex()), tc.asyncAssertSuccess(b4 -> {
        tc.assertTrue(b4);
        ctx.writeClient().deleteValue(key, tc.asyncAssertSuccess());
       }));
      }));
     }));
    }));
   }));
  }));
}

代码示例来源:origin: io.vertx/vertx-consul-client

private void blockingQuery(TestContext tc, BiConsumer<String, Handler<Long>> indexSupplier) {
  String key = randomFooBarAlpha();
  String value = randomAlphaString(10);
  ctx.writeClient()
   .putValue(key, randomAlphaString(10), tc.asyncAssertSuccess(b1 -> {
    tc.assertTrue(b1);
    indexSupplier.accept(key, consulIndex -> {
     Async async = tc.async(2);
     vertx.setTimer(TimeUnit.SECONDS.toMillis(2), l -> {
      ctx.writeClient().putValue(key, value, tc.asyncAssertSuccess(b2 -> {
       tc.assertTrue(b2);
       ctx.readClient().getValueWithOptions(key, new BlockingQueryOptions().setIndex(consulIndex), tc.asyncAssertSuccess(kv -> {
        tc.assertTrue(kv.getModifyIndex() > consulIndex);
        tc.assertEquals(kv.getValue(), value);
        async.countDown();
       }));
       ctx.readClient().getValuesWithOptions("foo/bar", new BlockingQueryOptions().setIndex(consulIndex), tc.asyncAssertSuccess(kv -> {
        tc.assertTrue(kv.getIndex() > consulIndex);
        tc.assertTrue(kv.getList().size() == 1);
        async.countDown();
       }));
      }));
     });
     async.handler(v -> ctx.writeClient().deleteValue(key, tc.asyncAssertSuccess()));
    });
   }));
 }
}

相关文章