@Override protected void sendPongMessage(PongMessage message) throws IOException { getNativeSession().getBasicRemote().sendPong(message.getPayload()); }
@Override protected void sendPingMessage(PingMessage message) throws IOException { getNativeSession().getBasicRemote().sendPing(message.getPayload()); }
@Override public void onSchema(final Schema schema) { try { session.getBasicRemote().sendText( mapper.writeValueAsString(EntityUtil.buildSourceSchemaEntity(schema)) ); } catch (final IOException e) { log.error("Error sending schema", e); SessionUtil.closeSilently(session, CloseCodes.PROTOCOL_ERROR, "Unable to send schema"); } }
@Override protected void sendTextMessage(TextMessage message) throws IOException { getNativeSession().getBasicRemote().sendText(message.getPayload(), message.isLast()); }
@Override protected void sendBinaryMessage(BinaryMessage message) throws IOException { getNativeSession().getBasicRemote().sendBinary(message.getPayload(), message.isLast()); }
/** * Send a stop message to server as result of user request. */ public void sendMessage( StopMessage stopMessage ) throws KettleException { sessionValid(); try { if ( !alReadySendedStopMessage.getAndSet( true ) ) { this.userSession.getBasicRemote().sendObject( stopMessage ); } } catch ( Exception e ) { throw new KettleException( e ); } }
/** * Send a execution request message. */ public void sendMessage( ExecutionRequest request ) throws KettleException { sessionValid(); try { request.setReuseSparkContext( reuseSparkContext ); this.userSession.getBasicRemote().sendObject( request ); } catch ( Exception e ) { throw new KettleException( e ); } }
session.getBasicRemote().sendText(""); } catch (IOException e) {
remote = session.getBasicRemote();
private void sendText(Session session, String message) { RemoteEndpoint.Basic basic = session.getBasicRemote(); try { basic.sendText(message); } catch (IOException e) { e.printStackTrace(); } }
@Override public void sendBlocking(byte[] data, int start, int length) throws IOException { synchronized (this) { try { websocketSession.getBasicRemote().sendBinary(ByteBuffer.wrap(data, start, length)); } catch (IOException e) { // Ignore } } }
/** * 公共方法:发送信息给所有人 */ private static void sendMessageToAll(String msg) { onlineSessions.forEach((id, session) -> { try { session.getBasicRemote().sendText(msg); } catch (IOException e) { e.printStackTrace(); } }); }
@Override public void sendBlocking(ByteBuffer data) throws IOException { synchronized (this) { try { websocketSession.getBasicRemote().sendBinary(data); } catch (IOException e) { // Ignore } } }
public void sendMessage(String message) throws IOException { this.session.getBasicRemote().sendText(message); } }
public OutputStream getSendStream() throws IOException { return websocketSession.getBasicRemote().getSendStream(); }
private void sendRealTimeLog(Log log) { if (wsSession == null) { return; } try { String format = websocketLogFormat(log); wsSession.getBasicRemote().sendText(format); LogEventHandler.log.debug("Log sent: {}", format); } catch (Throwable e) { LogEventHandler.log.warn("Fail to send real time log to queue"); } }
private void send(Event event) { try { wsSession.getBasicRemote().sendText(event.toJSON()); } catch (IOException e) { e.printStackTrace(); } } }
@Test public void testOnSchema() throws Exception { replayOnSubscribe(); session.getBasicRemote(); EasyMock.expectLastCall().andReturn(basic).once(); final Capture<String> schema = EasyMock.newCapture(); basic.sendText(EasyMock.capture(schema)); EasyMock.expectLastCall().andThrow(new IOException("bad bad io")).once(); final Capture<CloseReason> reason = EasyMock.newCapture(); session.close(EasyMock.capture(reason)); subscription.cancel(); EasyMock.replay(subscription, session, basic); subscriber.onSchema(SchemaBuilder .struct() .field("currency", Schema.STRING_SCHEMA) .field("amount", Schema.OPTIONAL_FLOAT32_SCHEMA) .build()); subscriber.close(); assertEquals( "[" + "{\"name\":\"currency\"," + "\"schema\":{\"type\":\"STRING\",\"fields\":null,\"memberSchema\":null}}," + "{\"name\":\"amount\"," + "\"schema\":{\"type\":\"DOUBLE\",\"fields\":null,\"memberSchema\":null}}]" , schema.getValue()); assertEquals("Unable to send schema", reason.getValue().getReasonPhrase()); assertEquals(CloseCodes.PROTOCOL_ERROR, reason.getValue().getCloseCode()); EasyMock.verify(subscription, session, basic); }
@Override public void send(JsonNode request) { synchronized (this) { if (websocketSession.isOpen()) { try { websocketSession.getBasicRemote().sendText(request.toString()); } catch (Exception e) { // Skip } } else { streamer.onClose(); } } }
@Override public synchronized IWebSocketConnection sendMessage(byte[] message, int offset, int length) throws IOException { checkClosed(); ByteBuffer buf = ByteBuffer.wrap(message, offset, length); session.getBasicRemote().sendBinary(buf); return this; }