org.eclipse.jetty.io.Connection Java Examples

The following examples show how to use org.eclipse.jetty.io.Connection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JettyConnectionMetrics.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #2
Source File: SelectChannelEndPoint.java    From WebSocket-for-Android with Apache License 2.0 5 votes vote down vote up
public void setConnection(Connection connection)
{
    Connection old=_connection;
    _connection=(AsyncConnection)connection;
    if (old!=null && old!=_connection)
        _manager.endPointUpgraded(this,old);
}
 
Example #3
Source File: SelectChannelEndPoint.java    From IoTgo_Android_App with MIT License 5 votes vote down vote up
public void setConnection(Connection connection)
{
    Connection old=_connection;
    _connection=(AsyncConnection)connection;
    if (old!=null && old!=_connection)
        _manager.endPointUpgraded(this,old);
}
 
Example #4
Source File: SelectChannelEndPoint.java    From IoTgo_Android_App with MIT License 5 votes vote down vote up
public void setConnection(Connection connection)
{
    Connection old=_connection;
    _connection=(AsyncConnection)connection;
    if (old!=null && old!=_connection)
        _manager.endPointUpgraded(this,old);
}
 
Example #5
Source File: HttpConductorImpl.java    From sql-layer with GNU Affero General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #6
Source File: HttpConductorImpl.java    From sql-layer with GNU Affero General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #7
Source File: ConnectionThrottler.java    From vespa with Apache License 2.0 5 votes vote down vote up
@Override
public void onOpened(Connection connection) {
    synchronized (monitor) {
        connectionsAccepting.remove(connection.getEndPoint().getTransport());
        ++connectionOpened;
    }
}
 
Example #8
Source File: HttpManagement.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
public void onClosed(final Connection connection)
{
    SettableFuture<Void> closeFuture = _closeFutures.remove(connection);
    if (closeFuture != null)
    {
        closeFuture.set(null);
    }
}
 
Example #9
Source File: JettyConnectionMetrics.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Override
public void onOpened(Connection connection) {
    Timer.Sample started = Timer.start(registry);
    synchronized (connectionSamplesLock) {
        connectionSamples.put(connection, started);
        maxConnections.record(connectionSamples.size());
    }
}
 
Example #10
Source File: ServerConnectionFactory.java    From java-11-examples with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #11
Source File: JettyWebServer.java    From Doradus with Apache License 2.0 4 votes vote down vote up
@Override
public void onOpened(Connection arg0) {
    for (RequestCallback callback : m_requestCallbacks) {
        callback.onConnectionOpened();
    }
}
 
Example #12
Source File: WebSocketConnectionRFC6455.java    From IoTgo_Android_App with MIT License 4 votes vote down vote up
public WebSocket.Connection getConnection()
{
    return _connection;
}
 
Example #13
Source File: WebSocketConnectionRFC6455.java    From IoTgo_Android_App with MIT License 4 votes vote down vote up
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;
}
 
Example #14
Source File: SelectChannelEndPoint.java    From IoTgo_Android_App with MIT License 4 votes vote down vote up
public Connection getConnection()
{
    return _connection;
}
 
Example #15
Source File: WebSocketConnectionRFC6455.java    From IoTgo_Android_App with MIT License 4 votes vote down vote up
public void shutdown()
{
    final WebSocket.Connection connection = _connection;
    if (connection != null)
        connection.close(CLOSE_SHUTDOWN, null);
}
 
Example #16
Source File: SslConnection.java    From IoTgo_Android_App with MIT License 4 votes vote down vote up
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;
}
 
Example #17
Source File: SslConnection.java    From IoTgo_Android_App with MIT License 4 votes vote down vote up
public void onClose()
{
    Connection connection = _sslEndPoint.getConnection();
    if (connection != null && connection != this)
        connection.onClose();
}
 
Example #18
Source File: SslConnection.java    From IoTgo_Android_App with MIT License 4 votes vote down vote up
public Connection getConnection()
{
    return _connection;
}
 
Example #19
Source File: SslConnection.java    From IoTgo_Android_App with MIT License 4 votes vote down vote up
public void setConnection(Connection connection)
{
    _connection=(AsyncConnection)connection;
}
 
Example #20
Source File: SelectChannelEndPoint.java    From IoTgo_Android_App with MIT License 4 votes vote down vote up
public Connection getConnection()
{
    return _connection;
}
 
Example #21
Source File: SelectChannelEndPoint.java    From WebSocket-for-Android with Apache License 2.0 4 votes vote down vote up
public Connection getConnection()
{
    return _connection;
}
 
Example #22
Source File: ArmeriaConnector.java    From armeria with Apache License 2.0 4 votes vote down vote up
@Override
public Connection newConnection(Connector connector, EndPoint endPoint) {
    throw new UnsupportedOperationException();
}
 
Example #23
Source File: SslConnection.java    From WebSocket-for-Android with Apache License 2.0 4 votes vote down vote up
public void onClose()
{
    Connection connection = _sslEndPoint.getConnection();
    if (connection != null && connection != this)
        connection.onClose();
}
 
Example #24
Source File: JettyWebServer.java    From Doradus with Apache License 2.0 4 votes vote down vote up
@Override
public void onClosed(Connection arg0) {
    for (RequestCallback callback : m_requestCallbacks) {
        callback.onConnectionClosed();
    }
}
 
Example #25
Source File: WebSocketClientFactory.java    From WebSocket-for-Android with Apache License 2.0 4 votes vote down vote up
@Override
protected void endPointUpgraded(ConnectedEndPoint endpoint, Connection oldConnection)
{
    LOG.debug("upgrade {} -> {}", oldConnection, endpoint.getConnection());
}
 
Example #26
Source File: WebSocketClientFactory.java    From WebSocket-for-Android with Apache License 2.0 4 votes vote down vote up
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 if (!initExtensions(_future.getExtensions()))
        {
            _error = "Bad Sec-WebSocket-Extension";
        }
        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;
}
 
Example #27
Source File: WebSocketConnectionRFC6455.java    From WebSocket-for-Android with Apache License 2.0 4 votes vote down vote up
public WebSocket.Connection getConnection()
{
    return _connection;
}
 
Example #28
Source File: SslConnection.java    From WebSocket-for-Android with Apache License 2.0 4 votes vote down vote up
public void setConnection(Connection connection)
{
    _connection=(AsyncConnection)connection;
}
 
Example #29
Source File: WebSocketConnectionRFC6455.java    From WebSocket-for-Android with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example #30
Source File: WebSocketConnectionRFC6455.java    From WebSocket-for-Android with Apache License 2.0 4 votes vote down vote up
public void shutdown()
{
    final WebSocket.Connection connection = _connection;
    if (connection != null)
        connection.close(CLOSE_SHUTDOWN, null);
}