public MuxChannel(long channelId, Muxer muxer) { this.channelId = channelId; this.muxer = muxer; this.policy = muxer.getPolicy().clonePolicy(); this.suspendToken = new AtomicBoolean(false); this.ioState = new IOState(); ioState.setState(ConnectionState.CONNECTING); this.inputClosed = new AtomicBoolean(false); this.outputClosed = new AtomicBoolean(false); }
public boolean isOpen() { return (getState() != ConnectionState.CLOSED); }
public boolean isClosed() { return (isInputClosed() && isOutputClosed()); }
/** * Internal * * @param frame * the frame to write * @return the future for the network write of the frame */ private Future<Void> sendAsyncFrame(WebSocketFrame frame) { FutureWriteCallback future = new FutureWriteCallback(); try { connection.getIOState().assertOutputOpen(); outgoing.outgoingFrame(frame,future); } catch (IOException e) { future.writeFailed(e); } return future; }
@Override public void disconnect() { this.ioState.setState(ConnectionState.CLOSED); // TODO: disconnect the virtual end-point? }
public AbstractWebSocketConnection(EndPoint endp, Executor executor, Scheduler scheduler, WebSocketPolicy policy, ByteBufferPool bufferPool) { super(endp,executor); this.id = Long.toString(ID_GEN.incrementAndGet()); this.policy = policy; this.bufferPool = bufferPool; this.generator = new Generator(policy,bufferPool); this.parser = new Parser(policy,bufferPool); this.scheduler = scheduler; this.extensions = new ArrayList<>(); this.suspendToken = new AtomicBoolean(false); this.ioState = new IOState(); this.ioState.addListener(this); this.flusher = new Flusher(bufferPool,generator,endp); this.setInputBufferSize(policy.getInputBufferSize()); this.setMaxIdleTimeout(policy.getIdleTimeout()); }
public boolean isActive() { return (ioState.isOpen()); }
public void assertInputOpen() throws IOException { if (isInputClosed()) { throw new IOException("Connection input is closed"); } }
public void onWriteWebSocketClose() { if (ioState.onCloseHandshake(false)) { disconnect(); } }
public void assertOutputOpen() throws IOException { if (isOutputClosed()) { throw new IOException("Connection output is closed"); } }
public WebSocketSession(WebSocketContainerScope containerScope, URI requestURI, EventDriver websocket, LogicalConnection connection) { Objects.requireNonNull(containerScope,"Container Scope cannot be null"); Objects.requireNonNull(requestURI,"Request URI cannot be null"); this.classLoader = Thread.currentThread().getContextClassLoader(); this.containerScope = containerScope; this.requestURI = requestURI; this.websocket = websocket; this.connection = connection; this.executor = connection.getExecutor(); this.outgoingHandler = connection; this.incomingHandler = websocket; this.connection.getIOState().addListener(this); this.policy = websocket.getPolicy(); this.connection.setSession(this); addBean(this.connection); addBean(this.websocket); }
/** * Internal * * @param frame * the frame to write * @return the future for the network write of the frame */ private Future<Void> sendAsyncFrame(WebSocketFrame frame) { FutureWriteCallback future = new FutureWriteCallback(); try { connection.getIOState().assertOutputOpen(); outgoing.outgoingFrame(frame,future); } catch (IOException e) { future.writeFailed(e); } return future; }
@Override public void disconnect() { this.ioState.setState(ConnectionState.CLOSED); // TODO: disconnect the virtual end-point? }
public boolean isActive() { return (ioState.isOpen()); }
public void assertInputOpen() throws IOException { if (isInputClosed()) { throw new IOException("Connection input is closed"); } }
public void onWriteWebSocketClose() { if (ioState.onCloseHandshake(false)) { disconnect(); } }
public void assertOutputOpen() throws IOException { if (isOutputClosed()) { throw new IOException("Connection output is closed"); } }
public MuxChannel(long channelId, Muxer muxer) { this.channelId = channelId; this.muxer = muxer; this.policy = muxer.getPolicy().clonePolicy(); this.suspendToken = new AtomicBoolean(false); this.ioState = new IOState(); ioState.setState(ConnectionState.CONNECTING); this.inputClosed = new AtomicBoolean(false); this.outputClosed = new AtomicBoolean(false); }
public boolean awaitClosed(long duration) { return (isInputClosed() && isOutputClosed()); }
public void uncheckedSendFrame(WebSocketFrame frame, WriteCallback callback) { try { BatchMode batchMode = BatchMode.OFF; if (frame.isDataFrame()) batchMode = getBatchMode(); connection.getIOState().assertOutputOpen(); outgoing.outgoingFrame(frame, callback, batchMode); } catch (IOException e) { callback.writeFailed(e); } }