当前位置: 首页>>代码示例>>Java>>正文


Java EtcdClient类代码示例

本文整理汇总了Java中mousio.etcd4j.EtcdClient的典型用法代码示例。如果您正苦于以下问题:Java EtcdClient类的具体用法?Java EtcdClient怎么用?Java EtcdClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


EtcdClient类属于mousio.etcd4j包,在下文中一共展示了EtcdClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: EtcdDiscoverer

import mousio.etcd4j.EtcdClient; //导入依赖的package包/类
/**
 * Instantiates a new etcd discoverer and connects to etcd using the given URI.
 * @param uri The URI to connect to etcd.
 */
public EtcdDiscoverer(URI uri) {
    this.myInstances = new HashSet<>();
    this.client = new EtcdClient(uri);

    // Do not retry too many times or wait too long
    this.client.setRetryHandler(new RetryOnce(1));

    // Log server version
    EtcdVersionResponse versionResponse = this.client.version();

    if (versionResponse != null) {
        logger.info("Discoverer connected with etcd at {}, server version {}", uri.toString(), versionResponse.getServer());
    } else {
        logger.warn("Discoverer started, but could not connect to etcd");
    }

    // Create discoverable config directory
    this.client.putDir(buildPath(DISCOVERABLE_CONFIG_DIR));
}
 
开发者ID:INAETICS,项目名称:Drones-Simulator,代码行数:24,代码来源:EtcdDiscoverer.java

示例2: processDel

import mousio.etcd4j.EtcdClient; //导入依赖的package包/类
private void processDel(EtcdClient client, String path, boolean dir, Exchange exchange) throws Exception {
    EtcdKeyDeleteRequest request = client.delete(path);
    setRequestTimeout(request, exchange);
    setRequestRecursive(request, exchange);

    if (dir) {
        request.dir();
    }

    try {
        exchange.getIn().setHeader(EtcdConstants.ETCD_NAMESPACE, getNamespace());
        exchange.getIn().setBody(request.send().get());
    } catch (TimeoutException e) {
        throw new ExchangeTimedOutException(exchange, configuration.getTimeout());
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:EtcdKeysProducer.java

示例3: createClient

import mousio.etcd4j.EtcdClient; //导入依赖的package包/类
public EtcdClient createClient() throws Exception {
    String[] uris;
    if (getUris() != null) {
        uris = getUris().split(",");
    } else {
        uris = EtcdConstants.ETCD_DEFAULT_URIS.split(",");
    }

    URI[] etcdUriList = new URI[uris.length];

    int i = 0;
    for (String uri : uris) {
        etcdUriList[i++] = URI.create(camelContext.resolvePropertyPlaceholders(uri));
    }

    return new EtcdClient(
        new EtcdSecurityContext(
            sslContextParameters != null
                ? sslContextParameters.createSSLContext(camelContext)
                : null,
            userName,
            password),
        etcdUriList
    );
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:EtcdConfiguration.java

示例4: testWatchRecovery

import mousio.etcd4j.EtcdClient; //导入依赖的package包/类
@Test
public void testWatchRecovery() throws Exception {
    final String key = "/myKeyRecovery";
    final EtcdClient client = getClient();

    try {
        // Delete the key if present
        client.delete(key).send().get();
    } catch (EtcdException e) {
        if (!e.isErrorCode(EtcdErrorCode.KeyNotFound)) {
            throw e;
        }
    }

    // Fill the vent backlog ( > 1000)
    for (int i = 0; i < 2000; i++) {
        client.put(key, "v" + i).send().get();
    }

    context().startRoute("watchRecovery");

    testWatch("mock:watch-recovery", key, 10);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:EtcdWatchTest.java

示例5: testWatch

import mousio.etcd4j.EtcdClient; //导入依赖的package包/类
private void testWatch(String mockEndpoint, final String key, int updates) throws Exception {
    final String[] values = new String[updates];
    for (int i = 0; i < updates; i++) {
        values[i] = key + "=myValue-" + i;
    }

    MockEndpoint mock = getMockEndpoint(mockEndpoint);
    mock.expectedMessageCount(2);
    mock.expectedHeaderReceived(EtcdConstants.ETCD_NAMESPACE, EtcdNamespace.watch.name());
    mock.expectedHeaderReceived(EtcdConstants.ETCD_PATH, key);
    mock.expectedBodiesReceived(values);

    final EtcdClient client = getClient();
    for (int i = 0; i < updates; i++) {
        client.put(key, "myValue-" + i).send().get();
    }

    mock.assertIsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:EtcdWatchTest.java

示例6: deregister

import mousio.etcd4j.EtcdClient; //导入依赖的package包/类
@Override
public void deregister() throws Exception {
	EtcdClient etcdClient = null;
	
	try {
		// create our client
		etcdClient = EtcdDiscoveryStrategy.getEtcdClient(etcdUris, etcdUsername, etcdPassword);
		
		// delete
		etcdClient.delete(this.myEtcdKey).send().get();
		
	} catch(Exception e) {
		String msg = "Unexpected error in etcdClient.delete(key:"+this.myEtcdKey+"): " + e.getMessage();
		logger.severe(msg,e);
		throw new Exception(msg,e);
		
	} finally {
		try { etcdClient.close(); } catch(Exception ignore){}
	}
}
 
开发者ID:bitsofinfo,项目名称:hazelcast-etcd-discovery-spi,代码行数:21,代码来源:BaseRegistrator.java

示例7: testCustomEtcdNettyClient

import mousio.etcd4j.EtcdClient; //导入依赖的package包/类
@Test
public void testCustomEtcdNettyClient() throws Exception {
  NioEventLoopGroup evl = new NioEventLoopGroup();
  EtcdNettyConfig config = new EtcdNettyConfig()
      .setConnectTimeout(100)
      .setSocketChannelClass(NioSocketChannel.class)
      .setMaxFrameSize(1024 * 1024)
      .setEventLoopGroup(evl)
      .setHostName("localhost");

  EtcdNettyClient client = new EtcdNettyClient(config, ETCD_URI);
  EtcdClient etcdClient = new EtcdClient(client);
  etcdClient.setRetryHandler(new RetryNTimes(0, 0));

  assertNotNull(etcdClient.version());
}
 
开发者ID:jurmous,项目名称:etcd4j,代码行数:17,代码来源:EtcdNettyClientTest.java

示例8: testSuccessWithoutRetrying

import mousio.etcd4j.EtcdClient; //导入依赖的package包/类
@Test
public void testSuccessWithoutRetrying() throws Exception {

    whenHttp(server)
            .match(get("/v2/keys/foo"))
            .then(SUCCESS);

    try (EtcdClient etcd = new EtcdClient(serverURI)) {

        EtcdResponsePromise<EtcdKeysResponse> promise = etcd.get("foo")
                .setRetryPolicy(new RetryNTimes(1, 10))
                .send();

        EtcdKeysResponse resp = promise.get();

        assertThat(resp.node.value).isEqualTo("bar");
        assertThat(promise.getException()).isNull();

    }

    verifyHttp(server).once(
            method(Method.GET),
            uri("/v2/keys/foo")
    );
}
 
开发者ID:jurmous,项目名称:etcd4j,代码行数:26,代码来源:EtcdClientRetryPolicyTest.java

示例9: testSuccessAfterRetrying

import mousio.etcd4j.EtcdClient; //导入依赖的package包/类
@Test
public void testSuccessAfterRetrying() throws Exception {

    whenHttp(server)
            .match(get("/v2/keys/foo"))
            .then(sequence(FAILURE, SUCCESS));

    try (EtcdClient etcd = new EtcdClient(serverURI)) {

        EtcdResponsePromise<EtcdKeysResponse> promise = etcd.get("foo")
                .setRetryPolicy(new RetryNTimes(1, 10))
                .send();

        EtcdKeysResponse resp = promise.get();

        assertThat(resp.node.value).isEqualTo("bar");
        assertThat(promise.getException()).isNull();

    }

    verifyHttp(server).times(2,
            method(Method.GET),
            uri("/v2/keys/foo")
    );
}
 
开发者ID:jurmous,项目名称:etcd4j,代码行数:26,代码来源:EtcdClientRetryPolicyTest.java

示例10: putFileInEtcd

import mousio.etcd4j.EtcdClient; //导入依赖的package包/类
private static void putFileInEtcd(String path, String content) {
    try(EtcdClient etcd = new EtcdClient(URI.create(getEtcdUrl()))){
        EtcdKeysResponse etcdKeysResponse = etcd.put(directory + path, content).send().get();
        String config = etcdKeysResponse.getNode().getValue();
        assertThat(config).isEqualTo(content);
    } catch (Exception e) {
        throw new RuntimeException("Unknown exception while fetching configuration from etcd", e);
    }
}
 
开发者ID:conf4j,项目名称:conf4j,代码行数:10,代码来源:EtcdFileConfigurationSourceTest.java

示例11: EtcdClientWrapper

import mousio.etcd4j.EtcdClient; //导入依赖的package包/类
public EtcdClientWrapper(EtcdClient etcd, String prefix) {
    this.etcd = etcd;
    this.prefix = prefix;
    //possibly we need to create better id ob bus
    this.bus = MessageBusImpl.builder(KvStorageEvent.class, (s) -> new ConditionalMessageBusWrapper<>(s, KvStorageEvent::getKey, KvUtils::predicate))
      .id(getClass().getName())
      .build();
    this.executor = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder()
      .setNameFormat(getClass().getName() + "-bus-%d")
      .setDaemon(true)
      .build());
    eventWhirligig(-1);
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:14,代码来源:EtcdClientWrapper.java

示例12: client

import mousio.etcd4j.EtcdClient; //导入依赖的package包/类
@Bean
public EtcdClientWrapper client() {
    List<URI> uris = new ArrayList<>();
    for (String etcdUrl : etcdUrls) {
        uris.add(URI.create(etcdUrl));
    }
    log.info("About to connect to etcd: {}", (Object)etcdUrls);
    EtcdClient etcd = new EtcdClient(uris.toArray(new URI[uris.size()]));
    return new EtcdClientWrapper(etcd, prefix.trim());
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:11,代码来源:EtcdConfiguration.java

示例13: init

import mousio.etcd4j.EtcdClient; //导入依赖的package包/类
/** Init performs the initial read of values from etcd. */
public void init(String flagzDirectory) throws FlagException, EtcdFlagFieldUpdaterException {
  this.directoryPrefix = MoreObjects.firstNonNull(flagzDirectory, directoryFlag.get());
  client = new EtcdClient(uris.toArray(new URI[uris.size()]));
  client.setRetryHandler(retryPolicy);
  initialSetAllFlagz();
}
 
开发者ID:mwitkow,项目名称:java-flagz,代码行数:8,代码来源:EtcdFlagFieldUpdater.java

示例14: connectEtcd

import mousio.etcd4j.EtcdClient; //导入依赖的package包/类
@BeforeClass
public static void connectEtcd() {
  try {
    client = new EtcdClient(URI.create(ETCD_SERVER));
    client.setRetryHandler(ETCD_RETRY);
    Long etcdIndex = client.getAll().send().get().etcdIndex;
    LOG.info("Connected to Etcd version={} at EtcdIndex({}).", client.version(), etcdIndex);
  } catch (Exception e) {
    throw new RuntimeException("Etc.d must be running on localhost for these tests.", e);
  }
}
 
开发者ID:mwitkow,项目名称:java-flagz,代码行数:12,代码来源:EtcdFlagFieldUpdaterTest.java

示例15: getStats

import mousio.etcd4j.EtcdClient; //导入依赖的package包/类
Object getStats(EtcdClient client) {
    switch (getPath()) {
    case EtcdConstants.ETCD_LEADER_STATS_PATH:
        return client.getLeaderStats();
    case EtcdConstants.ETCD_SELF_STATS_PATH:
        return client.getSelfStats();
    case EtcdConstants.ETCD_STORE_STATS_PATH:
        return client.getStoreStats();
    default:
        throw new IllegalStateException("No stats for " + getPath());
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:13,代码来源:EtcdStatsEndpoint.java


注:本文中的mousio.etcd4j.EtcdClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。