/** * {@inheritDoc} */ @Override public WebSocket write(byte[] data, int offset, int length) throws IOException { _write(data, offset, length); return this; }
@Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { future.channel().close(); } else { websocketChannels.add(ctx.channel()); ctx.channel().attr(ATTACHMENT).set(webSocket); if (config.noInternalAlloc()) { webSocket.resource(proxiedResource); } AtmosphereResponse response = config.noInternalAlloc() ? proxiedResponse : AtmosphereResponseImpl.newInstance(framework.getAtmosphereConfig(), atmosphereRequest, webSocket); webSocketProcessor.open(webSocket, atmosphereRequest, response); if (webSocketTimeout > 0) { webSocket.closeFuture(suspendTimer.scheduleAtFixedRate(() -> { if (webSocket.lastWriteTimeStampInMilliseconds() != 0 && (System.currentTimeMillis() - webSocket.lastWriteTimeStampInMilliseconds() > webSocketTimeout)) { logger.debug("Timing out {}", webSocket); webSocket.close(); } }, webSocketTimeout, webSocketTimeout, TimeUnit.MILLISECONDS)); } } } });
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { super.channelInactive(ctx); Object o = ctx.attr(ATTACHMENT).get(); if (o == null) return; if (WebSocket.class.isAssignableFrom(o.getClass())) { NettyWebSocket webSocket = NettyWebSocket.class.cast(o); logger.trace("Closing {}", webSocket.uuid()); try { if (webSocket.closeFuture() != null) { webSocket.closeFuture().cancel(true); } webSocketProcessor.close(webSocket, 1005); } catch (Exception ex) { logger.error("{}", webSocket, ex); } } else if (State.class.isAssignableFrom(o.getClass())) { logger.trace("State {}", o); State s = State.class.cast(o); if (s.action.type() == Action.TYPE.SUSPEND) { asynchronousProcessor.endRequest(s.resource(), true); } } else { logger.warn("Invalid state {} and Channel {}", o, ctx.channel()); } }
wsFactory.sendUnsupportedVersionResponse(ctx.channel()); } else { final NettyWebSocket webSocket = new NettyWebSocket(ctx.channel(), framework.getAtmosphereConfig(), config.noInternalAlloc(), config.binaryWrite()); final AtmosphereRequest atmosphereRequest = createAtmosphereRequest(ctx, request, EMPTY);
@Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { future.channel().close(); } else { websocketChannels.add(ctx.channel()); ctx.channel().attr(ATTACHMENT).set(webSocket); if (config.noInternalAlloc()) { webSocket.resource(proxiedResource); } AtmosphereResponse response = config.noInternalAlloc() ? proxiedResponse : AtmosphereResponseImpl.newInstance(framework.getAtmosphereConfig(), atmosphereRequest, webSocket); webSocketProcessor.open(webSocket, atmosphereRequest, response); if (webSocketTimeout > 0) { webSocket.closeFuture(suspendTimer.scheduleAtFixedRate(() -> { if (webSocket.lastWriteTimeStampInMilliseconds() != 0 && (System.currentTimeMillis() - webSocket.lastWriteTimeStampInMilliseconds() > webSocketTimeout)) { logger.debug("Timing out {}", webSocket); webSocket.close(); } }, webSocketTimeout, webSocketTimeout, TimeUnit.MILLISECONDS)); } } } });
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { super.channelInactive(ctx); Object o = ctx.attr(ATTACHMENT).get(); if (o == null) return; if (WebSocket.class.isAssignableFrom(o.getClass())) { NettyWebSocket webSocket = NettyWebSocket.class.cast(o); logger.trace("Closing {}", webSocket.uuid()); try { if (webSocket.closeFuture() != null) { webSocket.closeFuture().cancel(true); } webSocketProcessor.close(webSocket, 1005); } catch (Exception ex) { logger.error("{}", webSocket, ex); } } else if (State.class.isAssignableFrom(o.getClass())) { logger.trace("State {}", o); State s = State.class.cast(o); if (s.action.type() == Action.TYPE.SUSPEND) { asynchronousProcessor.endRequest(s.resource(), true); } } else { logger.warn("Invalid state {} and Channel {}", o, ctx.channel()); } }
wsFactory.sendUnsupportedVersionResponse(ctx.channel()); } else { final NettyWebSocket webSocket = new NettyWebSocket(ctx.channel(), framework.getAtmosphereConfig(), config.noInternalAlloc(), config.binaryWrite()); final AtmosphereRequest atmosphereRequest = createAtmosphereRequest(ctx, request, EMPTY);
public WebSocket write(byte[] data) throws IOException { _write(data, 0, data.length); return this; }
/** * {@inheritDoc} */ @Override public WebSocket write(byte[] data, int offset, int length) throws IOException { _write(data, offset, length); return this; }
public WebSocket write(byte[] data) throws IOException { _write(data, 0, data.length); return this; }