Java源码示例:org.eclipse.jetty.io.Connection

示例1
@Override
public void onClosed(Connection connection) {
    Timer.Sample sample;
    synchronized (connectionSamplesLock) {
        sample = connectionSamples.remove(connection);
    }

    if (sample != null) {
        String serverOrClient = connection instanceof HttpConnection ? "server" : "client";
        sample.stop(Timer.builder("jetty.connections.request")
                .description("Jetty client or server requests")
                .tag("type", serverOrClient)
                .tags(tags)
                .register(registry));
    }

    messagesIn.increment(connection.getMessagesIn());
    messagesOut.increment(connection.getMessagesOut());

    bytesIn.record(connection.getBytesIn());
    bytesOut.record(connection.getBytesOut());
}
 
示例2
@Override
public Connection newConnection(Connector connector, EndPoint endPoint) {
    LOG.info("newConnection: {}", endPoint.getLocalAddress().toString());
    ServerSessionListener listener = new CustomSessionListener(connector, endPoint, streamProcessors);

    Generator generator = new Generator(connector.getByteBufferPool(), getMaxDynamicTableSize(), getMaxHeaderBlockFragment());
    FlowControlStrategy flowControl = getFlowControlStrategyFactory().newFlowControlStrategy();
    HTTP2ServerSession session = new HTTP2ServerSession(connector.getScheduler(), endPoint, generator, listener, flowControl);
    session.setMaxLocalStreams(getMaxConcurrentStreams());
    session.setMaxRemoteStreams(getMaxConcurrentStreams());
    // For a single stream in a connection, there will be a race between
    // the stream idle timeout and the connection idle timeout. However,
    // the typical case is that the connection will be busier and the
    // stream idle timeout will expire earlier than the connection's.
    long streamIdleTimeout = getStreamIdleTimeout();
    if (streamIdleTimeout <= 0) {
        streamIdleTimeout = endPoint.getIdleTimeout();
    }
    session.setStreamIdleTimeout(streamIdleTimeout);
    session.setInitialSessionRecvWindow(getInitialSessionRecvWindow());

    ServerParser parser = newServerParser(connector, session, RateControl.NO_RATE_CONTROL);
    HTTP2Connection connection = new HTTP2ServerConnection(connector.getByteBufferPool(), executor,
            endPoint, getHttpConfiguration(), parser, session, getInputBufferSize(), listener);
    connection.addListener(connectionListener);
    return configure(connection, connector, endPoint);
}
 
示例3
@Override
public void onOpened(Connection connection) {
    Timer.Sample started = Timer.start(registry);
    synchronized (connectionSamplesLock) {
        connectionSamples.put(connection, started);
        maxConnections.record(connectionSamples.size());
    }
}
 
示例4
@Override
public void onClosed(final Connection connection)
{
    SettableFuture<Void> closeFuture = _closeFutures.remove(connection);
    if (closeFuture != null)
    {
        closeFuture.set(null);
    }
}
 
示例5
@Override
public void onOpened(Connection connection) {
    synchronized (monitor) {
        connectionsAccepting.remove(connection.getEndPoint().getTransport());
        ++connectionOpened;
    }
}
 
示例6
@Override  
protected void connectionClosed(Connection connection) {
    if (connection instanceof AsyncHttpConnection) {
        AsyncHttpConnection conn = (AsyncHttpConnection)connection;
        ServerSessionMonitor monitor = (ServerSessionMonitor)conn.getAssociatedObject();
        if (monitor != null) {
            monitorService.deregisterSessionMonitor(monitor, session);
            conn.setAssociatedObject(null);
        }
    }
    super.connectionClosed(connection);
}
 
示例7
@Override  
protected void connectionClosed (Connection connection) {
    if (connection instanceof SslConnection) {
        AsyncHttpConnection conn = (AsyncHttpConnection)((SslConnection) connection).getSslEndPoint().getConnection();
        ServerSessionMonitor monitor = (ServerSessionMonitor)conn.getAssociatedObject();
        if (monitor != null) {
            monitorService.deregisterSessionMonitor(monitor, session);
            conn.setAssociatedObject(null);
        }
    }
    super.connectionClosed(connection);
}
 
示例8
public void setConnection(Connection connection)
{
    Connection old=_connection;
    _connection=(AsyncConnection)connection;
    if (old!=null && old!=_connection)
        _manager.endPointUpgraded(this,old);
}
 
示例9
public void setConnection(Connection connection)
{
    Connection old=_connection;
    _connection=(AsyncConnection)connection;
    if (old!=null && old!=_connection)
        _manager.endPointUpgraded(this,old);
}
 
示例10
public void setConnection(Connection connection)
{
    Connection old=_connection;
    _connection=(AsyncConnection)connection;
    if (old!=null && old!=_connection)
        _manager.endPointUpgraded(this,old);
}
 
示例11
@Override
public Connection newConnection(Connector connector, EndPoint endPoint) {
    HttpConnectionCustom conn = new HttpConnectionCustom(getHttpConfiguration(), connector,
        endPoint, getHttpCompliance(), isRecordHttpComplianceViolations());
    return configure(conn, connector, endPoint);
}
 
示例12
@Override
public void onOpened(Connection connection) {
    LOG.info("onOpened");
}
 
示例13
@Override
public void onClosed(Connection connection) {
    LOG.info("onClosed");
}
 
示例14
@Override
public Connection getConnection()
{
    return _underlying.getConnection();
}
 
示例15
@Override
public void setConnection(final Connection connection)
{
    _underlying.setConnection(connection);
}
 
示例16
@Override
public void upgrade(final Connection newConnection)
{
    _underlying.upgrade(newConnection);
}
 
示例17
@Override
public void onOpened(final Connection connection)
{
    _closeFutures.put(connection, SettableFuture.create());
}
 
示例18
@Override
public void onClosed(Connection connection) {
    synchronized (monitor) {
        --connectionOpened;
    }
}
 
示例19
@Override
public Connection newConnection(Connector connector, EndPoint endPoint) {
    System.out.println("Received new connection from " + endPoint.getRemoteAddress());
    ConnectionTracker.getInstance().onConnection();
    return super.newConnection(connector, endPoint);
}
 
示例20
@Override
protected void endPointUpgraded(ConnectedEndPoint endpoint, Connection oldConnection)
{
    LOG.debug("upgrade {} -> {}", oldConnection, endpoint.getConnection());
}
 
示例21
public Connection handle() throws IOException
{
    while (_endp.isOpen() && !_parser.isComplete())
    {
        if (_handshake==null || _handshake.length()>0)
            if (!handshake())
                return this;

        if (!_parser.parseAvailable())
        {
            if (_endp.isInputShutdown())
                _future.handshakeFailed(new IOException("Incomplete handshake response"));
            return this;
        }
    }
    if (_error == null)
    {
        if (_accept == null)
        {
            _error = "No Sec-WebSocket-Accept";
        }
        else if (!WebSocketConnectionRFC6455.hashKey(_key).equals(_accept))
        {
            _error = "Bad Sec-WebSocket-Accept";
        }
        else
        {
            WebSocketConnection connection = newWebSocketConnection();

            Buffer header = _parser.getHeaderBuffer();
            if (header.hasContent())
                connection.fillBuffersFrom(header);
            _buffers.returnBuffer(header);

            _future.onConnection(connection);

            return connection;
        }
    }

    _endp.close();
    return this;
}
 
示例22
public WebSocket.Connection getConnection()
{
    return _connection;
}
 
示例23
public Connection handle() throws IOException
{
    Thread current = Thread.currentThread();
    ClassLoader oldcontext = current.getContextClassLoader();
    current.setContextClassLoader(_context);
    try
    {
        // handle the framing protocol
        boolean progress=true;

        while (progress)
        {
            int flushed=_generator.flushBuffer();
            int filled=_parser.parseNext();

            progress = flushed>0 || filled>0;
            _endp.flush();

            if (_endp instanceof AsyncEndPoint && ((AsyncEndPoint)_endp).hasProgressed())
                progress=true;
        }
    }
    catch(IOException e)
    {
        try
        {
            if (_endp.isOpen())
                _endp.close();
        }
        catch(IOException e2)
        {
            LOG.ignore(e2);
        }
        throw e;
    }
    finally
    {
        current.setContextClassLoader(oldcontext);
        _parser.returnBuffer();
        _generator.returnBuffer();
        if (_endp.isOpen())
        {
            if (_closedIn && _closedOut && _outbound.isBufferEmpty())
                _endp.close();
            else if (_endp.isInputShutdown() && !_closedIn)
                closeIn(CLOSE_NO_CLOSE,null);
            else
                checkWriteable();
        }
    }
    return this;
}
 
示例24
public void shutdown()
{
    final WebSocket.Connection connection = _connection;
    if (connection != null)
        connection.close(CLOSE_SHUTDOWN, null);
}
 
示例25
public Connection handle() throws IOException
{
    try
    {
        allocateBuffers();

        boolean progress=true;

        while (progress)
        {
            progress=false;

            // If we are handshook let the delegate connection
            if (_engine.getHandshakeStatus()!=HandshakeStatus.NOT_HANDSHAKING)
                progress=process(null,null);

            // handle the delegate connection
            AsyncConnection next = (AsyncConnection)_connection.handle();
            if (next!=_connection && next!=null)
            {
                _connection=next;
                progress=true;
            }

            _logger.debug("{} handle {} progress={}", _session, this, progress);
        }
    }
    finally
    {
        releaseBuffers();

        if (!_ishut && _sslEndPoint.isInputShutdown() && _sslEndPoint.isOpen())
        {
            _ishut=true;
            try
            {
                _connection.onInputShutdown();
            }
            catch(Throwable x)
            {
                _logger.warn("onInputShutdown failed", x);
                try{_sslEndPoint.close();}
                catch(IOException e2){
                    _logger.ignore(e2);}
            }
        }
    }

    return this;
}
 
示例26
public void onClose()
{
    Connection connection = _sslEndPoint.getConnection();
    if (connection != null && connection != this)
        connection.onClose();
}
 
示例27
public Connection getConnection()
{
    return _connection;
}
 
示例28
public void setConnection(Connection connection)
{
    _connection=(AsyncConnection)connection;
}
 
示例29
public Connection getConnection()
{
    return _connection;
}
 
示例30
@Override
protected void endPointUpgraded(ConnectedEndPoint endpoint, Connection oldConnection)
{
    LOG.debug("upgrade {} -> {}", oldConnection, endpoint.getConnection());
}