Search in sources :

Example 1 with NIOTransport

use of org.glassfish.grizzly.nio.NIOTransport 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 2 with NIOTransport

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

the class GenericGrizzlyListener method stop.

@Override
public void stop() throws IOException {
    stopDelayedExecutor();
    final NIOTransport localTransport = transport;
    transport = null;
    if (localTransport != null) {
        localTransport.shutdownNow();
    }
    if (workerExecutorService != null) {
        final ExecutorService localExecutorService = workerExecutorService;
        workerExecutorService = null;
        localExecutorService.shutdownNow();
    }
    rootFilterChain = null;
}
Also used : NIOTransport(org.glassfish.grizzly.nio.NIOTransport) UDPNIOTransport(org.glassfish.grizzly.nio.transport.UDPNIOTransport) TCPNIOTransport(org.glassfish.grizzly.nio.transport.TCPNIOTransport) GrizzlyExecutorService(org.glassfish.grizzly.threadpool.GrizzlyExecutorService) ExecutorService(java.util.concurrent.ExecutorService)

Example 3 with NIOTransport

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

the class GrizzlyConfigTest method testSelectionKeyHandlerConfiguration.

@Test
public void testSelectionKeyHandlerConfiguration() throws Exception {
    GrizzlyConfig grizzlyConfig = null;
    try {
        configure();
        grizzlyConfig = new GrizzlyConfig("grizzly-config-skh.xml");
        grizzlyConfig.setupNetwork();
        final String bufferType = grizzlyConfig.getConfig().getNetworkListeners().getNetworkListener().get(0).findTransport().getByteBufferType();
        GenericGrizzlyListener genericGrizzlyListener = (GenericGrizzlyListener) getListener(grizzlyConfig, "http-listener-1");
        NIOTransport transport = (NIOTransport) genericGrizzlyListener.getTransport();
        assertNotSame(DummySelectionKeyHandler.class.getName(), transport.getSelectionKeyHandler().getClass().getName());
    } finally {
        if (grizzlyConfig != null) {
            grizzlyConfig.shutdownNetwork();
            grizzlyConfig.shutdown();
        }
    }
}
Also used : NIOTransport(org.glassfish.grizzly.nio.NIOTransport) Test(org.junit.Test)

Aggregations

NIOTransport (org.glassfish.grizzly.nio.NIOTransport)3 SelectableChannel (java.nio.channels.SelectableChannel)1 ExecutorService (java.util.concurrent.ExecutorService)1 NextAction (org.glassfish.grizzly.filterchain.NextAction)1 NIOConnection (org.glassfish.grizzly.nio.NIOConnection)1 SelectorHandler (org.glassfish.grizzly.nio.SelectorHandler)1 SelectorRunner (org.glassfish.grizzly.nio.SelectorRunner)1 TCPNIOTransport (org.glassfish.grizzly.nio.transport.TCPNIOTransport)1 UDPNIOTransport (org.glassfish.grizzly.nio.transport.UDPNIOTransport)1 GrizzlyExecutorService (org.glassfish.grizzly.threadpool.GrizzlyExecutorService)1 LazyServiceInitializer (org.glassfish.internal.grizzly.LazyServiceInitializer)1 Test (org.junit.Test)1