本文整理汇总了Java中io.atomix.catalyst.concurrent.Listener类的典型用法代码示例。如果您正苦于以下问题:Java Listener类的具体用法?Java Listener怎么用?Java Listener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Listener类属于io.atomix.catalyst.concurrent包,在下文中一共展示了Listener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: handleClosed
import io.atomix.catalyst.concurrent.Listener; //导入依赖的package包/类
/**
* Handles the channel being closed.
*/
void handleClosed() {
if (!closed) {
closed = true;
for (ContextualFuture<?> responseFuture : responseFutures.values()) {
responseFuture.context.executor().execute(() -> responseFuture.completeExceptionally(new ConnectException("connection closed")));
}
responseFutures.clear();
for (Listener<Connection> listener : closeListeners) {
listener.accept(this);
}
timeout.cancel();
}
}
示例4: onStateChange
import io.atomix.catalyst.concurrent.Listener; //导入依赖的package包/类
/**
* Registers a state change listener on the session manager.
*
* @param callback The state change listener callback.
* @return The state change listener.
*/
public Listener<Session.State> onStateChange(Consumer<Session.State> callback) {
Listener<Session.State> listener = new Listener<Session.State>() {
@Override
public void accept(Session.State state) {
callback.accept(state);
}
@Override
public void close() {
changeListeners.remove(this);
}
};
changeListeners.add(listener);
return listener;
}
示例5: handleException
import io.atomix.catalyst.concurrent.Listener; //导入依赖的package包/类
/**
* Handles an exception.
*
* @param t The exception to handle.
*/
void handleException(Throwable t) {
if (failure == null) {
failure = t;
for (ContextualFuture<?> responseFuture : responseFutures.values()) {
responseFuture.context.executor().execute(() -> responseFuture.completeExceptionally(t));
}
responseFutures.clear();
for (Listener<Throwable> listener : exceptionListeners) {
listener.accept(t);
}
}
}
示例6: onException
import io.atomix.catalyst.concurrent.Listener; //导入依赖的package包/类
@Override
public Listener<Throwable> onException(Consumer<Throwable> listener) {
if (failure != null) {
listener.accept(failure);
}
return exceptionListeners.add(Assert.notNull(listener, "listener"));
}
示例7: onClose
import io.atomix.catalyst.concurrent.Listener; //导入依赖的package包/类
@Override
public Listener<Connection> onClose(Consumer<Connection> listener) {
if (closed) {
listener.accept(this);
}
return closeListeners.add(Assert.notNull(listener, "listener"));
}
示例8: onStateChange
import io.atomix.catalyst.concurrent.Listener; //导入依赖的package包/类
@Override
public Listener<State> onStateChange(Consumer<State> callback) {
return client.onStateChange(callback);
}
示例9: onEvent
import io.atomix.catalyst.concurrent.Listener; //导入依赖的package包/类
@Override
public Listener<Void> onEvent(String event, Runnable callback) {
return client.onEvent(event, callback);
}
示例10: exceptionListener
import io.atomix.catalyst.concurrent.Listener; //导入依赖的package包/类
@Override
public Listener<Throwable> exceptionListener(Consumer<Throwable> listener) {
return exceptionListeners.add(listener);
}
示例11: closeListener
import io.atomix.catalyst.concurrent.Listener; //导入依赖的package包/类
@Override
public Listener<Connection> closeListener(Consumer<Connection> listener) {
return closeListeners.add(listener);
}
示例12: onStateChange
import io.atomix.catalyst.concurrent.Listener; //导入依赖的package包/类
@Override
public Listener<State> onStateChange(Consumer<State> callback) {
return state.onStateChange(callback);
}
示例13: onEvent
import io.atomix.catalyst.concurrent.Listener; //导入依赖的package包/类
/**
* Registers a session event listener.
*/
@SuppressWarnings("unchecked")
public Listener<Void> onEvent(String event, Runnable callback) {
return onEvent(event, v -> callback.run());
}
示例14: onStateChange
import io.atomix.catalyst.concurrent.Listener; //导入依赖的package包/类
@Override
public Listener<State> onStateChange(Consumer<State> callback) {
return new StateChangeListener(callback);
}
示例15: onEvent
import io.atomix.catalyst.concurrent.Listener; //导入依赖的package包/类
@Override
public Listener<Void> onEvent(String event, Runnable callback) {
return onEvent(event, v -> callback.run());
}