@Override public void handleClosed() { synchronized (this) { closed = true; } super.handleClosed(); }
public void reportBytesRead(long numberOfBytes) { NetworkMetrics metrics = metrics(); if (metrics != null) { metrics.bytesRead(metric(), remoteAddress(), numberOfBytes); } }
public final ChannelFuture sendFile(RandomAccessFile raf, long offset, long length) throws IOException { // Write the content. ChannelPromise writeFuture = chctx.newPromise(); if (!supportsFileRegion()) { // Cannot use zero-copy writeToChannel(new ChunkedFile(raf, offset, length, 8192), writeFuture); } else { // No encryption - use zero-copy. sendFileRegion(raf, offset, length, writeFuture); } if (writeFuture != null) { writeFuture.addListener(fut -> raf.close()); } else { raf.close(); } return writeFuture; }
protected synchronized void handleException(Throwable t) { NetworkMetrics metrics = metrics(); if (metrics != null) { metrics.exceptionOccurred(metric, remoteAddress(), t); } if (exceptionHandler != null) { exceptionHandler.handle(t); } else { if (log.isDebugEnabled()) { log.error(t.getMessage(), t); } else { log.error(t.getMessage()); } } }
public void writeToChannel(Object obj) { writeToChannel(obj, voidPromise); }
writeToChannel(new DefaultFileRegion(file.getChannel(), offset, length), writeFuture); } else { ChannelPromise promise = chctx.newPromise(); writeToChannel(region, promise); promise.addListener(future -> { if (future.isSuccess()) { sendFileRegion(file, offset + MAX_REGION_SIZE, length - MAX_REGION_SIZE, writeFuture); } else { future.cause().printStackTrace();
protected void complete(Response response) { DefaultHttpSocketMetric httpSocketMetric = (DefaultHttpSocketMetric) ((ConnectionBase) clientRequest.connection()) .metric(); invocation.getInvocationStageTrace().finishGetConnection(httpSocketMetric.getRequestBeginTime()); invocation.getInvocationStageTrace().finishWriteToBuffer(httpSocketMetric.getRequestEndTime()); invocation.getInvocationStageTrace().finishClientFiltersResponse(); asyncResp.complete(response); }
private void actualClose(final ContextInternal closeContext, final Handler<AsyncResult<Void>> done) { if (id != null) { vertx.sharedHttpServers().remove(id); } ContextInternal currCon = vertx.getContext(); for (ConnectionBase conn : connectionMap.values()) { conn.close(); } // Sanity check if (vertx.getContext() != currCon) { throw new IllegalStateException("Context was changed"); } if (metrics != null) { metrics.close(); } ChannelGroupFuture fut = serverChannelGroup.close(); fut.addListener(cgf -> executeCloseDone(closeContext, done, fut.cause())); }
public static Context getConnectionContext(ConnectionBase connection) { return connection.getContext(); } }
httpServer.requestHandler(mainRouter::accept); httpServer.connectionHandler(connection -> { DefaultHttpServerMetrics serverMetrics = (DefaultHttpServerMetrics) ((ConnectionBase) connection).metrics(); DefaultServerEndpointMetric endpointMetric = serverMetrics.getEndpointMetric(); long connectedCount = endpointMetric.getCurrentConnectionCount();
@Override public Http1xConnectionBase exceptionHandler(Handler<Throwable> handler) { return (Http1xConnectionBase) super.exceptionHandler(handler); }
@Override public Http1xConnectionBase closeHandler(Handler<Void> handler) { return (Http1xConnectionBase) super.closeHandler(handler); }
@Override protected void handleException(Throwable t) { super.handleException(t); Handler<Throwable> handler; synchronized (DatagramSocketImpl.this) { handler = exceptionHandler; } if (handler != null) { handler.handle(t); } }
/** * Set the connection, this is called when the channel is added to the pipeline. * * @param connection the connection */ private void setConnection(C connection) { conn = connection; endReadAndFlush = v -> conn.endReadAndFlush(); messageHandler = ((ConnectionBase)conn)::handleRead; // Dubious cast to make compiler happy if (addHandler != null) { addHandler.handle(connection); } }
@Override public synchronized NetSocketInternal writeMessage(Object message) { if (closed) { throw new IllegalStateException("Socket is closed"); } super.writeToChannel(message); return this; }
protected synchronized void handleException(Throwable t) { NetworkMetrics metrics = metrics(); if (metrics != null) { metrics.exceptionOccurred(metric, remoteAddress(), t); } if (exceptionHandler != null) { exceptionHandler.handle(t); } else { if (log.isDebugEnabled()) { log.error(t.getMessage(), t); } else { log.error(t.getMessage()); } } }
writeToChannel(new DefaultFileRegion(file.getChannel(), offset, length), writeFuture); } else { ChannelPromise promise = chctx.newPromise(); writeToChannel(region, promise); promise.addListener(future -> { if (future.isSuccess()) { sendFileRegion(file, offset + MAX_REGION_SIZE, length - MAX_REGION_SIZE, writeFuture); } else { future.cause().printStackTrace();
protected void fail(Throwable e) { if (invocation.isFinished()) { return; } InvocationStageTrace stageTrace = invocation.getInvocationStageTrace(); ConnectionBase connection = (ConnectionBase) clientRequest.connection(); // connection maybe null when exception happens such as ssl handshake failure if (connection != null) { DefaultHttpSocketMetric httpSocketMetric = (DefaultHttpSocketMetric) connection.metric(); stageTrace.finishGetConnection(httpSocketMetric.getRequestBeginTime()); stageTrace.finishWriteToBuffer(httpSocketMetric.getRequestEndTime()); } // even failed and did not received response, still set time for it // that will help to know the real timeout time if (stageTrace.getFinishReceiveResponse() == 0) { stageTrace.finishReceiveResponse(); } if (stageTrace.getStartClientFiltersResponse() == 0) { stageTrace.startClientFiltersResponse(); } stageTrace.finishClientFiltersResponse(); asyncResp.fail(invocation.getInvocationType(), e); }
private void actualClose(final ContextInternal closeContext, final Handler<AsyncResult<Void>> done) { if (id != null) { vertx.sharedHttpServers().remove(id); } ContextInternal currCon = vertx.getContext(); for (ConnectionBase conn : connectionMap.values()) { conn.close(); } // Sanity check if (vertx.getContext() != currCon) { throw new IllegalStateException("Context was changed"); } if (metrics != null) { metrics.close(); } ChannelGroupFuture fut = serverChannelGroup.close(); fut.addListener(cgf -> executeCloseDone(closeContext, done, fut.cause())); }
public static Context getConnectionContext(ConnectionBase connection) { return connection.getContext(); } }