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


Java Listener类代码示例

本文整理汇总了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());
}
 
开发者ID:atomix,项目名称:copycat,代码行数:27,代码来源:ClientSessionStateTest.java

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

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

示例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;
}
 
开发者ID:atomix,项目名称:copycat,代码行数:21,代码来源:ClientSessionState.java

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

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

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

示例8: onStateChange

import io.atomix.catalyst.concurrent.Listener; //导入依赖的package包/类
@Override
public Listener<State> onStateChange(Consumer<State> callback) {
    return client.onStateChange(callback);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:5,代码来源:DelegatingCopycatClient.java

示例9: onEvent

import io.atomix.catalyst.concurrent.Listener; //导入依赖的package包/类
@Override
public Listener<Void> onEvent(String event, Runnable callback) {
    return client.onEvent(event, callback);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:5,代码来源:DelegatingCopycatClient.java

示例10: exceptionListener

import io.atomix.catalyst.concurrent.Listener; //导入依赖的package包/类
@Override
public Listener<Throwable> exceptionListener(Consumer<Throwable> listener) {
    return exceptionListeners.add(listener);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:5,代码来源:CopycatTransportConnection.java

示例11: closeListener

import io.atomix.catalyst.concurrent.Listener; //导入依赖的package包/类
@Override
public Listener<Connection> closeListener(Consumer<Connection> listener) {
    return closeListeners.add(listener);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:5,代码来源:CopycatTransportConnection.java

示例12: onStateChange

import io.atomix.catalyst.concurrent.Listener; //导入依赖的package包/类
@Override
public Listener<State> onStateChange(Consumer<State> callback) {
  return state.onStateChange(callback);
}
 
开发者ID:atomix,项目名称:copycat,代码行数:5,代码来源:ClientSession.java

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

示例14: onStateChange

import io.atomix.catalyst.concurrent.Listener; //导入依赖的package包/类
@Override
public Listener<State> onStateChange(Consumer<State> callback) {
  return new StateChangeListener(callback);
}
 
开发者ID:atomix,项目名称:copycat,代码行数:5,代码来源:DefaultCopycatClient.java

示例15: onEvent

import io.atomix.catalyst.concurrent.Listener; //导入依赖的package包/类
@Override
public Listener<Void> onEvent(String event, Runnable callback) {
  return onEvent(event, v -> callback.run());
}
 
开发者ID:atomix,项目名称:copycat,代码行数:5,代码来源:DefaultCopycatClient.java


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