本文整理汇总了Java中com.netflix.curator.framework.CuratorFrameworkFactory类的典型用法代码示例。如果您正苦于以下问题:Java CuratorFrameworkFactory类的具体用法?Java CuratorFrameworkFactory怎么用?Java CuratorFrameworkFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CuratorFrameworkFactory类属于com.netflix.curator.framework包,在下文中一共展示了CuratorFrameworkFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ZkConnector
import com.netflix.curator.framework.CuratorFrameworkFactory; //导入依赖的package包/类
public ZkConnector(String zkConnect, int zkConnectionTimeoutMs,
int zkSessionTimeoutMs, int retryTimes, int sleepMsBetweenRetries) {
curator = CuratorFrameworkFactory.newClient(zkConnect,
zkSessionTimeoutMs, zkConnectionTimeoutMs, new RetryNTimes(
retryTimes, sleepMsBetweenRetries));
curator.start();
curator.getConnectionStateListenable().addListener(
createConnectionStateListener());
boolean success = false;
try {
success = curator.getZookeeperClient()
.blockUntilConnectedOrTimedOut();
} catch (InterruptedException e) {
}
if (!success)
throw new RuntimeException(
"Fail to establish zookeeper connection.");
else
LOGGER.log(Level.INFO, "Zookeeper connection is established.");
}
示例2: createZookeeperConnection
import com.netflix.curator.framework.CuratorFrameworkFactory; //导入依赖的package包/类
public static CuratorFramework createZookeeperConnection(String connectString,
int sessionTimeoutMs, int connectionTimeoutMs, ConnectionStateListener cnxnListener,
int retrycount, int retryWaitTime, long sessionId, byte[] sessionPwd) throws Exception {
RetryPolicy retryPolicy = new RetryNTimes(retrycount , retryWaitTime);
ZookeeperFactory factory = new ZooKeeperFactory(sessionId, sessionPwd);
CuratorFramework client = CuratorFrameworkFactory.builder().zookeeperFactory(factory)
.sessionTimeoutMs(sessionTimeoutMs)
.connectionTimeoutMs(connectionTimeoutMs)
.connectString(connectString).retryPolicy(retryPolicy).build();
client.getConnectionStateListenable().addListener(cnxnListener);
client.start();
return client;
}
示例3: createCurator
import com.netflix.curator.framework.CuratorFrameworkFactory; //导入依赖的package包/类
private void createCurator() {
String resolvablcnxnstr = findDNSResolvableZkHosts(m_config.getZkConnect());
m_curator = CuratorFrameworkFactory.newClient(
resolvablcnxnstr,
m_config.getZkSessionTimeoutMs(),
m_config.getZkConnectionTimeoutMs(),
new RetryNTimes(m_config.getRetryTimes(), m_config
.getSleepMsBetweenRetries()));
m_curator.getConnectionStateListenable().addListener(
createConnectionStateListener());
m_curator.start();
boolean success = false;
try {
success = m_curator.getZookeeperClient()
.blockUntilConnectedOrTimedOut();
} catch (InterruptedException e) {
}
if (!success)
throw new RuntimeException(
"Fail to establish zookeeper connection.");
else {
if (LOGGER.isInfoEnabled())
LOGGER.info(
"Zookeeper connection is established.");
}
}
示例4: newCurator
import com.netflix.curator.framework.CuratorFrameworkFactory; //导入依赖的package包/类
public static CuratorFramework newCurator(Map conf, List<String> servers, Object port, String root, ZookeeperAuthInfo auth) {
List<String> serverPorts = new ArrayList<String>();
for(String zkServer: (List<String>) servers) {
serverPorts.add(zkServer + ":" + Utils.getInt(port));
}
String zkStr = StringUtils.join(serverPorts, ",") + root;
try {
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder()
.connectString(zkStr)
.connectionTimeoutMs(Utils.getInt(conf.get(Config.STORM_ZOOKEEPER_CONNECTION_TIMEOUT)))
.sessionTimeoutMs(Utils.getInt(conf.get(Config.STORM_ZOOKEEPER_SESSION_TIMEOUT)))
.retryPolicy(new BoundedExponentialBackoffRetry(
Utils.getInt(conf.get(Config.STORM_ZOOKEEPER_RETRY_INTERVAL)),
Utils.getInt(conf.get(Config.STORM_ZOOKEEPER_RETRY_TIMES)),
Utils.getInt(conf.get(Config.STORM_ZOOKEEPER_RETRY_INTERVAL_CEILING))));
if(auth!=null && auth.scheme!=null) {
builder = builder.authorization(auth.scheme, auth.payload);
}
return builder.build();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例5: testClientCreation
import com.netflix.curator.framework.CuratorFrameworkFactory; //导入依赖的package包/类
@Test
public void testClientCreation() throws Exception {
TestingServer server = new TestingServer();
String namespace = "/sample";
ZooKeeperNetworkClient client = new ZooKeeperNetworkClient(server.getConnectString() + namespace);
CuratorFramework curator = CuratorFrameworkFactory
.builder()
.connectString(server.getConnectString())
.retryPolicy(new RetryOneTime(1))
.build();
curator.start();
Assert.assertNotNull(curator.checkExists().forPath(PathUtils.toPath(namespace, ZooKeeperNetworkClient.BASE_PATH)));
Assert.assertNotNull(curator.checkExists().forPath(PathUtils.toPath(namespace, ZooKeeperNetworkClient.NODE_STATES_PATH)));
Assert.assertNotNull(curator.checkExists().forPath(PathUtils.toPath(namespace, ZooKeeperNetworkClient.CLUSTER_PATH)));
curator.close();
client.close();
server.close();
}
示例6: ThriftDirectoryClient
import com.netflix.curator.framework.CuratorFrameworkFactory; //导入依赖的package包/类
public ThriftDirectoryClient(KeyStore keystore, Properties props) throws Exception {
// Extract Directory PSK
SIPHASH_PSK = SipHashInline.getKey(keystore.getKey(KeyStore.SIPHASH_DIRECTORY_PSK));
this.curatorFramework = CuratorFrameworkFactory.builder()
.connectionTimeoutMs(1000)
.retryPolicy(new RetryNTimes(10, 500))
.connectString(props.getProperty(Configuration.DIRECTORY_ZK_QUORUM))
.build();
this.curatorFramework.start();
if ("true".equals(props.getProperty(Configuration.DIRECTORY_STREAMING_NOPROXY))) {
this.noProxy = true;
} else {
this.noProxy = false;
}
ServiceDiscovery<Map> discovery = ServiceDiscoveryBuilder.builder(Map.class)
.basePath(props.getProperty(Configuration.DIRECTORY_ZK_ZNODE))
.client(curatorFramework)
.build();
discovery.start();
serviceCache = discovery.serviceCacheBuilder().name(Directory.DIRECTORY_SERVICE).build();
serviceCache.addListener(this);
serviceCache.start();
cacheChanged();
}
示例7: GeoDirectoryThriftClient
import com.netflix.curator.framework.CuratorFrameworkFactory; //导入依赖的package包/类
public GeoDirectoryThriftClient(KeyStore keystore, Properties props) throws Exception {
if (!props.containsKey(Configuration.GEODIR_ZK_SERVICE_QUORUM) || !props.containsKey(Configuration.GEODIR_ZK_SERVICE_ZNODE)) {
curatorFramework = null;
serviceCache = null;
return;
}
curatorFramework = CuratorFrameworkFactory.builder()
.connectionTimeoutMs(1000)
.retryPolicy(new RetryNTimes(10, 500))
.connectString(props.getProperty(Configuration.GEODIR_ZK_SERVICE_QUORUM))
.build();
curatorFramework.start();
ServiceDiscovery<Map> discovery = ServiceDiscoveryBuilder.builder(Map.class)
.basePath(props.getProperty(Configuration.GEODIR_ZK_SERVICE_ZNODE))
.client(curatorFramework)
.build();
discovery.start();
serviceCache = discovery.serviceCacheBuilder().name(GeoDirectory.GEODIR_SERVICE).build();
serviceCache.addListener(this);
serviceCache.start();
cacheChanged();
}
示例8: getCuratorClient
import com.netflix.curator.framework.CuratorFrameworkFactory; //导入依赖的package包/类
public synchronized CuratorFramework getCuratorClient() {
if (client == null) {
try {
String zkHostPort = ConfigPropertieUtil.getInstance().getString("curator.lock.zk.connect");
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
client = CuratorFrameworkFactory.newClient(zkHostPort, retryPolicy);
client.start();
} catch (Exception e) {
LOGGER.error("Get curatorClient error.", e);
}
}
return client;
}
示例9: createWithOptions
import com.netflix.curator.framework.CuratorFrameworkFactory; //导入依赖的package包/类
private CuratorFramework createWithOptions(String connectionString,
RetryPolicy retryPolicy, int connectionTimeoutMs,
int sessionTimeoutMs) throws IOException {
return CuratorFrameworkFactory.builder()
.connectString(connectionString).retryPolicy(retryPolicy)
.connectionTimeoutMs(connectionTimeoutMs)
.sessionTimeoutMs(sessionTimeoutMs).build();
}
示例10: main
import com.netflix.curator.framework.CuratorFrameworkFactory; //导入依赖的package包/类
public static void main(String[] args) {
RetryPolicy policy = new RetryNTimes(1, 100);
CuratorFramework zkClient = CuratorFrameworkFactory.newClient("localhost:2181", 3000, 3000, policy);
zkClient.start();
IdGenerator zkGen = ZKGenerator.newBuilder(zkClient).setCounterName("mark_test").setMaxIdsToFetch(1000)
.setRootPath("/id_gen").build();
runGenerator(zkGen);
Jedis redisClient = new Jedis("localhost");;
IdGenerator redisGen = RedisGenerator.newBuilder(redisClient).setCounterName("alex_test").setMaxIdsToFetch(1000).build();
runGenerator(redisGen);
}
示例11: newCurator
import com.netflix.curator.framework.CuratorFrameworkFactory; //导入依赖的package包/类
private CuratorFramework newCurator(Map stateConf) throws Exception {
Integer port = (Integer) stateConf.get(Config.TRANSACTIONAL_ZOOKEEPER_PORT);
String serverPorts = "";
for (String server : (List<String>) stateConf.get(Config.TRANSACTIONAL_ZOOKEEPER_SERVERS)) {
serverPorts = serverPorts + server + ":" + port + ",";
}
return CuratorFrameworkFactory.newClient(serverPorts,
Utils.getInt(stateConf.get(Config.STORM_ZOOKEEPER_SESSION_TIMEOUT)),
15000,
new RetryNTimes(Utils.getInt(stateConf.get(Config.STORM_ZOOKEEPER_RETRY_TIMES)),
Utils.getInt(stateConf.get(Config.STORM_ZOOKEEPER_RETRY_INTERVAL))));
}
示例12: DynamicBrokersReader
import com.netflix.curator.framework.CuratorFrameworkFactory; //导入依赖的package包/类
public DynamicBrokersReader(Map conf, String zkStr, String zkPath, String topic) {
_zkPath = zkPath;
_topic = topic;
try {
_curator = CuratorFrameworkFactory.newClient(
zkStr,
Utils.getInt(conf.get(Config.STORM_ZOOKEEPER_SESSION_TIMEOUT)),
15000,
new RetryNTimes(Utils.getInt(conf.get(Config.STORM_ZOOKEEPER_RETRY_TIMES)),
Utils.getInt(conf.get(Config.STORM_ZOOKEEPER_RETRY_INTERVAL))));
_curator.start();
} catch (Exception ex) {
LOG.error("can't connect to zookeeper");
}
}
示例13: setUp
import com.netflix.curator.framework.CuratorFrameworkFactory; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
server = new TestingServer();
String connectionString = server.getConnectString();
Map conf = new HashMap();
conf.put(Config.STORM_ZOOKEEPER_SESSION_TIMEOUT, 1000);
conf.put(Config.STORM_ZOOKEEPER_RETRY_TIMES, 4);
conf.put(Config.STORM_ZOOKEEPER_RETRY_INTERVAL, 5);
ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(1000, 3);
zookeeper = CuratorFrameworkFactory.newClient(connectionString, retryPolicy);
dynamicBrokersReader = new DynamicBrokersReader(conf, connectionString, masterPath, topic);
zookeeper.start();
}
示例14: connect
import com.netflix.curator.framework.CuratorFrameworkFactory; //导入依赖的package包/类
void connect(String zk, String broker, int port)
{
try {
consumer = new SimpleConsumer(broker, port, 1000, 1024*1024*10);
curator = CuratorFrameworkFactory.newClient(zk, 1000, 15000, new RetryNTimes(5, 2000));
curator.start();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例15: setUp
import com.netflix.curator.framework.CuratorFrameworkFactory; //导入依赖的package包/类
@BeforeMethod
public void setUp() throws Exception {
testingServer = new TestingServer();
component = new TestingComponent(null);
Item testBatch = new Item(BATCHID);
Event testEvent = new Event();
testEvent.setEventID("Data_Received");
testEvent.setSuccess(true);
testEvent.setDate(new Date());
testEvent.setDetails("");
testBatch.setEventList(new ArrayList<>(Arrays.asList(testEvent)));
component.setItems(new ArrayList<>(Arrays.asList(testBatch)));
lockClient = CuratorFrameworkFactory.newClient(
testingServer.getConnectString(), new ExponentialBackoffRetry(1000, 3));
lockClient.start();
autonoumous = new AutonomousComponent<>(component,
lockClient,
1,
1,
Arrays.asList("Data_Received"), null, null, null,
DEFAULT_TIMEOUT,
DEFAULT_TIMEOUT,
DEFAULT_TIMEOUT,
100,
component.getEventTrigger(),
component.getEventStorer());
}
开发者ID:statsbiblioteket,项目名称:newspaper-batch-event-framework,代码行数:34,代码来源:AutonomousComponentTest.java