本文整理汇总了Java中io.atomix.catalyst.concurrent.Listener.close方法的典型用法代码示例。如果您正苦于以下问题:Java Listener.close方法的具体用法?Java Listener.close怎么用?Java Listener.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.atomix.catalyst.concurrent.Listener
的用法示例。
在下文中一共展示了Listener.close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSessionStateChange
import io.atomix.catalyst.concurrent.Listener; //导入方法依赖的package包/类
/**
* Tests session state change callbacks.
*/
public void testSessionStateChange() {
ClientSessionState state = new ClientSessionState(UUID.randomUUID().toString());
AtomicBoolean changed = new AtomicBoolean();
AtomicReference<Session.State> change = new AtomicReference<>();
Listener<Session.State> listener = state.onStateChange(s -> {
changed.set(true);
change.set(s);
});
assertEquals(state.getState(), Session.State.CLOSED);
state.setState(Session.State.CLOSED);
assertFalse(changed.get());
state.setState(Session.State.OPEN);
assertTrue(changed.get());
assertEquals(change.get(), Session.State.OPEN);
changed.set(false);
listener.close();
state.setState(Session.State.EXPIRED);
assertFalse(changed.get());
}
示例2: testStateTransitionWithRecovery
import io.atomix.catalyst.concurrent.Listener; //导入方法依赖的package包/类
/**
* Tests state transition with recovery
*/
public void testStateTransitionWithRecovery() throws Throwable {
createServers(3);
final CopycatClient client = createClient(RecoveryStrategies.RECOVER);
final AtomicReference<CopycatClient.State> prev =
new AtomicReference<>(CopycatClient.State.CONNECTED);
Listener<CopycatClient.State> stateListener = client.onStateChange(s -> {
switch (s) {
case CONNECTED:
threadAssertEquals(CopycatClient.State.SUSPENDED,
prev.getAndSet(CopycatClient.State.CONNECTED));
resume();
break;
case SUSPENDED:
threadAssertEquals(CopycatClient.State.CONNECTED,
prev.getAndSet(CopycatClient.State.SUSPENDED));
resume();
break;
case CLOSED:
threadFail("State not allowed");
}
});
((ClientSession) client.session()).expire().thenAccept(v -> resume());
await(5000, 3);
stateListener.close();
}
示例3: testStaleStateTransition
import io.atomix.catalyst.concurrent.Listener; //导入方法依赖的package包/类
public void testStaleStateTransition() throws InterruptedException {
ClientSessionState state = new ClientSessionState(UUID.randomUUID().toString(), Duration.ofMillis(1));
AtomicBoolean changed = new AtomicBoolean();
AtomicReference<Session.State> change = new AtomicReference<>();
Listener<Session.State> listener = state.onStateChange(
s -> {
changed.set(true);
change.set(s);
}
);
state.setState(Session.State.OPEN);
assertEquals(state.getState(), Session.State.OPEN);
assertEquals(change.get(), Session.State.OPEN);
assertTrue(changed.get());
changed.set(false);
state.setState(Session.State.UNSTABLE);
assertEquals(state.getState(), Session.State.UNSTABLE);
assertEquals(change.get(), Session.State.UNSTABLE);
assertTrue(changed.get());
Thread.sleep(10);
changed.set(false);
state.setState(Session.State.UNSTABLE);
assertEquals(state.getState(), Session.State.STALE);
assertEquals(change.get(), Session.State.STALE);
assertTrue(changed.get());
changed.set(false);
state.setState(Session.State.UNSTABLE);
assertEquals(state.getState(), Session.State.STALE);
assertEquals(change.get(), Session.State.STALE);
assertFalse(changed.get());
state.setState(Session.State.CLOSED);
assertEquals(state.getState(), Session.State.CLOSED);
assertEquals(change.get(), Session.State.CLOSED);
assertTrue(changed.get());
listener.close();
}