Search in sources :

Example 1 with ByteBufferManager

use of org.glassfish.grizzly.memory.ByteBufferManager in project Payara by payara.

the class GenericGrizzlyListener method configureTransport.

protected void configureTransport(final NetworkListener networkListener, final Transport transportConfig, final FilterChainBuilder filterChainBuilder) {
    final String transportClassName = transportConfig.getClassname();
    if (TCPNIOTransport.class.getName().equals(transportClassName)) {
        transport = configureTCPTransport(transportConfig);
    } else if (UDPNIOTransport.class.getName().equals(transportClassName)) {
        transport = configureUDPTransport();
    } else {
        throw new GrizzlyConfigException("Unsupported transport type " + transportConfig.getName());
    }
    String selectorName = transportConfig.getSelectionKeyHandler();
    if (selectorName != null) {
        if (getSelectionKeyHandlerByName(selectorName, transportConfig) != null) {
            if (LOGGER.isLoggable(Level.INFO)) {
                LOGGER.warning("Element, selection-key-handler, has been deprecated and is effectively ignored by the runtime.");
            }
        }
    }
    if (!Transport.BYTE_BUFFER_TYPE.equalsIgnoreCase(transportConfig.getByteBufferType())) {
        transport.setMemoryManager(new ByteBufferManager(true, AbstractMemoryManager.DEFAULT_MAX_BUFFER_SIZE, ByteBufferManager.DEFAULT_SMALL_BUFFER_SIZE));
    }
    final int acceptorThreads = Integer.parseInt(transportConfig.getAcceptorThreads());
    transport.setSelectorRunnersCount(acceptorThreads);
    final int readSize = Integer.parseInt(transportConfig.getSocketReadBufferSize());
    if (readSize > 0) {
        transport.setReadBufferSize(readSize);
    }
    final int writeSize = Integer.parseInt(transportConfig.getSocketWriteBufferSize());
    if (writeSize > 0) {
        transport.setWriteBufferSize(writeSize);
    }
    final ThreadPoolConfig kernelThreadPoolConfig = transport.getKernelThreadPoolConfig();
    kernelThreadPoolConfig.setPoolName(networkListener.getName() + "-kernel");
    if (acceptorThreads > 0) {
        kernelThreadPoolConfig.setCorePoolSize(acceptorThreads).setMaxPoolSize(acceptorThreads);
    }
    transport.setIOStrategy(loadIOStrategy(transportConfig.getIoStrategy()));
    transport.setNIOChannelDistributor(new RoundRobinConnectionDistributor(transport, Boolean.parseBoolean(transportConfig.getDedicatedAcceptorEnabled())));
    filterChainBuilder.add(new TransportFilter());
}
Also used : TCPNIOTransport(org.glassfish.grizzly.nio.transport.TCPNIOTransport) ThreadPoolConfig(org.glassfish.grizzly.threadpool.ThreadPoolConfig) RoundRobinConnectionDistributor(org.glassfish.grizzly.nio.RoundRobinConnectionDistributor) TransportFilter(org.glassfish.grizzly.filterchain.TransportFilter) ByteBufferManager(org.glassfish.grizzly.memory.ByteBufferManager)

Example 2 with ByteBufferManager

use of org.glassfish.grizzly.memory.ByteBufferManager in project Payara by payara.

the class GrizzlyConfigTest method testDirectBufferConfiguration.

@Test
public void testDirectBufferConfiguration() throws Exception {
    GrizzlyConfig grizzlyConfig = null;
    try {
        configure();
        grizzlyConfig = new GrizzlyConfig("grizzly-direct-buffer.xml");
        grizzlyConfig.setupNetwork();
        final String bufferType = grizzlyConfig.getConfig().getNetworkListeners().getNetworkListener().get(0).findTransport().getByteBufferType();
        Assert.assertEquals("direct", bufferType);
        GenericGrizzlyListener genericGrizzlyListener = (GenericGrizzlyListener) getListener(grizzlyConfig, "http-listener-1");
        MemoryManager mm = genericGrizzlyListener.getTransport().getMemoryManager();
        assertEquals(ByteBufferManager.class.getName(), mm.getClass().getName());
        assertTrue(((ByteBufferManager) mm).isDirect());
    } finally {
        if (grizzlyConfig != null) {
            grizzlyConfig.shutdownNetwork();
            grizzlyConfig.shutdown();
        }
    }
}
Also used : MemoryManager(org.glassfish.grizzly.memory.MemoryManager) HeapMemoryManager(org.glassfish.grizzly.memory.HeapMemoryManager) ByteBufferManager(org.glassfish.grizzly.memory.ByteBufferManager) Test(org.junit.Test)

Aggregations

ByteBufferManager (org.glassfish.grizzly.memory.ByteBufferManager)2 TransportFilter (org.glassfish.grizzly.filterchain.TransportFilter)1 HeapMemoryManager (org.glassfish.grizzly.memory.HeapMemoryManager)1 MemoryManager (org.glassfish.grizzly.memory.MemoryManager)1 RoundRobinConnectionDistributor (org.glassfish.grizzly.nio.RoundRobinConnectionDistributor)1 TCPNIOTransport (org.glassfish.grizzly.nio.transport.TCPNIOTransport)1 ThreadPoolConfig (org.glassfish.grizzly.threadpool.ThreadPoolConfig)1 Test (org.junit.Test)1