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


Java Async类代码示例

本文整理汇总了Java中javax.websocket.RemoteEndpoint.Async的典型用法代码示例。如果您正苦于以下问题:Java Async类的具体用法?Java Async怎么用?Java Async使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Async类属于javax.websocket.RemoteEndpoint包,在下文中一共展示了Async类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendMessage

import javax.websocket.RemoteEndpoint.Async; //导入依赖的package包/类
/**
 * 
 * @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()));
        }
    }
}
 
开发者ID:hschott,项目名称:ready-websocket-plugin,代码行数:25,代码来源:TyrusClient.java

示例2: testPublishEvent

import javax.websocket.RemoteEndpoint.Async; //导入依赖的package包/类
/**
 * 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());
}
 
开发者ID:OpenChatAlytics,项目名称:OpenChatAlytics,代码行数:41,代码来源:RealtimeResourceTest.java

示例3: sendTextAsync

import javax.websocket.RemoteEndpoint.Async; //导入依赖的package包/类
public void sendTextAsync(Session session, String text) {
    Async asyncRemote = session.getAsyncRemote();
    if (this.asyncTimeout != null) {
        asyncRemote.setSendTimeout(this.asyncTimeout.longValue());
    }
    asyncRemote.sendText(text);
}
 
开发者ID:hawkular,项目名称:hawkular-commons,代码行数:8,代码来源:WebSocketHelper.java

示例4: mockSession

import javax.websocket.RemoteEndpoint.Async; //导入依赖的package包/类
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;
}
 
开发者ID:mslosarz,项目名称:nextrtc-signaling-server,代码行数:11,代码来源:BaseTest.java

示例5: testOnMessage

import javax.websocket.RemoteEndpoint.Async; //导入依赖的package包/类
/**
 * 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());
}
 
开发者ID:OpenChatAlytics,项目名称:OpenChatAlytics,代码行数:58,代码来源:EventsResourceTest.java

示例6: getAsyncRemote

import javax.websocket.RemoteEndpoint.Async; //导入依赖的package包/类
@Override
public Async getAsyncRemote() {
	// TODO Auto-generated method stub
	return null;
}
 
开发者ID:smit-happens,项目名称:WhiteboardProject,代码行数:6,代码来源:MockWebsocketSession.java

示例7: getAsyncRemote

import javax.websocket.RemoteEndpoint.Async; //导入依赖的package包/类
public Async getAsyncRemote() {
	// TODO Auto-generated method stub
	return null;
}
 
开发者ID:cloudronin,项目名称:cyberattack-event-collector,代码行数:5,代码来源:FakeSession.java

示例8: KafkaConsumerTask

import javax.websocket.RemoteEndpoint.Async; //导入依赖的package包/类
public KafkaConsumerTask(KafkaStream stream, Async remoteEndpoint, final Session session, final boolean messagesOnly) {
  this.stream = stream;
  this.remoteEndpoint = remoteEndpoint;
  this.session = session;
  this.messagesOnly = messagesOnly;
}
 
开发者ID:nikore,项目名称:kafka-ws,代码行数:7,代码来源:KafkaConsumer.java

示例9: mockAsync

import javax.websocket.RemoteEndpoint.Async; //导入依赖的package包/类
protected Async mockAsync(ArgumentMatcher<Message> match) {
    Async async = mock(Async.class);
    when(async.sendObject(Mockito.argThat(match))).thenReturn(null);
    return async;
}
 
开发者ID:mslosarz,项目名称:nextrtc-signaling-server,代码行数:6,代码来源:BaseTest.java

示例10: setCom

import javax.websocket.RemoteEndpoint.Async; //导入依赖的package包/类
public static void setCom(Async com){
	AbstractInterlocutor.com = com;
}
 
开发者ID:pja35,项目名称:p2pEngine,代码行数:4,代码来源:AbstractInterlocutor.java

示例11: setCom

import javax.websocket.RemoteEndpoint.Async; //导入依赖的package包/类
public static void setCom(Async com){
	Answer.com = com;
}
 
开发者ID:pja35,项目名称:p2pEngine,代码行数:4,代码来源:Answer.java


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