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


Java RetryNTimes类代码示例

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


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

示例1: testServer

import org.apache.curator.retry.RetryNTimes; //导入依赖的package包/类
public void testServer(){
        try {
        TestingServer server=new TestingServer(2181,new File("/"));
        server.start();

        CuratorFramework curatorFramework = CuratorFrameworkFactory.
                builder().
                connectString(server.getConnectString()).
                sessionTimeoutMs(1000).
                retryPolicy(new RetryNTimes(3, 1000)).
                build();
        curatorFramework.start();
        System.out.println(curatorFramework.getChildren().forPath("/"));
        curatorFramework.close();
        server.stop();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
 
开发者ID:mumudemo,项目名称:mumu-zookeeper,代码行数:21,代码来源:CuratorServer.java

示例2: ZkService

import org.apache.curator.retry.RetryNTimes; //导入依赖的package包/类
/**
 * 创建ZK连接
 * @param connectString  ZK服务器地址列表
 * @param sessionTimeout   Session超时时间
 */
public ZkService(String connectString, int sessionTimeout) throws Exception {
    CuratorFrameworkFactory.Builder builder;
    builder = CuratorFrameworkFactory.builder()
            .connectString(connectString)
            .namespace("")
            .authorization("digest", auth.getBytes())
            .retryPolicy(new RetryNTimes(Integer.MAX_VALUE, 1000))
            .connectionTimeoutMs(sessionTimeout);

    client = builder.build();
    client.start();
    if(!client.blockUntilConnected(20, TimeUnit.SECONDS)) {
        throw new Exception("zookeeper connected failed!");
    }

    tableVersions = new HashMap<>();
    cache = new HashMap<>();
}
 
开发者ID:BriData,项目名称:DBus,代码行数:24,代码来源:ZkService.java

示例3: verifyZkStore

import org.apache.curator.retry.RetryNTimes; //导入依赖的package包/类
@Test
public void verifyZkStore() throws Exception {
  DrillConfig config = getConfig();
  String connect = config.getString(ExecConstants.ZK_CONNECTION);
  CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder()
  .namespace(config.getString(ExecConstants.ZK_ROOT))
  .retryPolicy(new RetryNTimes(1, 100))
  .connectionTimeoutMs(config.getInt(ExecConstants.ZK_TIMEOUT))
  .connectString(connect);

  try(CuratorFramework curator = builder.build()){
    curator.start();
    ZkPStoreProvider provider = new ZkPStoreProvider(config, curator);
    PStoreTestUtil.test(provider);
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:17,代码来源:TestPStoreProviders.java

示例4: createConnector

import org.apache.curator.retry.RetryNTimes; //导入依赖的package包/类
private void createConnector() {
    CuratorFramework curator = CuratorFrameworkFactory.builder()
            .connectionTimeoutMs(specificConfig.getConnectionTimeoutMs())
            .retryPolicy(new RetryNTimes(specificConfig.getRetryCount(), specificConfig.getSleepsBetweenRetryMs()))
            .connectString(specificConfig.getConnectionUrl())
            .compressionProvider(new GzipCompressionCustomProvider())
            .build();
    
    setClient(curator);
    setBasePath(specificConfig.getZookeeperBasePath());
    setCacheHosts(specificConfig.isCacheHosts());
    setStacksCacheFactory(() -> new ZKStacksCache(curator, this, new ServiceDiscoveryHostJsonSerializer(),
            specificConfig.isCacheHosts(), specificConfig.getZookeeperBasePath()));
    
    setNodeCacheFactory(new ZkNodeCacheFactory(this, curator));
    setPathChildrenCacheFactory(new ZkPathChildrenCacheFactory(this, curator));
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:18,代码来源:Connector.java

示例5: curatorFramework

import org.apache.curator.retry.RetryNTimes; //导入依赖的package包/类
@Bean
public CuratorFramework curatorFramework() {
    ZKConfig config = config();

    if (config.useZooKeeperWaitTimePolicy()) {
        return new RedirectorCuratorFramework(config);
    }

    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder()
            .connectString(config.getZooKeeperConnection())
            .connectionTimeoutMs(config.getZooKeeperConnectionTimeout())
            .sessionTimeoutMs(config.getZooKeeperSessionTimeout())
            .retryPolicy(new RetryNTimes(config.getZooKeeperRetryAttempts(), config.getZooKeeperRetryInterval()))
            .compressionProvider(new GzipCompressionProvider());

    return builder.build();
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:18,代码来源:AbstractCommonBeans.java

示例6: createConnection

import org.apache.curator.retry.RetryNTimes; //导入依赖的package包/类
private void createConnection() throws Exception {
  // Curator connection
  CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
  builder = builder.connectString(zkHostPort)
      .connectionTimeoutMs(zkSessionTimeout)
      .retryPolicy(new RetryNTimes(numRetries, zkRetryInterval));

  // Set up authorization based on fencing scheme
  List<AuthInfo> authInfos = new ArrayList<>();
  for (ZKUtil.ZKAuthInfo zkAuth : zkAuths) {
    authInfos.add(new AuthInfo(zkAuth.getScheme(), zkAuth.getAuth()));
  }
  if (useDefaultFencingScheme) {
    byte[] defaultFencingAuth =
        (zkRootNodeUsername + ":" + zkRootNodePassword).getBytes(
            Charset.forName("UTF-8"));
    authInfos.add(new AuthInfo(zkRootNodeAuthScheme, defaultFencingAuth));
  }
  builder = builder.authorization(authInfos);

  // Connect to ZK
  curatorFramework = builder.build();
  curatorFramework.start();
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:25,代码来源:ZKRMStateStore.java

示例7: getGeolocationServiceProvider

import org.apache.curator.retry.RetryNTimes; //导入依赖的package包/类
private static ServiceProvider<Object> getGeolocationServiceProvider() throws Exception {
	if(geolocationServiceProvider == null) {
		CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient("192.168.99.100:2181", new RetryNTimes(5, 1000));
		curatorFramework.start();

		ServiceDiscovery<Object> serviceDiscovery = ServiceDiscoveryBuilder.builder(Object.class)
				.basePath("com.packt.microservices")
				.client(curatorFramework)
				.build();
		serviceDiscovery.start();

		geolocationServiceProvider = serviceDiscovery.serviceProviderBuilder()
				.serviceName("geolocation")
				.build();
		geolocationServiceProvider.start();
	}
	return geolocationServiceProvider;
}
 
开发者ID:PacktPublishing,项目名称:Microservices-Deployment-Cookbook,代码行数:19,代码来源:ZookeeperServiceDiscovery.java

示例8: CuratorZookeeperClient

import org.apache.curator.retry.RetryNTimes; //导入依赖的package包/类
public CuratorZookeeperClient(URL url) {
    super(url);
    try {
        Builder builder = CuratorFrameworkFactory.builder()
                .connectString(url.getBackupAddress())
                .retryPolicy(new RetryNTimes(Integer.MAX_VALUE, 1000))
                .connectionTimeoutMs(5000);
        String authority = url.getAuthority();
        if (authority != null && authority.length() > 0) {
            builder = builder.authorization("digest", authority.getBytes());
        }
        client = builder.build();
        client.getConnectionStateListenable().addListener((client, state) -> {
            if (state == ConnectionState.LOST) {
                CuratorZookeeperClient.this.stateChanged(StateListener.DISCONNECTED);
            } else if (state == ConnectionState.CONNECTED) {
                CuratorZookeeperClient.this.stateChanged(StateListener.CONNECTED);
            } else if (state == ConnectionState.RECONNECTED) {
                CuratorZookeeperClient.this.stateChanged(StateListener.RECONNECTED);
            }
        });
        client.start();
    } catch (Exception e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
 
开发者ID:linux-china,项目名称:dubbo3,代码行数:27,代码来源:CuratorZookeeperClient.java

示例9: ServiceRegistry

import org.apache.curator.retry.RetryNTimes; //导入依赖的package包/类
/**
 * <p>Retrieves the Zookeeper service URI from the environemnt and initiates the client.</p>
 */
@Inject
public ServiceRegistry() {

    try {
        String zookeeperUri = System.getenv("ZOOKEEPER_URI");

        zookeeper = CuratorFrameworkFactory.newClient(zookeeperUri, new RetryNTimes(5, 1000));

        zookeeper.start();

        zonePaths = new ConcurrentHashMap<>();
    } catch (Exception ex) {
        throw new RuntimeException(ex.getLocalizedMessage());
    }
}
 
开发者ID:TFaga,项目名称:kumuluzee-examples,代码行数:19,代码来源:ServiceRegistry.java

示例10: setup

import org.apache.curator.retry.RetryNTimes; //导入依赖的package包/类
@BeforeClass
public static void setup() throws Exception {
  // start the zk server
  startZKServer();
  
  HostAndPort hostAndPort1 = HostAndPort.fromString("localhost:"+PORT);
  ArrayList<HostAndPort> list = new ArrayList<HostAndPort>();
  list.add(hostAndPort1);
  identifier = new ServerIdentifier(rootZnode, list);
  serviceRegistry = ServiceRegistryProvider.provider().getRegistryFactory().getServiceRegistry(identifier);
  serviceRegistry.start();
  
  // 1.Connect to zk
  client =
      CuratorFrameworkFactory.newClient(identifier.getConnectionString(), new RetryNTimes(10,
          5000));
  client.start();  
  
  entry = new RegisterEntry();
  HostMetadata metadata = new HostMetadata("localhost", 4443, zone, true);
  entry.setServiceName(targetService.getAuthority());     
  entry.setDescription(targetService.getAuthority());
  entry.setLastUpdated(Calendar.getInstance().getTime());
  entry.setHostMetadata(metadata);
  
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:27,代码来源:ZkNameResolverTest.java

示例11: setup

import org.apache.curator.retry.RetryNTimes; //导入依赖的package包/类
@BeforeClass
public static void setup() throws Exception {
  // start the zk server
  startZKServer();

  HostAndPort hostAndPort1 = HostAndPort.fromString("localhost:" + PORT);
  ArrayList<HostAndPort> list = new ArrayList<HostAndPort>();
  list.add(hostAndPort1);
  identifier = new ServerIdentifier(rootZnode, list);
  serviceRegistry =
      ServiceRegistryProvider.provider().getRegistryFactory().getServiceRegistry(identifier);
  serviceRegistry.start();

  client =
      CuratorFrameworkFactory.newClient(identifier.getConnectionString(), new RetryNTimes(10,
          5000));
  client.start();

  entry = new RegisterEntry();
  HostMetadata metadata = new HostMetadata("localhost", 4442, zone, true);
  entry.setServiceName(targetService.getAuthority());
  entry.setDescription(targetService.getAuthority());
  entry.setLastUpdated(Calendar.getInstance().getTime());
  entry.setHostMetadata(metadata);

}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:27,代码来源:ServiceRegistryTest.java

示例12: setUp

import org.apache.curator.retry.RetryNTimes; //导入依赖的package包/类
@BeforeMethod
public void setUp() throws Exception {
    LifeCycleRegistry lifeCycleRegistry = mock(LifeCycleRegistry.class);
    _queueService = mock(QueueService.class);
    _jobHandlerRegistry = new DefaultJobHandlerRegistry();
    _jobStatusDAO = new InMemoryJobStatusDAO();
    _testingServer = new TestingServer();
    _curator = CuratorFrameworkFactory.builder()
            .connectString(_testingServer.getConnectString())
            .retryPolicy(new RetryNTimes(3, 100))
            .build();

    _curator.start();

    _service = new DefaultJobService(
            lifeCycleRegistry, _queueService, "testqueue", _jobHandlerRegistry, _jobStatusDAO, _curator,
            1, Duration.ZERO, 100, Duration.standardHours(1));

    _store = new InMemoryDataStore(new MetricRegistry());
    _dataStoreResource = new DataStoreResource1(_store, new DefaultDataStoreAsync(_store, _service, _jobHandlerRegistry));

}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:23,代码来源:PurgeTest.java

示例13: setUp

import org.apache.curator.retry.RetryNTimes; //导入依赖的package包/类
@BeforeMethod
public void setUp() throws Exception {
    LifeCycleRegistry lifeCycleRegistry = mock(LifeCycleRegistry.class);
    _queueService = mock(QueueService.class);
    _jobHandlerRegistry = new DefaultJobHandlerRegistry();
    _jobStatusDAO = new InMemoryJobStatusDAO();
    _testingServer = new TestingServer();
    _curator = CuratorFrameworkFactory.builder()
            .connectString(_testingServer.getConnectString())
            .retryPolicy(new RetryNTimes(3, 100))
            .build();

    _curator.start();

    _service = new DefaultJobService(
            lifeCycleRegistry, _queueService, "testqueue", _jobHandlerRegistry, _jobStatusDAO, _curator,
            1, Duration.ZERO, 100, Duration.standardHours(1));
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:19,代码来源:TestDefaultJobService.java

示例14: connectToZk

import org.apache.curator.retry.RetryNTimes; //导入依赖的package包/类
private CuratorFramework connectToZk(String connectString) throws InterruptedException {
	Builder builder = CuratorFrameworkFactory.builder();

	builder.connectionTimeoutMs(3000);
	builder.connectString(connectString);
	builder.maxCloseWaitMs(3000);
	builder.namespace("xpipe");
	builder.retryPolicy(new RetryNTimes(3, 1000));
	builder.sessionTimeoutMs(5000);

	CuratorFramework client = builder.build();
	client.start();
	client.blockUntilConnected();

	return client;
}
 
开发者ID:ctripcorp,项目名称:x-pipe,代码行数:17,代码来源:MetaServerPrepareResourcesAndStart.java

示例15: create

import org.apache.curator.retry.RetryNTimes; //导入依赖的package包/类
@Override
public CuratorFramework create(String address) throws InterruptedException {

	Builder builder = CuratorFrameworkFactory.builder();
	builder.connectionTimeoutMs(getZkConnectionTimeoutMillis());
	builder.connectString(address);
	builder.maxCloseWaitMs(getZkCloseWaitMillis());
	builder.namespace(getZkNamespace());
	builder.retryPolicy(new RetryNTimes(getZkRetries(), getSleepMsBetweenRetries()));
	builder.sessionTimeoutMs(getZkSessionTimeoutMillis());
	builder.threadFactory(XpipeThreadFactory.create("Xpipe-ZK-" + address, true));

	logger.info("[create]{}, {}", Codec.DEFAULT.encode(this), address);
	CuratorFramework curatorFramework = builder.build();
	curatorFramework.start();
	curatorFramework.blockUntilConnected(waitForZkConnectedMillis(), TimeUnit.MILLISECONDS);
	
	return curatorFramework;
}
 
开发者ID:ctripcorp,项目名称:x-pipe,代码行数:20,代码来源:DefaultZkConfig.java


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