@Override public void onClose(final DataFrame frame) { if (state.compareAndSet(State.CONNECTED, State.CLOSING)) { final ClosingFrame closing = (ClosingFrame) frame; protocolHandler.close(closing.getCode(), closing.getTextPayload()); } else { state.set(State.CLOSED); protocolHandler.doClose(); } WebSocketListener listener; while ((listener = listeners.poll()) != null) { listener.onClose(this, frame); } }
protected byte[] toRawData(byte[] binary, boolean last) { final DataFrame dataFrame = protocolHandler.toDataFrame(binary, last); return protocolHandler.frame(dataFrame); }
protocolHandler.setFilterChainContext(ctx); protocolHandler.setConnection(connection); protocolHandler.setMappingData(reg.mappingData); WebSocketHolder.set(connection, protocolHandler, socket); holder.application = app; protocolHandler.handshake(ctx, app, requestContent); request.getConnection().addCloseListener(new GenericCloseListener() { @Override
final FilterChainContext ctx = protocolHandler.getFilterChainContext(); protocolHandler.getMappingData();
context.protocolHandler.setConnection(ctx.getConnection()); final GrizzlyWebSocketAdapter webSocketAdapter = createWebSocketAdapter(context);
@SuppressWarnings("unchecked") protected void sendRaw(byte[] rawData) { final Connection connection = protocolHandler.getConnection(); final MemoryManager mm = connection.getTransport().getMemoryManager(); final Buffer buffer = Buffers.wrap(mm, rawData); buffer.allowBufferDispose(false); connection.write(buffer); }
public HandShake handshake(FilterChainContext ctx, WebSocketApplication app, HttpContent request) { final HandShake handshake = createServerHandShake(request); app.handshake(handshake); final HttpResponsePacket response = ((HttpRequestPacket) request.getHttpHeader()).getResponse(); handshake.respond(ctx, app, response); return handshake; }
@Override public void close(int code, String reason) { if (state.compareAndSet(State.CONNECTED, State.CLOSING)) { protocolHandler.close(code, reason); } }
/** * Handle Grizzly {@link Connection} write phase. If the {@link Connection} has associated {@link WebSocket} object * (websocket connection), we assume that message is websocket {@link DataFrame} and serialize it into a {@link * Buffer}. * * @param ctx {@link FilterChainContext} * * @return {@link NextAction} instruction for {@link FilterChain}, how it should continue the execution * * @throws java.io.IOException */ @Override public NextAction handleWrite(FilterChainContext ctx) throws IOException { // get the associated websocket final WebSocket websocket = getWebSocket(ctx.getConnection()); final Object msg = ctx.getMessage(); // if there is one if (websocket != null && DataFrame.isDataFrame(msg)) { final DataFrame frame = (DataFrame) msg; final WebSocketHolder holder = WebSocketHolder.get(ctx.getConnection()); final Buffer wrap = Buffers.wrap(ctx.getMemoryManager(), holder.handler.frame(frame)); ctx.setMessage(wrap); } // invoke next filter in the chain return ctx.getInvokeAction(); }
protected void utf8Decode(boolean finalFragment, byte[] data, DataFrame dataFrame) { final ByteBuffer b = getByteBuffer(data); int n = (int) (b.remaining() * currentDecoder.averageCharsPerByte()); CharBuffer cb = CharBuffer.allocate(n);
protocolHandler.setFilterChainContext(ctx); protocolHandler.setConnection(connection); protocolHandler.setMappingData(reg.mappingData); WebSocketHolder.set(connection, protocolHandler, socket); holder.application = app; protocolHandler.handshake(ctx, app, requestContent); request.getConnection().addCloseListener(new GenericCloseListener() { @Override
final FilterChainContext ctx = protocolHandler.getFilterChainContext(); protocolHandler.getMappingData();
context.protocolHandler.setConnection(ctx.getConnection()); final GrizzlyWebSocketAdapter webSocketAdapter = createWebSocketAdapter(context); context.webSocket = webSocketAdapter;
@SuppressWarnings("unchecked") protected void sendRaw(byte[] rawData) { final Connection connection = protocolHandler.getConnection(); final MemoryManager mm = connection.getTransport().getMemoryManager(); final Buffer buffer = Buffers.wrap(mm, rawData); buffer.allowBufferDispose(false); connection.write(buffer); }
public HandShake handshake(FilterChainContext ctx, WebSocketApplication app, HttpContent request) { final HandShake handshake = createServerHandShake(request); app.handshake(handshake); final HttpResponsePacket response = ((HttpRequestPacket) request.getHttpHeader()).getResponse(); handshake.respond(ctx, app, response); return handshake; }
@Override public void close(int code, String reason) { if (state.compareAndSet(State.CONNECTED, State.CLOSING)) { protocolHandler.close(code, reason); } }
/** * Handle Grizzly {@link Connection} write phase. If the {@link Connection} has associated {@link WebSocket} object * (websocket connection), we assume that message is websocket {@link DataFrame} and serialize it into a {@link * Buffer}. * * @param ctx {@link FilterChainContext} * * @return {@link NextAction} instruction for {@link FilterChain}, how it should continue the execution * * @throws java.io.IOException */ @Override public NextAction handleWrite(FilterChainContext ctx) throws IOException { // get the associated websocket final WebSocket websocket = getWebSocket(ctx.getConnection()); final Object msg = ctx.getMessage(); // if there is one if (websocket != null && DataFrame.isDataFrame(msg)) { final DataFrame frame = (DataFrame) msg; final WebSocketHolder holder = WebSocketHolder.get(ctx.getConnection()); final Buffer wrap = Buffers.wrap(ctx.getMemoryManager(), holder.handler.frame(frame)); ctx.setMessage(wrap); } // invoke next filter in the chain return ctx.getInvokeAction(); }
protected void utf8Decode(boolean finalFragment, byte[] data, DataFrame dataFrame) { final ByteBuffer b = getByteBuffer(data); int n = (int) (b.remaining() * currentDecoder.averageCharsPerByte()); CharBuffer cb = CharBuffer.allocate(n);
protocolHandler.setFilterChainContext(ctx); protocolHandler.setConnection(connection); protocolHandler.setMappingData(reg.mappingData); WebSocketHolder.set(connection, protocolHandler, socket); holder.application = app; protocolHandler.handshake(ctx, app, requestContent); request.getConnection().addCloseListener(new GenericCloseListener() { @Override
protected byte[] toRawData(byte[] binary, boolean last) { final DataFrame dataFrame = protocolHandler.toDataFrame(binary, last); return protocolHandler.frame(dataFrame); }