Package org.glassfish.grizzly

Examples of org.glassfish.grizzly.Connection


        assert (context != null);
        assert (requestPacket != null);

        this.requestPacket = requestPacket;
        this.contentBuilder = HttpContent.builder(requestPacket);
        final Connection c = context.getConnection();
        origMaxPendingBytes = c.getMaxAsyncWriteQueueSize();
        if (configuredMaxPendingBytes != DEFAULT) {
            c.setMaxAsyncWriteQueueSize(configuredMaxPendingBytes);
        }
        this.context = context;
        asyncTransferInitiated = true;
        final Runnable r = new Runnable() {
            @Override
            public void run() {
                try {
                    if (requestPacket.isSecure() &&
                            (getSSLEngine(context.getConnection()) == null)) {
                        flushOnSSLHandshakeComplete();
                    } else {
                        feeder.flush();
                    }
                } catch (IOException ioe) {
                    throwError(ioe);
                }
            }
        };

        // If the current thread is a selector thread, we need to execute
        // the remainder of the task on the worker thread to prevent
        // it from being blocked.
        if (isServiceThread()) {
            c.getTransport().getWorkerThreadPool().execute(r);
        } else {
            r.run();
        }
    }
View Full Code Here


    private void flushOnSSLHandshakeComplete() throws IOException {
        final FilterChain filterChain = context.getFilterChain();
        final int idx = filterChain.indexOfType(SSLFilter.class);
        assert (idx != -1);
        final SSLFilter filter = (SSLFilter) filterChain.get(idx);
        final Connection c = context.getConnection();
        filter.addHandshakeListener(new SSLBaseFilter.HandshakeListener() {
            public void onStart(Connection connection) {
            }

            public void onComplete(Connection connection) {
                if (c.equals(connection)) {
                    filter.removeHandshakeListener(this);
                    try {
                        feeder.flush();
                    } catch (IOException ioe) {
                        throwError(ioe);
View Full Code Here

            @Override
            public void ready() {
                try {
                    flush();
                } catch (IOException e) {
                    final Connection c = feedableBodyGenerator.context.getConnection();
                    if (!Utils.isSpdyConnection(c)) {
                        c.setMaxAsyncWriteQueueSize(feedableBodyGenerator.origMaxPendingBytes);
                    }
                    feedableBodyGenerator.throwError(e);
                }
            }
View Full Code Here

        }

        @Override
        public String selectProtocol(SSLEngine engine, LinkedHashSet<String> protocols) {
            GrizzlyAsyncHttpProvider.LOGGER.info("ProtocolSelector::selectProtocol: " + protocols);
            final Connection connection = NextProtoNegSupport.getConnection(engine);

            // Give preference to SPDY/3.1 or SPDY/3.  If not available, check for HTTP as a
            // fallback           
            for (SpdyVersion version : SUPPORTED_SPDY_VERSIONS) {
                final String versionDef = version.toString();
View Full Code Here

        }

        @Override
        public void onNoDeal(SSLEngine engine) {
            GrizzlyAsyncHttpProvider.LOGGER.info("ProtocolSelector::onNoDeal");
            final Connection connection = NextProtoNegSupport.getConnection(engine);
            connection.closeSilently();
        }
View Full Code Here

                httpHeader.setSkipRemainder(true);
                final Request newRequest = fc.getRequest();
                final AsyncHandler newHandler = fc.getAsyncHandler();
                try {
                    final ConnectionManager m = context.getProvider().getConnectionManager();
                    final Connection c = m.obtainConnection(newRequest, context.getFuture());
                    final HttpTxContext newContext = context.copy();
                    newContext.setRequest(newRequest);
                    context.setFuture(null);
                    context.getProvider().execute(c, newRequest, newHandler, context.getFuture(), newContext);
                } catch (Exception e) {
View Full Code Here

    }

    @SuppressWarnings("rawtypes")
    private static HttpTxContext cleanup(final FilterChainContext ctx) {

        final Connection c = ctx.getConnection();
        final HttpTxContext context = HttpTxContext.remove(ctx);
        if (!Utils.isSpdyConnection(c) && !Utils.isIgnored(c)) {
            final ConnectionManager manager = context.getProvider().getConnectionManager();
            //if (!manager.canReturnConnection(c)) {
            //    context.abort(
View Full Code Here

        final UpgradeResponse upgradeResponse = new TyrusUpgradeResponse();
        final WebSocketEngine.UpgradeInfo upgradeInfo = serverContainer.getWebSocketEngine().upgrade(upgradeRequest, upgradeResponse);

        switch (upgradeInfo.getStatus()) {
            case SUCCESS:
                final Connection grizzlyConnection = ctx.getConnection();
                write(ctx, upgradeRequest, upgradeResponse);

                final org.glassfish.tyrus.spi.Connection connection = upgradeInfo.createConnection(new GrizzlyWriter(ctx.getConnection()), new org.glassfish.tyrus.spi.Connection.CloseListener() {
                    @Override
                    public void close(CloseReason reason) {
                        grizzlyConnection.close();
                    }
                });

                TYRUS_CONNECTION.set(grizzlyConnection, connection);

                grizzlyConnection.addCloseListener(new CloseListener() {
                    @Override
                    public void onClosed(Closeable closeable, ICloseType type) throws IOException {
                        connection.close(new CloseReason(CloseReason.CloseCodes.GOING_AWAY, "Close detected on connection"));
                        // might not be necessary, connection is going to be recycled/freed anyway
                        TYRUS_CONNECTION.remove(grizzlyConnection);
View Full Code Here

    private class ClientRunner implements Runnable {

        @Override
        public void run() {
            Connection connection = null;
            try {

                final FilterChainBuilder clientFilterBuilder = FilterChainBuilder.stateless()
                        .add(new TransportFilter())
                        .add(new StringFilter(Charset.forName("UTF-8")))
                        .add(new HelloClientFilter(countDownLatch));


                final TCPNIOTransport transport = TCPNIOTransportBuilder.newInstance()
                        .setProcessor(clientFilterBuilder.build())
                        .build();

                try {
                    transport.start();
                    connection = transport.connect("localhost", 20389).get();
                    connection.write("foo");
                } catch (IOException e) {
                    e.printStackTrace()//To change body of catch statement use File | Settings | File Templates.
                }

                countDownLatch.await();
                if (connection != null)
                    connection.close();

                try {
                    transport.stop();
                } catch (IOException e) {
                    LOGGER.debug("can't close connect", e);
View Full Code Here

        final UpgradeResponse upgradeResponse = new TyrusUpgradeResponse();
        final WebSocketEngine.UpgradeInfo upgradeInfo = serverContainer.getWebSocketEngine().upgrade(upgradeRequest, upgradeResponse);

        switch (upgradeInfo.getStatus()) {
            case SUCCESS:
                final Connection grizzlyConnection = ctx.getConnection();
                write(ctx, upgradeRequest, upgradeResponse);

                final org.glassfish.tyrus.spi.Connection connection = upgradeInfo.createConnection(new GrizzlyWriter(ctx.getConnection()), new org.glassfish.tyrus.spi.Connection.CloseListener() {
                    @Override
                    public void close(CloseReason reason) {
                        grizzlyConnection.close();
                    }
                });

                TYRUS_CONNECTION.set(grizzlyConnection, connection);

                grizzlyConnection.addCloseListener(new CloseListener() {
                    @Override
                    public void onClosed(Closeable closeable, ICloseType type) throws IOException {
                        connection.close(new CloseReason(CloseReason.CloseCodes.GOING_AWAY, "Close detected on connection"));
                        // might not be necessary, connection is going to be recycled/freed anyway
                        TYRUS_CONNECTION.remove(grizzlyConnection);
View Full Code Here

TOP

Related Classes of org.glassfish.grizzly.Connection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.