本文整理汇总了Java中org.apache.curator.framework.state.ConnectionState.SUSPENDED属性的典型用法代码示例。如果您正苦于以下问题:Java ConnectionState.SUSPENDED属性的具体用法?Java ConnectionState.SUSPENDED怎么用?Java ConnectionState.SUSPENDED使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.curator.framework.state.ConnectionState
的用法示例。
在下文中一共展示了ConnectionState.SUSPENDED属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: stateChanged
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
mIsLeader.set(false);
if ((newState == ConnectionState.LOST) || (newState == ConnectionState.SUSPENDED)) {
if (mCurrentMasterThread != null) {
mCurrentMasterThread.interrupt();
}
} else {
try {
LOG.info("The current leader is " + LEADER_SELECTOR.getLeader().getId());
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
}
}
示例2: stateChanged
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
if (newState == ConnectionState.SUSPENDED || newState == ConnectionState.LOST) {
this.isLeader = false;
leaderExecutor.shutdownNow();
throw new CancelLeadershipException();
}
}
示例3: stateChanged
@Override
public void stateChanged(CuratorFramework framework, ConnectionState newState) {
if (newState == ConnectionState.SUSPENDED || newState == ConnectionState.LOST) {
this.isLeader = false;
leaderExecutor.shutdownNow();
throw new CancelLeadershipException();
}
}
示例4: KafkaConsumerCache
/**
* Creates a KafkaConsumerCache object. Before it is used, you must call
* startCache()
*
* @param apiId
* @param s
* @param metrics
*/
public KafkaConsumerCache(String apiId, MetricsSet metrics) {
if (apiId == null) {
throw new IllegalArgumentException("API Node ID must be specified.");
}
fApiId = apiId;
// fSettings = s;
fMetrics = metrics;
String strkSetting_ZkBasePath= AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop,kSetting_ZkBasePath);
if(null==strkSetting_ZkBasePath)strkSetting_ZkBasePath = kDefault_ZkBasePath;
fBaseZkPath = strkSetting_ZkBasePath;
fConsumers = new ConcurrentHashMap<String, KafkaConsumer>();
fSweepScheduler = Executors.newScheduledThreadPool(1);
curatorConsumerCache = null;
status = Status.NOT_STARTED;
listener = new ConnectionStateListener() {
public void stateChanged(CuratorFramework client, ConnectionState newState) {
if (newState == ConnectionState.LOST) {
log.info("ZooKeeper connection expired");
handleConnectionLoss();
} else if (newState == ConnectionState.READ_ONLY) {
log.warn("ZooKeeper connection set to read only mode.");
} else if (newState == ConnectionState.RECONNECTED) {
log.info("ZooKeeper connection re-established");
handleReconnection();
} else if (newState == ConnectionState.SUSPENDED) {
log.warn("ZooKeeper connection has been suspended.");
handleConnectionSuspended();
}
}
};
}
示例5: stateChanged
@Override
public void stateChanged(final CuratorFramework client, final ConnectionState state) {
if (state == ConnectionState.LOST || state == ConnectionState.SUSPENDED) {
log.warn("connection state changed, now");
isStop.set(true);
}
}
示例6: stateChanged
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
if ((newState == ConnectionState.SUSPENDED) || (newState == ConnectionState.LOST)) {
try {
shutdown();
} catch (SchedulerException e) {
throw new RuntimeException("failed to shutdown scheduler", e);
}
}
}
示例7: stateChanged
@Override
public void stateChanged(CuratorFramework curatorFramework, ConnectionState newState)
{
if ( (newState == ConnectionState.LOST) || (newState == ConnectionState.SUSPENDED) )
{
if ( ourThread != null )
{
ourThread.interrupt();
}
}
}
示例8: stateChanged
@Override
public void stateChanged(CuratorFramework curatorFramework, ConnectionState newState) {
if (newState == ConnectionState.LOST || newState == ConnectionState.SUSPENDED) {
LOG.debug("Lost leadership due to ZK state change to {}: {}", newState, getId());
closeLeaderLatch();
}
}
示例9: stateChanged
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
if (newState == ConnectionState.SUSPENDED || newState == ConnectionState.LOST) {
lastState = newState;
}
}
示例10: testDisconnectReconnectWithMultipleClients
@Test
public void testDisconnectReconnectWithMultipleClients() throws Exception
{
Timing timing = new Timing();
CuratorFramework curatorFramework1 = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryNTimes(10, 500));
CuratorFramework curatorFramework2 = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryNTimes(10, 500));
curatorFramework1.start();
curatorFramework1.checkExists().forPath("/"); // clear initial connect events
curatorFramework2.start();
curatorFramework2.checkExists().forPath("/"); // clear initial connect events
final String sharedCountPath = "/count";
final int initialCount = 10;
SharedCount sharedCount1 = new SharedCount(curatorFramework1, sharedCountPath, initialCount);
SharedCount sharedCountWithFaultyWatcher = createSharedCountWithFaultyWatcher(curatorFramework2, sharedCountPath, initialCount);
class MySharedCountListener implements SharedCountListener
{
final public Phaser gotSuspendEvent = new Phaser(1);
final public Phaser gotChangeEvent = new Phaser(1);
final public Phaser getReconnectEvent = new Phaser(1);
final public AtomicInteger numChangeEvents = new AtomicInteger(0);
@Override
public void countHasChanged(SharedCountReader sharedCount, int newCount) throws Exception
{
numChangeEvents.incrementAndGet();
gotChangeEvent.arrive();
}
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState)
{
if (newState == ConnectionState.SUSPENDED) {
gotSuspendEvent.arrive();
} else if (newState == ConnectionState.RECONNECTED) {
getReconnectEvent.arrive();
}
}
}
MySharedCountListener listener1 = new MySharedCountListener();
sharedCount1.addListener(listener1);
sharedCount1.start();
MySharedCountListener listener2 = new MySharedCountListener();
sharedCountWithFaultyWatcher.addListener(listener2);
try
{
sharedCount1.setCount(12);
Assert.assertEquals(listener1.gotChangeEvent.awaitAdvanceInterruptibly(0, timing.seconds(), TimeUnit.SECONDS), 1);
Assert.assertEquals(sharedCount1.getCount(), 12);
Assert.assertEquals(sharedCountWithFaultyWatcher.getCount(), 10);
// new counter with faultyWatcher start
sharedCountWithFaultyWatcher.start();
for (int i = 0; i < 10; i++) {
sharedCount1.setCount(13 + i);
Assert.assertEquals(sharedCount1.getCount(), 13 + i);
server.restart();
Assert.assertEquals(listener2.getReconnectEvent.awaitAdvanceInterruptibly(i, timing.forWaiting().seconds(), TimeUnit.SECONDS), i + 1);
// CURATOR-311 introduces to Curator's client reading server's shared count value
// when client's state gets ConnectionState.RECONNECTED. Following tests ensures that.
Assert.assertEquals(listener2.gotChangeEvent.awaitAdvanceInterruptibly(i, timing.forWaiting().seconds(), TimeUnit.SECONDS), i + 1);
Assert.assertEquals(sharedCountWithFaultyWatcher.getCount(), 13 + i);
}
}
finally
{
CloseableUtils.closeQuietly(sharedCount1);
CloseableUtils.closeQuietly(curatorFramework1);
CloseableUtils.closeQuietly(sharedCountWithFaultyWatcher);
CloseableUtils.closeQuietly(curatorFramework2);
}
}