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


Java ConnectionState.SUSPENDED属性代码示例

本文整理汇总了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);
    }
  }
}
 
开发者ID:mtunique,项目名称:tachyon-rdma,代码行数:16,代码来源:LeaderSelectorClient.java

示例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();
    }
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:8,代码来源:DistributedSequenceHandler.java

示例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();
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:8,代码来源:DistributedSequenceHandler.java

示例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();
			}
		}
	};
}
 
开发者ID:att,项目名称:dmaap-framework,代码行数:45,代码来源:KafkaConsumerCache.java

示例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);
  }
}
 
开发者ID:Yirendai,项目名称:cicada,代码行数:7,代码来源:ClusterLeaderManager.java

示例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);
        }
    }
}
 
开发者ID:apache,项目名称:kylin,代码行数:10,代码来源:DistributedScheduler.java

示例7: stateChanged

@Override
public void stateChanged(CuratorFramework curatorFramework, ConnectionState newState)
{
    if ( (newState == ConnectionState.LOST) || (newState == ConnectionState.SUSPENDED) )
    {
        if ( ourThread != null )
        {
            ourThread.interrupt();
        }
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:11,代码来源:TestLeaderSelectorWithExecutor.java

示例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();
    }
}
 
开发者ID:bazaarvoice,项目名称:curator-extensions,代码行数:7,代码来源:LeaderService.java

示例9: stateChanged

@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
	if (newState == ConnectionState.SUSPENDED || newState == ConnectionState.LOST) {
		lastState = newState;
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:6,代码来源:ZooKeeperCheckpointIDCounter.java

示例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);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:79,代码来源:TestSharedCount.java


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