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


Java RemoteEndpoint类代码示例

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


RemoteEndpoint类属于javax.websocket包,在下文中一共展示了RemoteEndpoint类的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: createProcess

import javax.websocket.RemoteEndpoint; //导入依赖的package包/类
synchronized LSPProcess createProcess(String wsKey, String lang, RemoteEndpoint.Basic remoteEndpoint, String ownerSessionId) throws LSPException {

		String procKey = processKey(wsKey, lang);
		String rpcType = langContexts.get(lang).getRpcType();
		String wsKeyElem[] = wsKey.split(WS_KEY_DELIMITER,3);

		disconnect(lang, ownerSessionId);
		LSPProcess lspProcess = new LSPProcess(wsKeyElem, lang, langContexts.get(lang).getProcessBuilder(wsKeyElem), remoteEndpoint, ownerSessionId);
		switch(rpcType) {
		case ENV_IPC_SOCKET:
			socketEnv(lspProcess, LangServerCtx.LangPrefix(lang));
			break;
		case ENV_IPC_PIPES:
			pipeEnv(lspProcess, LangServerCtx.LangPrefix(lang));
			break;
		case ENV_IPC_CLIENT:
			clientSocketEnv(lspProcess, LangServerCtx.LangPrefix(lang));
			break;
		default:
			streamEnv(lspProcess);
		}
		lspProcesses.put(procKey, lspProcess);
		return lspProcess;
	}
 
开发者ID:SAP,项目名称:cloud-language-servers-container,代码行数:25,代码来源:LSPProcessManager.java

示例3: processResult

import javax.websocket.RemoteEndpoint; //导入依赖的package包/类
protected final void processResult(Object result) {
    if (result == null) {
        return;
    }

    RemoteEndpoint.Basic remoteEndpoint = session.getBasicRemote();
    try {
        if (result instanceof String) {
            remoteEndpoint.sendText((String) result);
        } else if (result instanceof ByteBuffer) {
            remoteEndpoint.sendBinary((ByteBuffer) result);
        } else if (result instanceof byte[]) {
            remoteEndpoint.sendBinary(ByteBuffer.wrap((byte[]) result));
        } else {
            remoteEndpoint.sendObject(result);
        }
    } catch (IOException ioe) {
        throw new IllegalStateException(ioe);
    } catch (EncodeException ee) {
        throw new IllegalStateException(ee);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:23,代码来源:PojoMessageHandlerBase.java

示例4: processResult

import javax.websocket.RemoteEndpoint; //导入依赖的package包/类
protected final void processResult(Object result) {
	if (result == null) {
		return;
	}

	RemoteEndpoint.Basic remoteEndpoint = session.getBasicRemote();
	try {
		if (result instanceof String) {
			remoteEndpoint.sendText((String) result);
		} else if (result instanceof ByteBuffer) {
			remoteEndpoint.sendBinary((ByteBuffer) result);
		} else if (result instanceof byte[]) {
			remoteEndpoint.sendBinary(ByteBuffer.wrap((byte[]) result));
		} else {
			remoteEndpoint.sendObject(result);
		}
	} catch (IOException ioe) {
		throw new IllegalStateException(ioe);
	} catch (EncodeException ee) {
		throw new IllegalStateException(ee);
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:23,代码来源:PojoMessageHandlerBase.java

示例5: 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

示例6: updateAllMap

import javax.websocket.RemoteEndpoint; //导入依赖的package包/类
public void updateAllMap(int nc, boolean send, RemoteEndpoint.Basic... remotes) {
    for (int x = 0; x < data.length; x++) {
        for (int y = 0; y < data[0].length; y++) {
            if (nc != -1) {
                data[x][y] = nc;
            }
            if (send) {
                String msg = "update:" + x + ":" + y + ":" + data[x][y];
                for (RemoteEndpoint.Basic remote : remotes) {
                    try {
                        remote.sendText(msg);
                    } catch (IOException ex) {
                    }
                }
            }
        }
    }
}
 
开发者ID:andylizi,项目名称:Gobang,代码行数:19,代码来源:Room.java

示例7: setupTest

import javax.websocket.RemoteEndpoint; //导入依赖的package包/类
@Before
public void setupTest() throws Exception {
    this.origRegistry = MonitorWebsocket.getRegistry();
    this.origSendTimeout = MonitorWebsocket.getSendTimeout();
    this.origScheduler = MonitorWebsocket.getScheduler();

    this.mockRegistry = Mockito.mock(MonitorWebsocketRegistry.class);
    this.mockScheduler = Mockito.mock(Scheduler.class);

    this.mockSession = Mockito.mock(Session.class);
    this.mockReason = Mockito.mock(CloseReason.class);
    this.mockAsyncRemote = Mockito.mock(RemoteEndpoint.Async.class);
    this.mockBasic = Mockito.mock(RemoteEndpoint.Basic.class);
    this.mockSendProcess = Mockito.mock(StepListSchedulerProcess.class);

    this.mockLogger = Mockito.mock(Logger.class);

    Mockito.when(this.mockSession.getId()).thenReturn("x-sess-id-x");
    Mockito.when(this.mockSession.getAsyncRemote()).thenReturn(this.mockAsyncRemote);
    Mockito.when(this.mockSession.getBasicRemote()).thenReturn(this.mockBasic);
}
 
开发者ID:amlinv,项目名称:amq-monitor,代码行数:22,代码来源:MonitorWebsocketTest.java

示例8: 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

示例9: 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

示例10: 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

示例11: handle

import javax.websocket.RemoteEndpoint; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void handle(final ByteBuffer buf, final Session session) throws IOException {
    WebSocketContext context = new WebSocketContext(this, session, config);
    final int id = buf.getInt();
    currentContext.set(context);
    handle(buf.slice(), context).then(new Action<ByteBuffer>() {
        public void call(ByteBuffer value) throws Throwable {
            try {
                ByteBuffer buffer = ByteBuffer.allocate(4 + value.remaining());
                buffer.putInt(id);
                buffer.put(value);
                buffer.flip();
                final RemoteEndpoint.Async remote = session.getAsyncRemote();
                remote.sendBinary(buffer);
            }
            finally {
                ByteBufferStream.free(value);
            }
        }
    }).whenComplete(new Runnable() {
        public void run() {
            currentContext.remove();
            ByteBufferStream.free(buf);
        }
    });
}
 
开发者ID:hprose,项目名称:hprose-java,代码行数:27,代码来源:HproseWebSocketService.java

示例12: setup

import javax.websocket.RemoteEndpoint; //导入依赖的package包/类
@SuppressWarnings("ResultOfMethodCallIgnored")
@Before
public void setup() throws Exception{
    //setup mocks
    cle = new ClassLoaderEndpoint();
    session = mock(Session.class);
    RemoteEndpoint remoteEndpoint = mock(RemoteEndpoint.Async.class);
    doReturn(remoteEndpoint).when(session).getAsyncRemote();
    ((RemoteEndpoint.Async) doReturn(null).when(remoteEndpoint)).sendBinary(any(ByteBuffer.class));
    resourceRequest = mock(ResourceRequest.class);
    doReturn(UUID.randomUUID()).when(resourceRequest).getClassLoaderId();
    doReturn("resource1").when(resourceRequest).getResourceName();
    FressianWriter fressianWriter = mock(FressianWriter.class);
    doReturn(mock(Writer.class)).when(fressianWriter).writeObject(any(ResourceRequest.class));
    PowerMockito.whenNew(FressianWriter.class).withAnyArguments().thenReturn(fressianWriter);
}
 
开发者ID:kawasima,项目名称:websocket-classloader,代码行数:17,代码来源:ClassLoaderEndpointTest.java

示例13: onOpen

import javax.websocket.RemoteEndpoint; //导入依赖的package包/类
@Override
public void onOpen(Session session, EndpointConfig arg1) {
	final RemoteEndpoint.Basic remote = session.getBasicRemote();
	session.addMessageHandler(new MessageHandler.Whole<String>() {
		public void onMessage(String text) {
			try {
				remote.sendText(text.toUpperCase());
			} catch (IOException ioe) {
				ioe.printStackTrace();
			}
		}
	});
}
 
开发者ID:Sunature,项目名称:websocket,代码行数:14,代码来源:java7Ws.java

示例14: 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

示例15: join

import javax.websocket.RemoteEndpoint; //导入依赖的package包/类
public void join(User player2) {
    if (player2 == null) {
        return;
    }
    if (playing && checkOpen(player2)) {
        try {
            spectators.add(player2);
            player2.addMessageHandler(handler.new SpectatorHandler(player2));
            RemoteEndpoint.Basic remote = player2.getBasicRemote();
            remote.sendText("start:spectator");
            updateAllMap(-1, true, player2.getBasicRemote());
            remote.sendText("status:white:" + (turnToBlack ? "Waiting..." : "Holding..."));
            remote.sendText("status:black:" + (turnToBlack ? "Holding..." : "Waiting..."));
            remote.sendText("join:white:" + (player1IsWhite ? player1.getName() : this.player2.getName()));
            remote.sendText("join:black:" + (!player1IsWhite ? player1.getName() : this.player2.getName()));
            broadcast("join:spectator:" + player2.getName());
        } catch (IOException ex) {
            spectators.remove(player2);
        }
        return;
    }
    this.player2 = player2;
    broadcast("join:" + (player1IsWhite ? "black" : "white") + ":" + player2.getName());
    sendToPlayer2("join:" + (player1IsWhite ? "white" : "black") + ":" + player1.getName());
    if (canStart()) {
        start(false);
    }
    player2.addMessageHandler(this.handler.new Player2Handler());
}
 
开发者ID:andylizi,项目名称:Gobang,代码行数:30,代码来源:Room.java


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