private void releaseBufferedFrames() { if (bufferedFrames != null) { for (WebSocketFrame frame : bufferedFrames) { frame.release(); } bufferedFrames = null; } }
public static DefaultWebSocketMessage getWebSocketMessage(WebSocketFrame frame, String text, boolean isFinalFragment) { DefaultWebSocketMessage webSocketTextMessage = new DefaultWebSocketTextMessage(text, isFinalFragment); frame.release(); return webSocketTextMessage; }
public static DefaultWebSocketMessage getWebSocketMessage(WebSocketFrame webSocketFrame, ByteBuf content, boolean finalFragment) { ByteBuffer clonedContent = getClonedByteBuf(content); DefaultWebSocketMessage webSocketBinaryMessage = new DefaultWebSocketBinaryMessage(clonedContent, finalFragment); webSocketFrame.release(); return webSocketBinaryMessage; }
private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame msg) throws Exception { if (log.isDebugEnabled()) log.debug("Received {} WebSocketFrame: {} from channel: {}", getTransportType().getName(), msg, ctx.channel()); if (msg instanceof CloseWebSocketFrame) { sessionIdByChannel.remove(ctx.channel()); ChannelFuture f = ctx.writeAndFlush(msg); f.addListener(ChannelFutureListener.CLOSE); } else if (msg instanceof PingWebSocketFrame) { ctx.writeAndFlush(new PongWebSocketFrame(msg.content())); } else if (msg instanceof TextWebSocketFrame || msg instanceof BinaryWebSocketFrame){ Packet packet = PacketDecoder.decodePacket(msg.content()); packet.setTransportType(getTransportType()); String sessionId = sessionIdByChannel.get(ctx.channel()); packet.setSessionId(sessionId); msg.release(); ctx.fireChannelRead(packet); } else { msg.release(); log.warn("{} frame type is not supported", msg.getClass().getName()); } }
public static WebSocketControlMessage getWebSocketControlMessage(WebSocketFrame webSocketFrame, WebSocketControlSignal controlSignal) { ByteBuf content = webSocketFrame.content(); ByteBuffer clonedContent = getClonedByteBuf(content); WebSocketControlMessage webSocketControlMessage = new DefaultWebSocketControlMessage(controlSignal, clonedContent); webSocketFrame.release(); return webSocketControlMessage; }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception{ if(msg instanceof WebSocketFrame){ WebSocketFrame frame = (WebSocketFrame)msg; try{ if(frame instanceof TextWebSocketFrame || frame instanceof BinaryWebSocketFrame){ if(listener!=null){ MessageType type = frame instanceof TextWebSocketFrame ? MessageType.text : MessageType.binary; is.reset(frame.content()); listener.onMessage(this, type, is); } }else if(frame instanceof PingWebSocketFrame) ctx.write(new PongWebSocketFrame(frame.content().retain())); else if(frame instanceof CloseWebSocketFrame) handshaker.close(ctx.channel(), (CloseWebSocketFrame)frame.retain()); }finally{ frame.release(); } }else ctx.fireChannelRead(msg); }
TextWebSocketFrame textWebSocketFrame = (TextWebSocketFrame) frame; handler.onMessage(new DefaultWebSocketMessage<>(webSocket, textWebSocketFrame.text(), openResult)); frame.release();