Search in sources :

Example 1 with NIOConnection

use of org.glassfish.grizzly.nio.NIOConnection in project Payara by payara.

the class WSTCPProtocolFilter method handleRead.

@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();
}
Also used : Buffer(org.glassfish.grizzly.Buffer) ByteBuffer(java.nio.ByteBuffer) SocketChannel(java.nio.channels.SocketChannel) InetSocketAddress(java.net.InetSocketAddress) ByteBuffer(java.nio.ByteBuffer) NIOConnection(org.glassfish.grizzly.nio.NIOConnection)

Example 2 with NIOConnection

use of org.glassfish.grizzly.nio.NIOConnection in project Payara by payara.

the class ServiceInitializerFilter method handleAccept.

@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);
    targetInitializer.handleRequest(channel);
    return nextAction;
}
Also used : NIOTransport(org.glassfish.grizzly.nio.NIOTransport) SelectableChannel(java.nio.channels.SelectableChannel) SelectorHandler(org.glassfish.grizzly.nio.SelectorHandler) SelectorRunner(org.glassfish.grizzly.nio.SelectorRunner) LazyServiceInitializer(org.glassfish.internal.grizzly.LazyServiceInitializer) NextAction(org.glassfish.grizzly.filterchain.NextAction) NIOConnection(org.glassfish.grizzly.nio.NIOConnection)

Example 3 with NIOConnection

use of org.glassfish.grizzly.nio.NIOConnection in project Payara by payara.

the class WSTCPProtocolFilter method handleClose.

@Override
public NextAction handleClose(final FilterChainContext ctx) throws IOException {
    final Connection connection = ctx.getConnection();
    final SelectionKey selectionKey = ((NIOConnection) connection).getSelectionKey();
    try {
        if (connector != null) {
            connector.notifyConnectionClosed((SocketChannel) selectionKey.channel());
        } else {
            synchronized (sync) {
                if (connector != null) {
                    connector.notifyConnectionClosed((SocketChannel) selectionKey.channel());
                }
            }
        }
    } catch (Exception e) {
    }
    return ctx.getInvokeAction();
}
Also used : SelectionKey(java.nio.channels.SelectionKey) Connection(org.glassfish.grizzly.Connection) NIOConnection(org.glassfish.grizzly.nio.NIOConnection) IOException(java.io.IOException) NIOConnection(org.glassfish.grizzly.nio.NIOConnection)

Aggregations

NIOConnection (org.glassfish.grizzly.nio.NIOConnection)3 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ByteBuffer (java.nio.ByteBuffer)1 SelectableChannel (java.nio.channels.SelectableChannel)1 SelectionKey (java.nio.channels.SelectionKey)1 SocketChannel (java.nio.channels.SocketChannel)1 Buffer (org.glassfish.grizzly.Buffer)1 Connection (org.glassfish.grizzly.Connection)1 NextAction (org.glassfish.grizzly.filterchain.NextAction)1 NIOTransport (org.glassfish.grizzly.nio.NIOTransport)1 SelectorHandler (org.glassfish.grizzly.nio.SelectorHandler)1 SelectorRunner (org.glassfish.grizzly.nio.SelectorRunner)1 LazyServiceInitializer (org.glassfish.internal.grizzly.LazyServiceInitializer)1