本文整理汇总了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()));
}
}
}
示例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());
}
示例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);
}
示例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;
}
示例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());
}
示例6: getAsyncRemote
import javax.websocket.RemoteEndpoint.Async; //导入依赖的package包/类
@Override
public Async getAsyncRemote() {
// TODO Auto-generated method stub
return null;
}
示例7: getAsyncRemote
import javax.websocket.RemoteEndpoint.Async; //导入依赖的package包/类
public Async getAsyncRemote() {
// TODO Auto-generated method stub
return null;
}
示例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;
}
示例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;
}
示例10: setCom
import javax.websocket.RemoteEndpoint.Async; //导入依赖的package包/类
public static void setCom(Async com){
AbstractInterlocutor.com = com;
}
示例11: setCom
import javax.websocket.RemoteEndpoint.Async; //导入依赖的package包/类
public static void setCom(Async com){
Answer.com = com;
}