Java 类javax.websocket.RemoteEndpoint.Basic 实例源码

项目:cloud-language-servers-container    文件:LSPProcessManager.java   
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;
    }
项目:script-wars    文件:GameViewerSocket.java   
@OnOpen
public void open(@PathParam("gametype") String gameID, Session session) throws IOException {
    type = GameType.getGameType(gameID);
    if(type == null) {
        session.close(new CloseReason(CloseReason.CloseCodes.UNEXPECTED_CONDITION, "Invalid game type"));
        return;
    }

    Basic sender = session.getBasicRemote();

    viewer = data -> {
            synchronized(session) {
                if(session.isOpen())
                    try { sender.sendBinary(data); } catch (IOException e) {}
            }
    };

    DisplayHandler.addGlobalViewer(viewer);
}
项目:cito    文件:AbstractEndpointTest.java   
@Test
public void onError() throws IOException, EncodeException {
    final Session session = mock(Session.class);
    when(session.getId()).thenReturn("sessionId");
    final Throwable cause = new Throwable();
    when(this.errorEvent.select(OnError.Literal.onError())).thenReturn(this.errorEvent);
    final Basic basic = mock(Basic.class);
    when(session.getBasicRemote()).thenReturn(basic);

    this.endpoint.onError(session, cause);

    verify(session).getId();
    verify(session).getUserPrincipal();
    verify(this.log).warn(eq("WebSocket error. [id={},principle={},errorId={}]"), eq("sessionId"), isNull(), anyString(), eq(cause));
    verify(this.errorEvent).select(OnError.Literal.onError());
    verify(this.errorEvent).fire(cause);
    verify(session).getBasicRemote();
    verify(basic).sendObject(any(Frame.class));
    verify(session).close(any(CloseReason.class));
    verifyNoMoreInteractions(session, basic);
}
项目:cito    文件:SessionRegistryTest.java   
@Test
public void fromBroker() throws IOException, EncodeException {
    final Message msg = mock(Message.class);
    when(msg.sessionId()).thenReturn("sessionId");
    final Frame frame = mock(Frame.class);
    when(msg.frame()).thenReturn(frame);
    when(frame.command()).thenReturn(Command.MESSAGE);
    final Session session = Mockito.mock(Session.class);
    getSessionMap().put("sessionId", session);
    getPrincipalSessionMap().put(NULL_PRINCIPLE, new HashSet<>(singleton(session)));
    final Basic basic = mock(Basic.class);
    when(session.getBasicRemote()).thenReturn(basic);

    this.registry.fromBroker(msg);

    verify(msg).sessionId();
    verify(msg).frame();
    verify(frame, times(2)).command();
    verify(this.log).debug("Sending message to client. [sessionId={},command={}]", "sessionId", Command.MESSAGE);
    verify(session).getBasicRemote();
    verify(basic).sendObject(frame);
    verifyNoMoreInteractions(msg, frame, session, basic);
}
项目:cito    文件:SessionRegistryTest.java   
@Test
public void fromBroker_ioe() throws IOException, EncodeException {
    final Message msg = mock(Message.class);
    when(msg.sessionId()).thenReturn("sessionId");
    final Frame frame = mock(Frame.class);
    when(msg.frame()).thenReturn(frame);
    when(frame.command()).thenReturn(Command.MESSAGE);
    final Session session = Mockito.mock(Session.class);
    getSessionMap().put("sessionId", session);
    getPrincipalSessionMap().put(NULL_PRINCIPLE, new HashSet<>(singleton(session)));
    final Basic basic = mock(Basic.class);
    when(session.getBasicRemote()).thenReturn(basic);
    final IOException ioe = new IOException();
    doThrow(ioe).when(basic).sendObject(frame);

    this.registry.fromBroker(msg);

    verify(msg).sessionId();
    verify(msg).frame();
    verify(frame, times(3)).command();
    verify(this.log).debug("Sending message to client. [sessionId={},command={}]", "sessionId", Command.MESSAGE);
    verify(session).getBasicRemote();
    verify(basic).sendObject(frame);
    verify(this.log).error("Unable to send message! [sessionid={},command={}]", "sessionId", Command.MESSAGE, ioe);
    verifyNoMoreInteractions(msg, frame, session, basic);
}
项目:hawkular-commons    文件:WebSocketHelper.java   
public long copyInputToOutput() throws IOException {
    Basic basicRemote = session.getBasicRemote();
    OutputStream outputStream = basicRemote.getSendStream();

    try {
        // slurp the input stream data and send directly to the output stream
        byte[] buf = new byte[4096];
        long totalBytesCopied = 0L;
        while (true) {
            int numRead = inputStream.read(buf);
            if (numRead == -1) {
                break;
            }
            outputStream.write(buf, 0, numRead);
            totalBytesCopied += numRead;
        }
        return totalBytesCopied;
    } finally {
        try {
            outputStream.close();
        } finally {
            inputStream.close();
        }
    }
}
项目:cloud-language-servers-container    文件:LSPProcessManager.java   
LSPProcess(String wsKeyElem[], String lang, ProcessBuilder pb, Basic remoteEndpoint, String ownerSessionId) {
    this.pb = pb;
    this.remoteEndpoint = remoteEndpoint; 
    this.projPathElem = "/" + String.join("/", Arrays.copyOfRange(wsKeyElem,1,wsKeyElem.length));
    this.lang = lang;
    this.ownerSessionId = ownerSessionId;
}
项目:tomcat7    文件:TesterFirehoseServer.java   
@OnMessage
public void onMessage(Session session, String msg) throws IOException {

    if (started) {
        return;
    }
    synchronized (this) {
        if (started) {
            return;
        } else {
            started = true;
        }
    }

    System.out.println("Received " + msg + ", now sending data");

    session.getUserProperties().put(
            "org.apache.tomcat.websocket.BLOCKING_SEND_TIMEOUT",
            Long.valueOf(SEND_TIME_OUT_MILLIS));

    Basic remote = session.getBasicRemote();
    remote.setBatchingAllowed(true);

    for (int i = 0; i < MESSAGE_COUNT; i++) {
        remote.sendText(MESSAGE);
        if (i % (MESSAGE_COUNT * 0.4) == 0) {
            remote.setBatchingAllowed(false);
            remote.setBatchingAllowed(true);
        }
    }

    // Flushing should happen automatically on session close
    session.close();
}
项目:minijax    文件:HelloWebSocketTest.java   
private Session getSession() {
    final Basic basicRemote = mock(Basic.class);

    final Session session = mock(Session.class);
    when(session.getBasicRemote()).thenReturn(basicRemote);
    return session;
}
项目:apache-tomcat-7.0.73-with-comment    文件:TesterFirehoseServer.java   
@OnMessage
public void onMessage(Session session, String msg) throws IOException {

    if (started) {
        return;
    }
    synchronized (this) {
        if (started) {
            return;
        } else {
            started = true;
        }
    }

    System.out.println("Received " + msg + ", now sending data");

    session.getUserProperties().put(
            "org.apache.tomcat.websocket.BLOCKING_SEND_TIMEOUT",
            Long.valueOf(SEND_TIME_OUT_MILLIS));

    Basic remote = session.getBasicRemote();
    remote.setBatchingAllowed(true);

    for (int i = 0; i < MESSAGE_COUNT; i++) {
        remote.sendText(MESSAGE);
        if (i % (MESSAGE_COUNT * 0.4) == 0) {
            remote.setBatchingAllowed(false);
            remote.setBatchingAllowed(true);
        }
    }

    // Flushing should happen automatically on session close
    session.close();
}
项目:Purifinity    文件:PurifinityServerSocketIT.java   
@Test
   public void test() throws Exception {
Session session = webSocketContainer.connectToServer(this, new URI(
    "ws://localhost:8080/purifinityserver/socket/server"));
try {
    Basic basic = session.getBasicRemote();
    basic.sendText("getStatus");
} finally {
    session.close(new CloseReason(CloseCodes.GOING_AWAY,
        "We are done..."));
}
Thread.sleep(5000);
   }
项目:class-guard    文件:TesterFirehoseServer.java   
@OnMessage
public void onMessage(Session session, String msg) throws IOException {

    if (started) {
        return;
    }
    synchronized (this) {
        if (started) {
            return;
        } else {
            started = true;
        }
    }

    System.out.println("Received " + msg + ", now sending data");

    session.getUserProperties().put(
            "org.apache.tomcat.websocket.BLOCKING_SEND_TIMEOUT",
            Long.valueOf(SEND_TIME_OUT_MILLIS));

    Basic remote = session.getBasicRemote();
    remote.setBatchingAllowed(true);

    for (int i = 0; i < MESSAGE_COUNT; i++) {
        remote.sendText(MESSAGE);
    }

    // Ensure remaining messages are flushed
    remote.setBatchingAllowed(false);
}
项目:apache-tomcat-7.0.57    文件:TesterFirehoseServer.java   
@OnMessage
public void onMessage(Session session, String msg) throws IOException {

    if (started) {
        return;
    }
    synchronized (this) {
        if (started) {
            return;
        } else {
            started = true;
        }
    }

    System.out.println("Received " + msg + ", now sending data");

    session.getUserProperties().put(
            "org.apache.tomcat.websocket.BLOCKING_SEND_TIMEOUT",
            Long.valueOf(SEND_TIME_OUT_MILLIS));

    Basic remote = session.getBasicRemote();
    remote.setBatchingAllowed(true);

    for (int i = 0; i < MESSAGE_COUNT; i++) {
        remote.sendText(MESSAGE);
    }

    // Ensure remaining messages are flushed
    remote.setBatchingAllowed(false);
}
项目:apache-tomcat-7.0.57    文件:TesterFirehoseServer.java   
@OnMessage
public void onMessage(Session session, String msg) throws IOException {

    if (started) {
        return;
    }
    synchronized (this) {
        if (started) {
            return;
        } else {
            started = true;
        }
    }

    System.out.println("Received " + msg + ", now sending data");

    session.getUserProperties().put(
            "org.apache.tomcat.websocket.BLOCKING_SEND_TIMEOUT",
            Long.valueOf(SEND_TIME_OUT_MILLIS));

    Basic remote = session.getBasicRemote();
    remote.setBatchingAllowed(true);

    for (int i = 0; i < MESSAGE_COUNT; i++) {
        remote.sendText(MESSAGE);
    }

    // Ensure remaining messages are flushed
    remote.setBatchingAllowed(false);
}
项目:cloud-language-servers-container    文件:LSPProcessManager.java   
OutputStreamHandler(RemoteEndpoint.Basic remoteEndpointBasic, InputStream out) {
    this.remote = remoteEndpointBasic;
    this.out = out;
}
项目:WhiteboardProject    文件:MessageSender.java   
public void sendMessage(Message message) throws IOException{
    Basic basic= session.getBasicRemote();
    basic.sendText(message.getString());
}
项目:WhiteboardProject    文件:MockWebsocketSession.java   
@Override
public Basic getBasicRemote() {
    Basic basic= new MockBasic();
    return basic;
}
项目:WhiteboardProject    文件:MockMessageSender.java   
public void sendMessage(Message message) throws IOException{
    Basic basic= session.getBasicRemote(); // MockWebsocketSession returns a MockBasic
    basic.sendText(message.getString()); // MockBasic sendText does nothing
}
项目:hawkular-commons    文件:WebSocketHelper.java   
public void sendTextSync(Session session, String text) throws IOException {
    Basic basicRemote = session.getBasicRemote();
    basicRemote.sendText(text);
}
项目:cyberattack-event-collector    文件:FakeSession.java   
public Basic getBasicRemote() {
    // TODO Auto-generated method stub
    return null;
}