本文整理汇总了Java中org.apache.curator.framework.recipes.leader.LeaderLatch.close方法的典型用法代码示例。如果您正苦于以下问题:Java LeaderLatch.close方法的具体用法?Java LeaderLatch.close怎么用?Java LeaderLatch.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.curator.framework.recipes.leader.LeaderLatch
的用法示例。
在下文中一共展示了LeaderLatch.close方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: releaseControl
import org.apache.curator.framework.recipes.leader.LeaderLatch; //导入方法依赖的package包/类
@Override
public void releaseControl(long dpid) {
log.info("Releasing control for {}", HexString.toHexString(dpid));
String dpidStr = HexString.toHexString(dpid);
SwitchLeadershipData swData = switches.remove(dpidStr);
if (swData == null) {
log.debug("Trying to release control of a switch we are not contesting");
return;
}
LeaderLatch latch = swData.getLatch();
latch.removeListener(swData.getListener());
try {
latch.close();
} catch (IOException e) {
// I think it's OK not to do anything here. Either the node got
// deleted correctly, or the connection went down and the node got deleted.
log.debug("releaseControl: caught IOException {}", dpidStr);
}
}
示例2: testReleaseControl
import org.apache.curator.framework.recipes.leader.LeaderLatch; //导入方法依赖的package包/类
/**
* Test if {@link ZookeeperRegistry#releaseControl(long)} correctly release control of specific switch.
* Because {@link ZookeeperRegistry#releaseControl(long)} doesn't return values, inject mock
* {@link LeaderLatch} object and verify latch is correctly set up.
*
* @throws Exception
*/
@Test
public void testReleaseControl() throws Exception {
// Mock of LeaderLatch
LeaderLatch latch = createMock(LeaderLatch.class);
latch.addListener(anyObject(SwitchLeaderListener.class));
expectLastCall().once();
latch.start();
expectLastCall().once();
latch.removeListener(anyObject(SwitchLeaderListener.class));
expectLastCall().once();
latch.close();
expectLastCall().once();
replay(latch);
PowerMock.expectNew(LeaderLatch.class,
anyObject(CuratorFramework.class),
anyObject(String.class),
anyObject(String.class))
.andReturn(latch).once();
PowerMock.replay(LeaderLatch.class);
String controllerId = "controller2013";
registry.registerController(controllerId);
long dpidToRequest = 2000L;
LoggingCallback callback = new LoggingCallback(1);
registry.requestControl(dpidToRequest, callback);
registry.releaseControl(dpidToRequest);
verify(latch);
}
示例3: closeLeaderLatch
import org.apache.curator.framework.recipes.leader.LeaderLatch; //导入方法依赖的package包/类
private synchronized void closeLeaderLatch() {
LeaderLatch latch = _latch; // Read the volatile once
if (latch.getState() == LeaderLatch.State.STARTED) {
try {
latch.close();
} catch (IOException e) {
LOG.debug("Unexpected exception closing LeaderLatch.", e);
}
}
// Return the latch to a latent state (newly created) for use by getLeader(), getParticipants() & friends.
_latch = newLeaderLatch();
// Wake up the main execution thread.
notifyAll();
}
示例4: testHasControl
import org.apache.curator.framework.recipes.leader.LeaderLatch; //导入方法依赖的package包/类
/**
* Test if {@link ZookeeperRegistry#hasControl(long)} returns
* correct status whether controller has control of specific switch.
*
* @throws Exception
*/
@Test
public void testHasControl() throws Exception {
// Mock of LeaderLatch
LeaderLatch latch = createMock(LeaderLatch.class);
latch.addListener(anyObject(SwitchLeaderListener.class));
expectLastCall().once();
latch.start();
expectLastCall().once();
expect(latch.hasLeadership()).andReturn(true).anyTimes();
latch.removeListener(anyObject(SwitchLeaderListener.class));
expectLastCall().once();
latch.close();
expectLastCall().once();
replay(latch);
PowerMock.expectNew(LeaderLatch.class,
anyObject(CuratorFramework.class),
anyObject(String.class),
anyObject(String.class))
.andReturn(latch);
PowerMock.replay(LeaderLatch.class);
String controllerId = "controller2013";
registry.registerController(controllerId);
long dpidToRequest = 2000L;
LoggingCallback callback = new LoggingCallback(2);
// Test before request control
assertFalse(registry.hasControl(dpidToRequest));
registry.requestControl(dpidToRequest, callback);
// Test after request control
assertTrue(registry.hasControl(dpidToRequest));
registry.releaseControl(dpidToRequest);
// Test after release control
assertFalse(registry.hasControl(dpidToRequest));
verify(latch);
}