Java 类javax.websocket.RemoteEndpoint.Async 实例源码

项目:ready-websocket-plugin    文件:TyrusClient.java   
/**
 * 
 * @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()));
        }
    }
}
项目:OpenChatAlytics    文件:RealtimeResourceTest.java   
/**
 * 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());
}
项目:hawkular-commons    文件:WebSocketHelper.java   
public void sendTextAsync(Session session, String text) {
    Async asyncRemote = session.getAsyncRemote();
    if (this.asyncTimeout != null) {
        asyncRemote.setSendTimeout(this.asyncTimeout.longValue());
    }
    asyncRemote.sendText(text);
}
项目:nextrtc-signaling-server    文件:BaseTest.java   
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;
}
项目:OpenChatAlytics    文件:EventsResourceTest.java   
/**
 * 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());
}
项目:WhiteboardProject    文件:MockWebsocketSession.java   
@Override
public Async getAsyncRemote() {
    // TODO Auto-generated method stub
    return null;
}
项目:cyberattack-event-collector    文件:FakeSession.java   
public Async getAsyncRemote() {
    // TODO Auto-generated method stub
    return null;
}
项目:kafka-ws    文件:KafkaConsumer.java   
public KafkaConsumerTask(KafkaStream stream, Async remoteEndpoint, final Session session, final boolean messagesOnly) {
  this.stream = stream;
  this.remoteEndpoint = remoteEndpoint;
  this.session = session;
  this.messagesOnly = messagesOnly;
}
项目:nextrtc-signaling-server    文件:BaseTest.java   
protected Async mockAsync(ArgumentMatcher<Message> match) {
    Async async = mock(Async.class);
    when(async.sendObject(Mockito.argThat(match))).thenReturn(null);
    return async;
}
项目:p2pEngine    文件:AbstractInterlocutor.java   
public static void setCom(Async com){
    AbstractInterlocutor.com = com;
}
项目:p2pEngine    文件:Answer.java   
public static void setCom(Async com){
    Answer.com = com;
}