@Override public SocketAddress clientAddress() { return getEndPoint().getRemoteAddress(); }
@Override public SocketAddress serverAddress() { return getEndPoint().getLocalAddress(); }
@Override public Connection newConnection(Connector connector, EndPoint endPoint) { final Connection connection = connectionFactory.newConnection(connector, endPoint); connection.addListener( new Connection.Listener() { @Override public void onOpened(Connection connection) { activeConns.incrementAndGet(); } @Override public void onClosed(Connection connection) { activeConns.decrementAndGet(); } } ); return connection; } }
ByteArrayBuffer buffer; try { buffer = new ByteArrayBuffer(getRequestMessage().getBodyString(), charset); } catch (UnsupportedEncodingException ex) { throw new RuntimeException("Unsupported character encoding: " + charset, ex); setRequestHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(buffer.length())); setRequestContent(buffer); buffer = new ByteArrayBuffer(getRequestMessage().getBodyBytes()); setRequestHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(buffer.length())); setRequestContent(buffer);
@Override public void close() { // Gentler close for SSL. getEndPoint().shutdownOutput(); super.close(); } }
@Override public void failed(Throwable x) { bufs.release(buf); } }
protected LocationEntry(String name, boolean inclusive) { super(name, inclusive); if (!getName().startsWith("file:")) throw new IllegalArgumentException(name); try { _file = Resource.newResource(getName()).getFile(); } catch(IOException e) { throw new RuntimeIOException(e); } }
private ByteBuffer acquire() { final ByteBuffer b = bufs.acquire(BUF_SIZE, false); b.limit(b.capacity()); return b; } }
@Override public void afterPropertiesSet() throws Exception { String name = this.threadPrefix + "@" + Integer.toHexString(hashCode()); if (this.executor == null) { QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setName(name); this.executor = threadPool; } if (this.byteBufferPool == null) { this.byteBufferPool = new MappedByteBufferPool(2048, this.executor instanceof ThreadPool.SizedThreadPool ? ((ThreadPool.SizedThreadPool) executor).getMaxThreads() / 2 : ProcessorUtils.availableProcessors() * 2); } if (this.scheduler == null) { this.scheduler = new ScheduledExecutorScheduler(name + "-scheduler", false); } if (this.executor instanceof LifeCycle) { ((LifeCycle)this.executor).start(); } this.scheduler.start(); }
public static boolean isConnectionOpen(HttpServletRequest request, byte[] heartbeat) { Request jettyRequest = (Request)request; AbstractHttpConnection connection = jettyRequest.getConnection(); Socket socket = (Socket)connection.getEndPoint().getTransport(); if (log.isLoggable(Level.FINE)) log.fine("Checking if client connection is still open: " + socket.getRemoteSocketAddress()); try { socket.getOutputStream().write(heartbeat); socket.getOutputStream().flush(); return true; } catch (IOException ex) { if (log.isLoggable(Level.FINE)) log.fine("Client connection has been closed: " + socket.getRemoteSocketAddress()); return false; } }
protected ByteBufferPool buildBufferPool() { return new ArrayByteBufferPool((int) minBufferPoolSize.toBytes(), (int) bufferPoolIncrement.toBytes(), (int) maxBufferPoolSize.toBytes()); } }
ByteArrayBuffer buffer; try { buffer = new ByteArrayBuffer(getRequestMessage().getBodyString(), charset); } catch (UnsupportedEncodingException ex) { throw new RuntimeException("Unsupported character encoding: " + charset, ex); setRequestHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(buffer.length())); setRequestContent(buffer); buffer = new ByteArrayBuffer(getRequestMessage().getBodyBytes()); setRequestHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(buffer.length())); setRequestContent(buffer);
@Override public void succeeded() { bufs.release(buf); }
@Override public void onContent(Response response, ByteBuffer buf) { final ByteBufferPool bufs = client.getByteBufferPool(); final ByteBuffer copy = bufs.acquire(buf.remaining(), false); copy.limit(buf.remaining()); copy.put(buf); copy.flip(); stream.offer(copy, new ReleaseCallback(bufs, copy)); }
@Override public void afterPropertiesSet() throws Exception { String name = this.threadPrefix + "@" + Integer.toHexString(hashCode()); if (this.executor == null) { QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setName(name); this.executor = threadPool; } if (this.byteBufferPool == null) { this.byteBufferPool = new MappedByteBufferPool(2048, this.executor instanceof ThreadPool.SizedThreadPool ? ((ThreadPool.SizedThreadPool) executor).getMaxThreads() / 2 : ProcessorUtils.availableProcessors() * 2); } if (this.scheduler == null) { this.scheduler = new ScheduledExecutorScheduler(name + "-scheduler", false); } if (this.executor instanceof LifeCycle) { ((LifeCycle)this.executor).start(); } this.scheduler.start(); }
public static boolean isConnectionOpen(HttpServletRequest request, byte[] heartbeat) { Request jettyRequest = (Request)request; AbstractHttpConnection connection = jettyRequest.getConnection(); Socket socket = (Socket)connection.getEndPoint().getTransport(); if (log.isLoggable(Level.FINE)) log.fine("Checking if client connection is still open: " + socket.getRemoteSocketAddress()); try { socket.getOutputStream().write(heartbeat); socket.getOutputStream().flush(); return true; } catch (IOException ex) { if (log.isLoggable(Level.FINE)) log.fine("Client connection has been closed: " + socket.getRemoteSocketAddress()); return false; } }
public Connection newConnection(Connector connector, EndPoint endPoint) { Connection connection = super.newConnection(connector, endPoint); connection.addListener(new Connection.Listener() { public void onOpened(Connection connection) { openConnection(); } public void onClosed(Connection connection) { closeConnection(); } }); return connection; } };
ArmeriaConnector(Server server) { this.server = server; executor = server.getThreadPool(); final HttpConfiguration httpConfig = server.getBean(HttpConfiguration.class); this.httpConfig = httpConfig != null ? httpConfig : new HttpConfiguration(); final Scheduler scheduler = server.getBean(Scheduler.class); this.scheduler = scheduler != null ? scheduler : new ScheduledExecutorScheduler(); final ByteBufferPool byteBufferPool = server.getBean(ByteBufferPool.class); this.byteBufferPool = byteBufferPool != null ? byteBufferPool : new ArrayByteBufferPool(); addBean(server, false); addBean(executor); unmanage(executor); addBean(this.httpConfig); addBean(this.scheduler); addBean(this.byteBufferPool); connectionFactory = new ArmeriaConnectionFactory(); connectionFactories = Collections.singleton(connectionFactory); }
@Override public void flush() { checkClose(); buf.flip(); if (buf.limit() == 0) { bufs.release(buf); return; } out.offer(buf, new ReleaseCallback(bufs, buf)); buf = acquire(); }
@Override public Connection newConnection(Connector connector, EndPoint endPoint) { final Connection connection = connectionFactory.newConnection(connector, endPoint); connection.addListener(new Connection.Listener() { @Nullable private Timer.Context context; @Override public void onOpened(Connection connection) { this.context = timer.time(); } @Override public void onClosed(Connection connection) { requireNonNull(context).stop(); } }); return connection; } }