public void failAll(Throwable t) { synchronized (this) { if (isFailed()) { // already failed. return; } failure = t; for (FrameEntry fe : queue) { notifyFailure(fe.callback); } queue.clear(); // notify flush callback flushCallback.failed(failure); } }
if (writeBytes.isFailed()) writeBytes.failAll(new WebSocketException("Connection closed")); return; buffer = writeBytes.getByteBuffer();
/** * Write of ByteBuffer failed. * * @param cause * the cause of the failure */ @Override public void failed(Throwable cause) { failAll(cause); }
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 String toString() { StringBuilder b = new StringBuilder(); b.append("WriteBytesProvider["); b.append("flushCallback=").append(flushCallback); if (isFailed()) { b.append(",FAILURE=").append(failure.getClass().getName()); b.append(",").append(failure.getMessage()); } else { b.append(",active=").append(active); b.append(",queue.size=").append(queue.size()); } b.append(']'); return b.toString(); } }
/** * Frame from API, User, or Internal implementation destined for network. */ @Override public void outgoingFrame(Frame frame, WriteCallback callback) { if (LOG.isDebugEnabled()) { LOG.debug("outgoingFrame({}, {})",frame,callback); } if (!isOpen()) { return; } synchronized (writeBytes) { writeBytes.enqueue(frame,WriteCallbackWrapper.wrap(callback)); } flush(); }
/** * Enqueue a close frame. * * @param statusCode * the WebSocket status code. * @param reason * the (optional) reason string. (null is allowed) * @see StatusCode */ private void enqueClose(int statusCode, String reason) { synchronized (writeBytes) { // It is possible to get close events from many different sources. // Make sure we only sent 1 over the network. if (writeBytes.isClosed()) { // already sent the close return; } } CloseInfo close = new CloseInfo(statusCode,reason); // TODO: create DisconnectCallback? outgoingFrame(close.asFrame(),new OnCloseCallback()); }
if (writeBytes.isFailed()) writeBytes.failAll(new WebSocketException("Connection closed")); return; buffer = writeBytes.getByteBuffer();
/** * Write of ByteBuffer failed. * * @param cause * the cause of the failure */ @Override public void failed(Throwable cause) { failAll(cause); }
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 String toString() { StringBuilder b = new StringBuilder(); b.append("WriteBytesProvider["); b.append("flushCallback=").append(flushCallback); if (isFailed()) { b.append(",FAILURE=").append(failure.getClass().getName()); b.append(",").append(failure.getMessage()); } else { b.append(",active=").append(active); b.append(",queue.size=").append(queue.size()); } b.append(']'); return b.toString(); } }
/** * Frame from API, User, or Internal implementation destined for network. */ @Override public void outgoingFrame(Frame frame, WriteCallback callback) { if (LOG.isDebugEnabled()) { LOG.debug("outgoingFrame({}, {})",frame,callback); } if (!isOpen()) { return; } synchronized (writeBytes) { writeBytes.enqueue(frame,WriteCallbackWrapper.wrap(callback)); } flush(); }
/** * Enqueue a close frame. * * @param statusCode * the WebSocket status code. * @param reason * the (optional) reason string. (null is allowed) * @see StatusCode */ private void enqueClose(int statusCode, String reason) { synchronized (writeBytes) { // It is possible to get close events from many different sources. // Make sure we only sent 1 over the network. if (writeBytes.isClosed()) { // already sent the close return; } } CloseInfo close = new CloseInfo(statusCode,reason); // TODO: create DisconnectCallback? outgoingFrame(close.asFrame(),new OnCloseCallback()); }
public void failAll(Throwable t) { synchronized (this) { if (isFailed()) { // already failed. return; } failure = t; for (FrameEntry fe : queue) { notifyFailure(fe.callback); } queue.clear(); // notify flush callback flushCallback.failed(failure); } }
if (isFailed()) notifyFailure(callback); return;
if (isFailed()) notifyFailure(callback); return;