Refine search
@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; } }
@Override public void upgrade(Connection newConnection) { Connection old_connection = getConnection(); if (LOG.isDebugEnabled()) LOG.debug("{} upgrading from {} to {}", this, old_connection, newConnection); ByteBuffer prefilled = (old_connection instanceof Connection.UpgradeFrom) ?((Connection.UpgradeFrom)old_connection).onUpgradeFrom():null; old_connection.onClose(); old_connection.getEndPoint().setConnection(newConnection); if (newConnection instanceof Connection.UpgradeTo) ((Connection.UpgradeTo)newConnection).onUpgradeTo(prefilled); else if (BufferUtil.hasContent(prefilled)) throw new IllegalStateException(); newConnection.onOpen(); }
@Override protected void accept(int acceptorID) throws IOException, InterruptedException { if (LOG.isDebugEnabled()) LOG.debug("accepting {}", acceptorID); LocalEndPoint endPoint = _connects.take(); endPoint.onOpen(); onEndPointOpened(endPoint); Connection connection = getDefaultConnectionFactory().newConnection(this, endPoint); endPoint.setConnection(connection); connection.onOpen(); }
@Override public void onOpened(Connection connection) { synchronized (this) { _accepting.remove(connection.getEndPoint().getTransport()); _connections++; if (LOG.isDebugEnabled()) LOG.debug("onOpened ({}+{}) < {} {}",_accepting.size(),_connections,_maxConnections,connection); check(); } }
@Override public void failed(Throwable x) { if (LOG.isDebugEnabled()) LOG.debug(this + " failed to write initial " + remaining + " bytes to server", x); close(); getConnection().close(); } });
/** Sends requests and get's responses based on thread activity. * Returns all the responses received once the thread activity has * returned to the level it was before the requests. * <p> * This methods waits until the connection is closed or * an idle period before returning the responses. * @param requestsBuffer the requests * @param idleFor The time the response stream must be idle for before returning * @param units The units of idleFor * @return the responses * @throws Exception if the requests fail */ public ByteBuffer getResponses(ByteBuffer requestsBuffer,long idleFor,TimeUnit units) throws Exception { LOG.debug("requests {}", BufferUtil.toUTF8String(requestsBuffer)); LocalEndPoint endp = executeRequest(requestsBuffer); endp.waitUntilClosedOrIdleFor(idleFor,units); ByteBuffer responses = endp.takeOutput(); endp.getConnection().close(); LOG.debug("responses {}", BufferUtil.toUTF8String(responses)); return responses; }
protected void connectionClosed(Connection connection) { connection.onClose(); if (_statsStartedAt.get() == -1) return; long duration = System.currentTimeMillis() - connection.getTimeStamp(); int requests = (connection instanceof AbstractHttpConnection)?((AbstractHttpConnection)connection).getRequests():0; _requestStats.set(requests); _connectionStats.decrement(); _connectionDurationStats.set(duration); }
@Override protected void endPointClosed(SelectChannelEndPoint endpoint) { endpoint.getConnection().onClose(); }
@Override public void onClosed(Connection connection) { connectionClosed(System.currentTimeMillis()-connection.getCreatedTimeStamp(),connection.getMessagesIn(),connection.getMessagesOut()); }
@Override public void onClosed(Connection connection) { if (!isStarted()) return; _connections.decrement(); long elapsed = System.currentTimeMillis() - connection.getCreatedTimeStamp(); _connectionsDuration.record(elapsed); long bytesIn = connection.getBytesIn(); if (bytesIn > 0) _rcvdBytes.add(bytesIn); long bytesOut = connection.getBytesOut(); if (bytesOut > 0) _sentBytes.add(bytesOut); long messagesIn = connection.getMessagesIn(); if (messagesIn > 0) _messagesIn.add(messagesIn); long messagesOut = connection.getMessagesOut(); if (messagesOut > 0) _messagesOut.add(messagesOut); }
public void failed(Throwable t) { connection.close(); }
@Override protected void connectionClosed(Connection connection) { super.connectionClosed(connection); disconnects.mark(); final long duration = clock.getTime() - connection.getTimeStamp(); this.duration.update(duration, TimeUnit.MILLISECONDS); connections.dec(); } }
@Override public void onOpened(Connection connection) { synchronized (monitor) { connectionsAccepting.remove(connection.getEndPoint().getTransport()); ++connectionOpened; } }
Sample(Connection connection) { _messagesIn=connection.getMessagesIn(); _messagesOut=connection.getMessagesOut(); }