Examples of NIOConnection


Examples of org.glassfish.grizzly.nio.NIOConnection

    private NIOConnection nextConnection() {
        synchronized(connections) {
            if (currentConnection == Integer.MAX_VALUE) { currentConnection = 0; }
            currentConnection = (currentConnection + 1) % hosts.length;

            final NIOConnection connection = connections[currentConnection];
            if (connection == null || !connection.isOpen()) {
                connections[currentConnection] = openConnection(this.hosts[currentConnection]);
            }

            return connections[currentConnection];
        }
View Full Code Here

Examples of org.glassfish.grizzly.nio.NIOConnection

    }

    private NIOConnection openConnection(final String host) {
        try {
            final Future<Connection> future = this.transport.connect(host, port);
            final NIOConnection connection = (NIOConnection) future.get(this.timeoutConnection, TimeUnit.MILLISECONDS);
            connection.setMaxAsyncWriteQueueSize(asyncWriteQueueMaxBytes);
            return connection;
        } catch (Exception e) {
            return null;
        }
    }
View Full Code Here

Examples of org.glassfish.grizzly.nio.NIOConnection

    private void sendRequest(final RexProMessage toSend) throws Exception {
        boolean sent = false;
        int tries = this.retries;
        while (!closed && tries > 0 && !sent) {
            try {
                final NIOConnection connection = nextConnection();
                if (connection != null && connection.isOpen()) {
                    final GrizzlyFuture future = connection.write(new MessageContainer(serializer, toSend));
                    future.get(this.timeoutWrite, TimeUnit.MILLISECONDS);
                    sent = true;
                } else {
                    throw new Exception("Connection was not open.  Ensure that Rexster Server is running/reachable.");
                }
View Full Code Here

Examples of org.glassfish.grizzly.nio.NIOConnection

        this.listener = listener;
    }

    @Override
    public NextAction handleAccept(final FilterChainContext ctx) throws IOException {
        final NIOConnection nioConnection = (NIOConnection) ctx.getConnection();
        final SelectableChannel channel = nioConnection.getChannel();
        if (targetInitializer == null) {
            synchronized (LOCK_OBJ) {
                if (targetInitializer == null) {
                    LazyServiceInitializer targetInitializerLocal = null;
                    for (final ServiceHandle<LazyServiceInitializer> initializer : initializerImplList) {
                        String listenerName = listener.getName();
                        String serviceName = initializer.getActiveDescriptor().getName();
                        if (serviceName != null && listenerName.equalsIgnoreCase(serviceName)) {
                            targetInitializerLocal = initializer.getService();
                            break;
                        }
                    }

                    if (targetInitializerLocal == null) {
                        logger.log(Level.SEVERE, "NO Lazy Initialiser implementation was found for port = {0}",
                                listener.getPort());
                        nioConnection.close();

                        return ctx.getStopAction();
                    }
                    if (!targetInitializerLocal.initializeService()) {
                        logger.log(Level.SEVERE, "Lazy Service initialization failed for port = {0}",
                                listener.getPort());

                        nioConnection.close();

                        return ctx.getStopAction();
                    }
                   
                    targetInitializer = targetInitializerLocal;
                }
            }
        }

        final NextAction nextAction = ctx.getSuspendAction();
        ctx.completeAndRecycle();

        // Deregister channel
        final SelectorRunner runner = nioConnection.getSelectorRunner();
        final SelectorHandler selectorHandler =
                ((NIOTransport) nioConnection.getTransport()).getSelectorHandler();

        selectorHandler.deregisterChannel(runner, channel);

        // Underlying service rely the channel is blocking
        channel.configureBlocking(true);
View Full Code Here

Examples of org.glassfish.grizzly.nio.NIOConnection

        this.listener = listener;
    }

    @Override
    public NextAction handleAccept(final FilterChainContext ctx) throws IOException {
        final NIOConnection nioConnection = (NIOConnection) ctx.getConnection();
        final SelectableChannel channel = nioConnection.getChannel();
        if (targetInitializer == null) {
            synchronized (LOCK_OBJ) {
                if (targetInitializer == null) {
                    LazyServiceInitializer targetInitializerLocal = null;
                    for (final ActiveDescriptor<?> initializer : initializerImplList) {
                        String listenerName = listener.getName();
                        String serviceName = initializer.getName();
                        if (serviceName != null && listenerName.equalsIgnoreCase(serviceName)) {
                            targetInitializerLocal = (LazyServiceInitializer) locator.getServiceHandle(initializer).getService();
                            break;
                        }
                    }

                    if (targetInitializerLocal == null) {
                        logger.log(Level.SEVERE, "NO Lazy Initialiser implementation was found for port = {0}",
                                listener.getPort());
                        nioConnection.close();

                        return ctx.getStopAction();
                    }
                    if (!targetInitializerLocal.initializeService()) {
                        logger.log(Level.SEVERE, "Lazy Service initialization failed for port = {0}",
                                listener.getPort());

                        nioConnection.close();

                        return ctx.getStopAction();
                    }
                   
                    targetInitializer = targetInitializerLocal;
                }
            }
        }

        final NextAction nextAction = ctx.getSuspendAction();
        ctx.completeAndRecycle();

        // Deregister channel
        final SelectorRunner runner = nioConnection.getSelectorRunner();
        final SelectorHandler selectorHandler =
                ((NIOTransport) nioConnection.getTransport()).getSelectorHandler();

        selectorHandler.deregisterChannel(runner, channel);

        // Underlying service rely the channel is blocking
        channel.configureBlocking(true);
View Full Code Here

Examples of org.glassfish.grizzly.nio.NIOConnection

        final AsyncWriteQueueRecord nextRecord = writeTaskQueue.getQueue().poll();
        if (nextRecord == null) {
            return null;
        } else if (!canBeAggregated(nextRecord)) {
            final NIOConnection connection = (NIOConnection) nextRecord.getConnection();
            offerToTaskQueue(connection, nextRecord, writeTaskQueue);
            return null;
        }

        return nextRecord;
View Full Code Here

Examples of org.glassfish.grizzly.nio.NIOConnection

        this.listener = listener;
    }

    @Override
    public NextAction handleAccept(final FilterChainContext ctx) throws IOException {
        final NIOConnection nioConnection = (NIOConnection) ctx.getConnection();
        final SelectableChannel channel = nioConnection.getChannel();
        if (targetInitializer == null) {
            synchronized (LOCK_OBJ) {
                if (targetInitializer == null) {
                    LazyServiceInitializer targetInitializerLocal = null;
                    for (final LazyServiceInitializer initializer : initializerImplList) {
                        String listenerName = listener.getName();
                        if (listenerName.equalsIgnoreCase(initializer.getServiceName())) {
                            targetInitializerLocal = initializer;
                            break;
                        }
                    }

                    if (targetInitializerLocal == null) {
                        logger.log(Level.SEVERE, "NO Lazy Initialiser implementation was found for port = {0}",
                                listener.getPort());
                        nioConnection.close();

                        return ctx.getStopAction();
                    }
                    if (!targetInitializerLocal.initializeService()) {
                        logger.log(Level.SEVERE, "Lazy Service initialization failed for port = {0}",
                                listener.getPort());

                        nioConnection.close();

                        return ctx.getStopAction();
                    }
                   
                    targetInitializer = targetInitializerLocal;
                }
            }
        }

        final NextAction nextAction = ctx.getSuspendAction();
        ctx.completeAndRecycle();

        // Deregister channel
        final SelectorRunner runner = nioConnection.getSelectorRunner();
        final SelectorHandler selectorHandler =
                ((NIOTransport) nioConnection.getTransport()).getSelectorHandler();

        selectorHandler.deregisterChannel(runner, channel);

        // Underlying service rely the channel is blocking
        channel.configureBlocking(true);
View Full Code Here

Examples of org.glassfish.grizzly.nio.NIOConnection

    private static final V3Module module = new V3Module();

    @Override
    public NextAction handleRead(final FilterChainContext ctx) throws IOException {
        final NIOConnection connection = (NIOConnection) ctx.getConnection();

        if (connector == null) {
            synchronized (sync) {
                if (connector == null) {

                    final InetSocketAddress socketAddress = (InetSocketAddress) connection.getPeerAddress();
                    final String host = socketAddress.getHostName();
                    final int port = socketAddress.getPort();

                    LOGGER.log(Level.INFO, "Initialize SOAP/TCP protocol for port: {0}", port);

                    connector = new Connector(host, port, module.getDelegate());
                }
            }
        }
       
        final Buffer buffer = ctx.getMessage();
        final ByteBuffer byteBuffer = buffer.toByteBuffer();
               
        final SocketChannel channel = (SocketChannel) connection.getChannel();
        connector.process(byteBuffer, channel);

        return ctx.getStopAction();
    }
View Full Code Here

Examples of org.glassfish.grizzly.nio.NIOConnection

        this.listener = listener;
    }

    @Override
    public NextAction handleAccept(final FilterChainContext ctx) throws IOException {
        final NIOConnection nioConnection = (NIOConnection) ctx.getConnection();
        final SelectableChannel channel = nioConnection.getChannel();
       
        // The LazyServiceInitializer's name we're looking for should be equal
        // to either listener or protocol name
        final String listenerName = listener.getName();
        final String protocolName = listener.getNetworkListener().getProtocol();
       
        if (targetInitializer == null) {
            synchronized (LOCK_OBJ) {
                if (targetInitializer == null) {
                    LazyServiceInitializer targetInitializerLocal = null;
                    for (final ActiveDescriptor<?> initializer : initializerImplList) {
                        String serviceName = initializer.getName();
                       
                       
                        if (serviceName != null &&
                                (listenerName.equalsIgnoreCase(serviceName) ||
                                protocolName.equalsIgnoreCase(serviceName))) {
                            targetInitializerLocal = (LazyServiceInitializer) locator.getServiceHandle(initializer).getService();
                            break;
                        }
                    }

                    if (targetInitializerLocal == null) {
                        logger.log(Level.SEVERE, "NO Lazy Initialiser implementation was found for port = {0}",
                                String.valueOf(listener.getPort()));
                        nioConnection.close();

                        return ctx.getStopAction();
                    }
                    if (!targetInitializerLocal.initializeService()) {
                        logger.log(Level.SEVERE, "Lazy Service initialization failed for port = {0}",
                                String.valueOf(listener.getPort()));

                        nioConnection.close();

                        return ctx.getStopAction();
                    }
                   
                    targetInitializer = targetInitializerLocal;
                }
            }
        }

        final NextAction nextAction = ctx.getSuspendAction();
        ctx.completeAndRecycle();

        // Deregister channel
        final SelectorRunner runner = nioConnection.getSelectorRunner();
        final SelectorHandler selectorHandler =
                ((NIOTransport) nioConnection.getTransport()).getSelectorHandler();

        selectorHandler.deregisterChannel(runner, channel);

        // Underlying service rely the channel is blocking
        channel.configureBlocking(true);
View Full Code Here

Examples of org.glassfish.grizzly.nio.NIOConnection

    private static final V3Module module = new V3Module();

    @Override
    public NextAction handleRead(final FilterChainContext ctx) throws IOException {
        final NIOConnection connection = (NIOConnection) ctx.getConnection();

        if (connector == null) {
            synchronized (sync) {
                if (connector == null) {

                    final InetSocketAddress socketAddress = (InetSocketAddress) connection.getPeerAddress();
                    final String host = socketAddress.getHostName();
                    final int port = socketAddress.getPort();

                    LOGGER.log(Level.INFO, LogUtils.SOAPTCP_PROTOCOL_INITIALIZED, port);

                    connector = new Connector(host, port, module.getDelegate());
                }
            }
        }
       
        final Buffer buffer = ctx.getMessage();
        final ByteBuffer byteBuffer = buffer.toByteBuffer();
               
        final SocketChannel channel = (SocketChannel) connection.getChannel();
        connector.process(byteBuffer, channel);

        return ctx.getStopAction();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.