java类javax.websocket.RemoteEndpoint.Async的实例源码

TyrusClient.java 文件源码 项目:ready-websocket-plugin 阅读 23 收藏 0 点赞 0 评论 0
/**
 * 
 * @see com.tsystems.readyapi.plugin.websocket.Client#sendMessage(com.tsystems.readyapi.plugin.websocket.Message,long)
 */
@Override
public void sendMessage(Message<?> message, long timeoutMillis) {
    Session session;
    if ((session = this.session.get()) != null) {
        throwable.set(null);
        future.set(null);

        Async asyncRemote = session.getAsyncRemote();
        asyncRemote.setSendTimeout(timeoutMillis);

        if (message instanceof Message.TextMessage) {
            Message.TextMessage text = (Message.TextMessage) message;
            future.set(asyncRemote.sendText(text.getPayload()));
        }
        if (message instanceof Message.BinaryMessage) {
            Message.BinaryMessage binary = (Message.BinaryMessage) message;
            future.set(asyncRemote.sendBinary(binary.getPayload()));
        }
    }
}
RealtimeResourceTest.java 文件源码 项目:OpenChatAlytics 阅读 33 收藏 0 点赞 0 评论 0
/**
 * Creates two sessions one that's closed and one that's open, sends an event and makes sure
 * that the closed gets collected and removed and that the event only gets propagated to the
 * open one
 */
@Test
public void testPublishEvent() {
    MessageSummary actualEvent = mock(MessageSummary.class);
    String eventType = actualEvent.getClass().getSimpleName();
    ChatAlyticsEvent event = new ChatAlyticsEvent(DateTime.now(), eventType, actualEvent);

    Async asyncRemote = mock(Async.class);
    when(session.getAsyncRemote()).thenReturn(asyncRemote);
    // open two sockets make one open and one closed
    ConnectionType type = ConnectionType.SUBSCRIBER;
    underTest.openSocket(type, session);
    verify(session).getId();
    verify(session).setMaxIdleTimeout(0);
    verifyNoMoreInteractions(session);
    Session closedSession = mock(Session.class);
    when(closedSession.getId()).thenReturn("id2");
    when(closedSession.isOpen()).thenReturn(false);
    underTest.openSocket(type, closedSession);
    verify(closedSession).getId();
    verify(closedSession).setMaxIdleTimeout(0);
    verifyNoMoreInteractions(closedSession);
    verify(session).isOpen();
    verifyNoMoreInteractions(session);
    assertEquals(2, underTest.numSessions());

    underTest.publishEvent(event);
    verify(session, times(2)).isOpen();
    verify(session).getAsyncRemote();
    verifyNoMoreInteractions(session);
    verify(asyncRemote).sendObject(event);
    verifyNoMoreInteractions(asyncRemote);
    verify(closedSession).isOpen();
    verifyNoMoreInteractions(closedSession);
    assertEquals(1, underTest.numSessions());
}
WebSocketHelper.java 文件源码 项目:hawkular-commons 阅读 25 收藏 0 点赞 0 评论 0
public void sendTextAsync(Session session, String text) {
    Async asyncRemote = session.getAsyncRemote();
    if (this.asyncTimeout != null) {
        asyncRemote.setSendTimeout(this.asyncTimeout.longValue());
    }
    asyncRemote.sendText(text);
}
BaseTest.java 文件源码 项目:nextrtc-signaling-server 阅读 32 收藏 0 点赞 0 评论 0
protected Session mockSession(String id, ArgumentMatcher<Message> match) {
    Session s = mock(Session.class);
    when(s.getId()).thenReturn(id);
    when(s.isOpen()).thenReturn(true);
    Async mockAsync = mockAsync(match);
    RemoteEndpoint.Basic mockBasic = mockBasic(match);
    when(s.getAsyncRemote()).thenReturn(mockAsync);
    when(s.getBasicRemote()).thenReturn(mockBasic);
    return s;
}
EventsResourceTest.java 文件源码 项目:OpenChatAlytics 阅读 26 收藏 0 点赞 0 评论 0
/**
 * Given an open and a closed session, this test makes sure that the event is only sent to the
 * open session. It also makes sure that the closed session gets removed from the list of open
 * sessions
 */
@Test
public void testOnMessage() {
    // open the compute connection
    Session computeSession = mock(Session.class);
    URI computeURI = URI.create("http://fake" + RT_COMPUTE_ENDPOINT);
    when(computeSession.getRequestURI()).thenReturn(computeURI);
    underTest.onOpen(computeSession);
    assertEquals(0, underTest.getSessions().size());
    verify(computeSession).getRequestURI();
    verify(computeSession).setMaxIdleTimeout(0);
    verifyNoMoreInteractions(computeSession);
    assertTrue(underTest.isConnectedToCompute());

    // add two sessions, one closed and one open
    Async asyncRemote = mock(Async.class);

    // open first client session
    Session firstClientSession = mock(Session.class);
    URI resourceURI = URI.create("http://fake" + RT_EVENT_ENDPOINT);
    when(firstClientSession.getRequestURI()).thenReturn(resourceURI);
    when(firstClientSession.isOpen()).thenReturn(true);
    when(firstClientSession.getAsyncRemote()).thenReturn(asyncRemote);
    underTest.onOpen(firstClientSession);
    verify(firstClientSession).getRequestURI();
    verify(firstClientSession).getId();
    verify(firstClientSession).setMaxIdleTimeout(0);
    verifyNoMoreInteractions(firstClientSession);
    assertEquals(1, underTest.getSessions().size());

    // open second client session
    Session secondClientSession = mock(Session.class);
    when(secondClientSession.getRequestURI()).thenReturn(resourceURI);
    when(secondClientSession.isOpen()).thenReturn(true);
    when(secondClientSession.getAsyncRemote()).thenReturn(asyncRemote);
    underTest.onOpen(secondClientSession);
    verify(secondClientSession).getRequestURI();
    verify(secondClientSession).getId();
    verify(secondClientSession).setMaxIdleTimeout(0);
    verifyNoMoreInteractions(secondClientSession);
    assertEquals(2, underTest.getSessions().size());

    // close the first session
    when(firstClientSession.isOpen()).thenReturn(false);
    ChatAlyticsEvent event = mock(ChatAlyticsEvent.class);
    underTest.onMessage(event);

    verify(event).setClazz(null);
    verify(firstClientSession, never()).getAsyncRemote();
    verify(secondClientSession).getAsyncRemote();
    verify(asyncRemote).sendObject(event);
    assertEquals(1, underTest.getSessions().size());
}
MockWebsocketSession.java 文件源码 项目:WhiteboardProject 阅读 34 收藏 0 点赞 0 评论 0
@Override
public Async getAsyncRemote() {
    // TODO Auto-generated method stub
    return null;
}
FakeSession.java 文件源码 项目:cyberattack-event-collector 阅读 27 收藏 0 点赞 0 评论 0
public Async getAsyncRemote() {
    // TODO Auto-generated method stub
    return null;
}
KafkaConsumer.java 文件源码 项目:kafka-ws 阅读 31 收藏 0 点赞 0 评论 0
public KafkaConsumerTask(KafkaStream stream, Async remoteEndpoint, final Session session, final boolean messagesOnly) {
  this.stream = stream;
  this.remoteEndpoint = remoteEndpoint;
  this.session = session;
  this.messagesOnly = messagesOnly;
}
BaseTest.java 文件源码 项目:nextrtc-signaling-server 阅读 30 收藏 0 点赞 0 评论 0
protected Async mockAsync(ArgumentMatcher<Message> match) {
    Async async = mock(Async.class);
    when(async.sendObject(Mockito.argThat(match))).thenReturn(null);
    return async;
}
AbstractInterlocutor.java 文件源码 项目:p2pEngine 阅读 28 收藏 0 点赞 0 评论 0
public static void setCom(Async com){
    AbstractInterlocutor.com = com;
}
Answer.java 文件源码 项目:p2pEngine 阅读 33 收藏 0 点赞 0 评论 0
public static void setCom(Async com){
    Answer.com = com;
}


问题


面经


文章

微信
公众号

扫码关注公众号