本文整理汇总了Java中javax.websocket.RemoteEndpoint.Async方法的典型用法代码示例。如果您正苦于以下问题:Java RemoteEndpoint.Async方法的具体用法?Java RemoteEndpoint.Async怎么用?Java RemoteEndpoint.Async使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.websocket.RemoteEndpoint
的用法示例。
在下文中一共展示了RemoteEndpoint.Async方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onOpen
import javax.websocket.RemoteEndpoint; //导入方法依赖的package包/类
@OnOpen
public void onOpen(Session session, @PathParam("uuid") String uuid) {
UUID key = UUID.fromString(uuid);
peers.put(key, session);
JsonArrayBuilder builder = Json.createArrayBuilder();
for (StatusEventType statusEventType : StatusEventType.values()) {
JsonObjectBuilder object = Json.createObjectBuilder();
builder.add(object.add(statusEventType.name(), statusEventType.getMessage()).build());
}
RemoteEndpoint.Async asyncRemote = session.getAsyncRemote();
asyncRemote.sendText(builder.build().toString());
// Send pending messages
List<String> messages = messageBuffer.remove(key);
if (messages != null) {
messages.forEach(asyncRemote::sendText);
}
}
示例2: onOpen
import javax.websocket.RemoteEndpoint; //导入方法依赖的package包/类
@OnOpen
public void onOpen(Session session, @PathParam("uuid") String uuid) {
UUID key = UUID.fromString(uuid);
peers.put(key, session);
JsonArrayBuilder builder = Json.createArrayBuilder();
for (StatusMessage statusMessage : StatusMessage.values()) {
JsonObjectBuilder object = Json.createObjectBuilder();
builder.add(object.add(statusMessage.name(), statusMessage.getMessage()).build());
}
RemoteEndpoint.Async asyncRemote = session.getAsyncRemote();
asyncRemote.sendText(builder.build().toString());
// Send pending messages
List<String> messages = messageBuffer.remove(key);
if (messages != null) {
messages.forEach(asyncRemote::sendText);
}
}
示例3: testSendMessageToClient
import javax.websocket.RemoteEndpoint; //导入方法依赖的package包/类
/**
* Test of sendMessageToClient method, of class CallServiceManager.
*/
@Test
public void testSendMessageToClient() {
System.out.println("sendMessageToClient");
Session client = mock(Session.class);
MessageToClient mtc = mock(MessageToClient.class);
RemoteEndpoint.Async async = mock(RemoteEndpoint.Async.class);
when(client.getAsyncRemote()).thenReturn(async);
when(messageToClientService.createMessageToClient(any(MessageFromClient.class), any(Session.class))).thenReturn(mtc).thenReturn(null);
boolean result = instance.sendMessageToClient(new MessageFromClient(), client);
assertThat(result).isTrue();
result = instance.sendMessageToClient(new MessageFromClient(), client);
assertThat(result).isFalse();
ArgumentCaptor<MessageToClient> captureMsg = ArgumentCaptor.forClass(MessageToClient.class);
verify(async).sendObject(captureMsg.capture());
assertThat(captureMsg.getValue()).isEqualTo(mtc);
}
示例4: testSendSubscriptionEvent
import javax.websocket.RemoteEndpoint; //导入方法依赖的package包/类
/**
* Test of sendSubscriptionEvent method, of class TopicManager.
*/
@Test
public void testSendSubscriptionEvent() {
System.out.println("sendSubscriptionEvent");
Collection<Session> sessions = new ArrayList<>();
Session session = mock(Session.class);
RemoteEndpoint.Async async = mock(RemoteEndpoint.Async.class);
sessions.add(session);
when(session.isOpen()).thenReturn(Boolean.FALSE).thenReturn(Boolean.TRUE);
when(session.getAsyncRemote()).thenReturn(async);
doReturn(Collections.EMPTY_LIST).doReturn(sessions).when(instance).getSessionsForTopic(TOPIC1);
instance.sendSubscriptionEvent(TOPIC1, 1);
instance.sendSubscriptionEvent(TOPIC1, 2);
instance.sendSubscriptionEvent(TOPIC1, 3);
ArgumentCaptor<MessageToClient> captureMsg = ArgumentCaptor.forClass(MessageToClient.class);
verify(async).sendObject(captureMsg.capture());
MessageToClient msg = captureMsg.getValue();
assertThat(msg.getType()).isEqualTo(MessageType.MESSAGE);
assertThat(msg.getId()).isEqualTo(TOPIC1);
assertThat(msg.getResponse()).isEqualTo(3);
}
示例5: checkAndSendMtcToSessionTest
import javax.websocket.RemoteEndpoint; //导入方法依赖的package包/类
/**
* Test of checkAndSendMtcToSession method, of class.
*
* @throws javax.websocket.SessionException
* @throws org.ocelotds.security.NotRecipientException
*/
@Test
public void checkAndSendMtcToSessionTest() throws SessionException, NotRecipientException {
System.out.println("checkAndSendMtcToSession");
Session session = mock(Session.class);
RemoteEndpoint.Async async = mock(RemoteEndpoint.Async.class);
when(session.isOpen()).thenReturn(true);
when(session.getId()).thenReturn("ID1");
when(session.getAsyncRemote()).thenReturn(async);
JsTopicMessageController jtmcmsgControl = mock(JsTopicMessageController.class);
MessageToClient mtc = mock(MessageToClient.class);
when(session.isOpen()).thenReturn(Boolean.TRUE);
when(userContextFactory.getUserContext(eq("ID1"))).thenReturn(mock(UserContext.class));
doNothing().doThrow(NotRecipientException.class).when(instance).checkMessageTopic(any(UserContext.class), anyString(), eq(PAYLOAD), eq(jtmcmsgControl));
int result = instance.checkAndSendMtcToSession(session, jtmcmsgControl, mtc, PAYLOAD);
assertThat(result).isEqualTo(1);
result = instance.checkAndSendMtcToSession(session, jtmcmsgControl, mtc, PAYLOAD);
assertThat(result).isEqualTo(0);
}
示例6: getIp
import javax.websocket.RemoteEndpoint; //导入方法依赖的package包/类
public static String getIp(javax.websocket.Session session){
RemoteEndpoint.Async async = session.getAsyncRemote();
InetSocketAddress addr = (InetSocketAddress) getFieldInstance(async,
"base#sos#socketWrapper#socket#sc#remoteAddress");
if(addr == null){
return "127.0.0.1";
}
return addr.getAddress().getHostAddress();
}
示例7: testRemoveSessionToTopic
import javax.websocket.RemoteEndpoint; //导入方法依赖的package包/类
/**
* Test of removeSessionToTopics method, of class TopicManager.
*
* @throws java.lang.IllegalAccessException
*/
@Test
public void testRemoveSessionToTopic() throws IllegalAccessException {
System.out.println("removeSessionToTopic");
Session session = mock(Session.class);
when(session.isOpen()).thenReturn(true);
int result = instance.registerTopicSession(TOPIC1, session);
assertThat(result).isEqualTo(1);
assertThat(instance.getNumberSubscribers(TOPIC1)).isEqualTo(1);
result = instance.registerTopicSession(TOPIC2, session);
assertThat(result).isEqualTo(1);
assertThat(instance.getNumberSubscribers(TOPIC2)).isEqualTo(1);
Session session1 = mock(Session.class);
when(session1.isOpen()).thenReturn(true);
result = instance.registerTopicSession(TOPIC2, session1);
assertThat(result).isEqualTo(2);
assertThat(instance.getNumberSubscribers(TOPIC2)).isEqualTo(2);
result = instance.registerTopicSession(SUBTOPIC2, session1);
assertThat(result).isEqualTo(1);
assertThat(instance.getNumberSubscribers(SUBTOPIC2)).isEqualTo(1);
RemoteEndpoint.Async async = mock(RemoteEndpoint.Async.class);
when(session1.getAsyncRemote()).thenReturn(async);
instance.removeSessionToTopics(session);
instance.removeSessionToTopics(null);
assertThat(instance.getNumberSubscribers(TOPIC1)).isEqualTo(0);
assertThat(instance.getNumberSubscribers(TOPIC2)).isEqualTo(1);
ArgumentCaptor<MessageToClient> captureMsg = ArgumentCaptor.forClass(MessageToClient.class);
verify(async).sendObject(captureMsg.capture());
MessageToClient msg = captureMsg.getValue();
assertThat(msg.getType()).isEqualTo(MessageType.MESSAGE);
assertThat(msg.getId()).isEqualTo(Constants.Topic.SUBSCRIBERS + Constants.Topic.COLON + TOPIC2);
assertThat(msg.getResponse()).isEqualTo(1);
}
示例8: TestClientActor
import javax.websocket.RemoteEndpoint; //导入方法依赖的package包/类
public TestClientActor(String name, Server server) {
this.server = server;
this.name = name;
Session session = mock(Session.class);
this.client = new MockedClient(server, session);
when(session.getId()).thenReturn(name);
when(session.isOpen()).thenReturn(true);
RemoteEndpoint.Async async = mockAsync(session);
RemoteEndpoint.Basic basic = mockBasic();
when(session.getAsyncRemote()).thenReturn(async);
when(session.getBasicRemote()).thenReturn(basic);
this.session = session;
}
示例9: getAsyncRemote
import javax.websocket.RemoteEndpoint; //导入方法依赖的package包/类
@Override
public RemoteEndpoint.Async getAsyncRemote() {
checkState();
return remoteEndpointAsync;
}
示例10: getAsyncRemote
import javax.websocket.RemoteEndpoint; //导入方法依赖的package包/类
@Override
public RemoteEndpoint.Async getAsyncRemote() {
checkState();
return remoteEndpointAsync;
}
示例11: getAsyncRemote
import javax.websocket.RemoteEndpoint; //导入方法依赖的package包/类
public RemoteEndpoint.Async getAsyncRemote(){
return socketSession.getAsyncRemote();
}
示例12: getAsyncRemote
import javax.websocket.RemoteEndpoint; //导入方法依赖的package包/类
@Override
public RemoteEndpoint.Async getAsyncRemote() {
throw new UnsupportedOperationException("Method is not supported");
}
示例13: getRemote
import javax.websocket.RemoteEndpoint; //导入方法依赖的package包/类
/**
* Helper to get the async remote endpoint.
*/
private RemoteEndpoint.Async getRemote() {
return webSocketSession.getAsyncRemote();
}
示例14: mockAsync
import javax.websocket.RemoteEndpoint; //导入方法依赖的package包/类
private RemoteEndpoint.Async mockAsync(Session session) {
RemoteEndpoint.Async async = mock(RemoteEndpoint.Async.class);
when(async.sendObject(Mockito.argThat(client))).thenReturn(null);
when(session.getAsyncRemote()).thenReturn(async);
return async;
}
示例15: BinaryFrameOutputStream
import javax.websocket.RemoteEndpoint; //导入方法依赖的package包/类
public BinaryFrameOutputStream(RemoteEndpoint.Async remote) {
this.buffer = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE);
this.remote = remote;
}