@Override public void disconnect() { disconnect(false); }
@Override public void resume() { if (suspendToken.getAndSet(false)) { fillInterested(); } }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; AbstractWebSocketConnection other = (AbstractWebSocketConnection)obj; EndPoint endp = getEndPoint(); EndPoint otherEndp = other.getEndPoint(); if (endp == null) { if (otherEndp != null) return false; } else if (!endp.equals(otherEndp)) return false; return true; }
@Override public void resume() { if (suspendToken.getAndSet(false)) { if (!isReading()) { fillInterested(); } } }
@Override public boolean isOpen() { return getIOState().isOpen() && getEndPoint().isOpen(); }
@Override public void onFillable() { LOG.debug("{} onFillable()",policy.getBehavior()); stats.countOnFillableEvents.incrementAndGet(); ByteBuffer buffer = bufferPool.acquire(getInputBufferSize(),true); BufferUtil.clear(buffer); boolean readMore = false; try { isFilling = true; readMore = (read(buffer) != -1); } finally { bufferPool.release(buffer); } if (readMore && (suspendToken.get() == false)) { fillInterested(); } else { isFilling = false; } }
stats.countOnFillableEvents.incrementAndGet(); ByteBuffer buffer = bufferPool.acquire(getInputBufferSize(),true); readMode = readParse(buffer); readMode = readDiscard(buffer); fillInterested();
private <C> void write(ByteBuffer buffer) { EndPoint endpoint = getEndPoint(); if (!isOpen()) { writeBytes.failAll(new IOException("Connection closed")); return; } try { endpoint.write(writeBytes,buffer); } catch (Throwable t) { writeBytes.failed(t); } } }
private int read(ByteBuffer buffer) EndPoint endPoint = getEndPoint(); try enqueClose(StatusCode.PROTOCOL,e.getMessage()); return -1; enqueClose(e.getStatusCode(),e.getMessage()); return -1;
/** * Override to set the masker. */ @Override public void outgoingFrame(Frame frame, WriteCallback callback, BatchMode batchMode) { if (frame instanceof WebSocketFrame) { masker.setMask((WebSocketFrame)frame); } super.outgoingFrame(frame,callback, batchMode); }
fillInterested(); break; case CLOSED: this.disconnect();
@Override public void onClose() { super.onClose(); this.getIOState().setState(ConnectionState.CLOSED); }
private ReadMode readDiscard(ByteBuffer buffer) EndPoint endPoint = getEndPoint(); try LOG.debug("read - EOF Reached (remote: {})",getRemoteAddress()); return ReadMode.EOF;
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()); }
/** * Event for no activity on connection (read or write) * @return true to signal that the endpoint must be closed, false to keep the endpoint open */ @Override protected boolean onReadTimeout(Throwable timeout) { IOState state = getIOState(); ConnectionState cstate = state.getConnectionState(); if (LOG.isDebugEnabled()) LOG.debug("{} Read Timeout - {}",policy.getBehavior(),cstate); if (cstate == ConnectionState.CLOSED) { if (LOG.isDebugEnabled()) LOG.debug("onReadTimeout - Connection Already CLOSED"); // close already completed, extra timeouts not relevant // allow underlying connection and endpoint to disconnect on its own return true; } try { notifyError(timeout); } finally { // This is an Abnormal Close condition session.close(StatusCode.SHUTDOWN,"Idle Timeout"); } return false; }
public AbstractWebSocketConnection(EndPoint endp, Executor executor, Scheduler scheduler, WebSocketPolicy policy, ByteBufferPool bufferPool) { super(endp,executor,EXECUTE_ONFILLABLE); // TODO review if this is best. Specifically with MUX 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.setState(ConnectionState.CONNECTING); this.writeBytes = new WriteBytesProvider(generator,new FlushCallback()); this.setInputBufferSize(policy.getInputBufferSize()); }
@Override public void close() { close(StatusCode.NORMAL,null); }
@Override public void close(int statusCode, String reason) { enqueClose(statusCode,reason); }
@Override public void succeeded() { // Lets process the next set of bytes... AbstractWebSocketConnection.this.complete(writeBytes); } }
@Override public void onFillable() { LOG.debug("{} onFillable()",policy.getBehavior()); stats.countOnFillableEvents.incrementAndGet(); ByteBuffer buffer = bufferPool.acquire(getInputBufferSize(),true); BufferUtil.clear(buffer); boolean readMore = false; try { isFilling = true; readMore = (read(buffer) != -1); } finally { bufferPool.release(buffer); } if (readMore && (suspendToken.get() == false)) { fillInterested(); } else { isFilling = false; } }