@Override public Object goAwayMessage() { return new TextWebSocketFrame("_CLOSE_"); }
@Override public Future<Void> sendTextFrame(String payload, boolean finalFragment, int rsv) { return channel.writeAndFlush(new TextWebSocketFrame(finalFragment, rsv, payload)); }
@Override public ChannelFuture sendPushMessage(ChannelHandlerContext ctx, ByteBuf mesg) { final TextWebSocketFrame wsf = new TextWebSocketFrame(mesg); return ctx.channel().writeAndFlush(wsf); }
@Override public Future<Void> sendTextFrame(ByteBuf payload, boolean finalFragment, int rsv) { return channel.writeAndFlush(new TextWebSocketFrame(finalFragment, rsv, payload)); }
public void message(String value) { ctx.writeAndFlush(new TextWebSocketFrame(value)); }
public void message(String value) { ctx.writeAndFlush(new TextWebSocketFrame(value)); }
private void sendMessage(ChannelHandlerContext ctx, ImmutableMap<String, Object> message) throws JsonProcessingException { ctx.channel().writeAndFlush(new TextWebSocketFrame( objectMapper.writeValueAsString(message) )); }
@Override public Object goAwayMessage() { return new TextWebSocketFrame("_CLOSE_"); }
/** * Send text to the server. * * @param text text need to be sent. */ public void sendText(String text) { if (channel == null) { LOGGER.debug("Channel is null. Cannot send text."); throw new IllegalArgumentException("Cannot find the channel to write"); } channel.writeAndFlush(new TextWebSocketFrame(text)); }
@Override public Object toFrame(Channel channel) { byte[] json = Json.JSON.toJson(this).getBytes(Constants.UTF_8); return new TextWebSocketFrame(Unpooled.wrappedBuffer(json)); }
@Override public void sendText(final String data, final SuccessCallback success, final OnError err) { ctx.channel().writeAndFlush(new TextWebSocketFrame(data)) .addListener(listener(success, err)); }
@Override public void sendText(final ByteBuffer data, final SuccessCallback success, final OnError err) { ByteBuf buffer = Unpooled.wrappedBuffer(data); ctx.channel().writeAndFlush(new TextWebSocketFrame(buffer)) .addListener(listener(success, err)); }
@Override public void sendText(final byte[] data, final SuccessCallback success, final OnError err) { ByteBuf buffer = Unpooled.wrappedBuffer(data); ctx.channel().writeAndFlush(new TextWebSocketFrame(buffer)) .addListener(listener(success, err)); }
@Override public ChannelFuture sendPushMessage(ChannelHandlerContext ctx, ByteBuf mesg) { final TextWebSocketFrame wsf = new TextWebSocketFrame(mesg); return ctx.channel().writeAndFlush(wsf); }
@Override public TextWebSocketFrame replace(ByteBuf content) { return new TextWebSocketFrame(isFinalFragment(), rsv(), content); }
@Override protected WebSocketFrame beginAggregation(WebSocketFrame start, ByteBuf content) throws Exception { if (start instanceof TextWebSocketFrame) { return new TextWebSocketFrame(true, start.rsv(), content); } if (start instanceof BinaryWebSocketFrame) { return new BinaryWebSocketFrame(true, start.rsv(), content); } // Should not reach here. throw new Error(); } }
public void sendClientMessage(String clientId, HttpRequest httpRequest) { try { if (clientRegistry.containsKey(clientId)) { clientRegistry.get(clientId).channel().writeAndFlush(new TextWebSocketFrame(webSocketMessageSerializer.serialize(httpRequest))); } } catch (Exception e) { throw new WebSocketException("Exception while sending web socket message " + httpRequest + " to client " + clientId, e); } }
void registerClient(String clientId, ChannelHandlerContext ctx) { try { ctx.channel().writeAndFlush(new TextWebSocketFrame(webSocketMessageSerializer.serialize(new WebSocketClientIdDTO().setClientId(clientId)))); } catch (Exception e) { throw new WebSocketException("Exception while sending web socket registration client id message to client " + clientId, e); } clientRegistry.put(clientId, ctx); Metrics.set(WEBSOCKET_CALLBACK_CLIENT_COUNT, clientRegistry.size()); }
WebSocketFrame encodeFrame(WebSocketFrameImpl frame) { ByteBuf buf = frame.getBinaryData(); if (buf != Unpooled.EMPTY_BUFFER) { buf = safeBuffer(buf, chctx.alloc()); } switch (frame.type()) { case BINARY: return new BinaryWebSocketFrame(frame.isFinal(), 0, buf); case TEXT: return new TextWebSocketFrame(frame.isFinal(), 0, buf); case CLOSE: return new CloseWebSocketFrame(true, 0, buf); case CONTINUATION: return new ContinuationWebSocketFrame(frame.isFinal(), 0, buf); case PONG: return new PongWebSocketFrame(buf); case PING: return new PingWebSocketFrame(buf); default: throw new IllegalStateException("Unsupported websocket msg " + frame); } }
protected WebSocketFrame toFrame(WebSocketMessage message) { ByteBuf byteBuf = NettyDataBufferFactory.toByteBuf(message.getPayload()); if (WebSocketMessage.Type.TEXT.equals(message.getType())) { return new TextWebSocketFrame(byteBuf); } else if (WebSocketMessage.Type.BINARY.equals(message.getType())) { return new BinaryWebSocketFrame(byteBuf); } else if (WebSocketMessage.Type.PING.equals(message.getType())) { return new PingWebSocketFrame(byteBuf); } else if (WebSocketMessage.Type.PONG.equals(message.getType())) { return new PongWebSocketFrame(byteBuf); } else { throw new IllegalArgumentException("Unexpected message type: " + message.getType()); } }