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


Java RemoteEndpoint.Async方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:19,代码来源:MissionControlStatusEndpoint.java

示例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);
    }
}
 
开发者ID:fabric8-launcher,项目名称:launchpad-missioncontrol,代码行数:19,代码来源:MissionControlStatusEndpoint.java

示例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);
}
 
开发者ID:ocelotds,项目名称:ocelot,代码行数:24,代码来源:CallServiceManagerTest.java

示例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);
}
 
开发者ID:ocelotds,项目名称:ocelot,代码行数:26,代码来源:TopicManagerImplTest.java

示例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);
}
 
开发者ID:ocelotds,项目名称:ocelot,代码行数:28,代码来源:TopicsMessagesBroadcasterTest.java

示例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();
}
 
开发者ID:xuerong,项目名称:MMServerEngine,代码行数:10,代码来源:Util.java

示例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);
}
 
开发者ID:ocelotds,项目名称:ocelot,代码行数:43,代码来源:TopicManagerImplTest.java

示例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;
}
 
开发者ID:mslosarz,项目名称:nextrtc-signaling-server,代码行数:14,代码来源:TestClientActor.java

示例9: getAsyncRemote

import javax.websocket.RemoteEndpoint; //导入方法依赖的package包/类
@Override
public RemoteEndpoint.Async getAsyncRemote() {
    checkState();
    return remoteEndpointAsync;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:6,代码来源:WsSession.java

示例10: getAsyncRemote

import javax.websocket.RemoteEndpoint; //导入方法依赖的package包/类
@Override
public RemoteEndpoint.Async getAsyncRemote() {
	checkState();
	return remoteEndpointAsync;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:6,代码来源:WsSession.java

示例11: getAsyncRemote

import javax.websocket.RemoteEndpoint; //导入方法依赖的package包/类
public RemoteEndpoint.Async getAsyncRemote(){
    return socketSession.getAsyncRemote();
}
 
开发者ID:andylizi,项目名称:Gobang,代码行数:4,代码来源:User.java

示例12: getAsyncRemote

import javax.websocket.RemoteEndpoint; //导入方法依赖的package包/类
@Override
public RemoteEndpoint.Async getAsyncRemote() {
    throw new UnsupportedOperationException("Method is not supported");
}
 
开发者ID:wso2,项目名称:carbon-transports,代码行数:5,代码来源:WebSocketSessionAdapter.java

示例13: getRemote

import javax.websocket.RemoteEndpoint; //导入方法依赖的package包/类
/**
 * Helper to get the async remote endpoint.
 */
private RemoteEndpoint.Async getRemote() {
    return webSocketSession.getAsyncRemote();
}
 
开发者ID:matzew,项目名称:simple-websocket-client,代码行数:7,代码来源:SimpleWebSocketClient.java

示例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;
}
 
开发者ID:mslosarz,项目名称:nextrtc-signaling-server,代码行数:7,代码来源:TestClientActor.java

示例15: BinaryFrameOutputStream

import javax.websocket.RemoteEndpoint; //导入方法依赖的package包/类
public BinaryFrameOutputStream(RemoteEndpoint.Async remote) {
    this.buffer = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE);
    this.remote = remote;
}
 
开发者ID:kawasima,项目名称:websocket-classloader,代码行数:5,代码来源:BinaryFrameOutputStream.java


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