Search in sources :

Example 31 with NetworkConfig

use of org.glassfish.grizzly.config.dom.NetworkConfig in project Payara by payara.

the class TransactionListenerTest method transactionEvents.

@Test
public void transactionEvents() throws Exception, TransactionFailure {
    httpService = getHabitat().getService(HttpService.class);
    NetworkConfig networkConfig = getHabitat().getService(NetworkConfig.class);
    final NetworkListener netListener = networkConfig.getNetworkListeners().getNetworkListener().get(0);
    final Http http = netListener.findHttpProtocol().getHttp();
    final TransactionListener listener = new TransactionListener() {

        public void transactionCommited(List<PropertyChangeEvent> changes) {
            events = changes;
        }

        public void unprocessedTransactedEvents(List<UnprocessedChangeEvents> changes) {
        }
    };
    Transactions transactions = getHabitat().getService(Transactions.class);
    try {
        transactions.addTransactionsListener(listener);
        assertTrue(httpService != null);
        logger.fine("Max connections = " + http.getMaxConnections());
        ConfigSupport.apply(new SingleConfigCode<Http>() {

            public Object run(Http param) {
                param.setMaxConnections("500");
                return null;
            }
        }, http);
        assertTrue("500".equals(http.getMaxConnections()));
        transactions.waitForDrain();
        assertTrue(events != null);
        logger.fine("Number of events " + events.size());
        assertTrue(events.size() == 1);
        PropertyChangeEvent event = events.iterator().next();
        assertTrue("max-connections".equals(event.getPropertyName()));
        assertTrue("500".equals(event.getNewValue().toString()));
        assertTrue("250".equals(event.getOldValue().toString()));
    } catch (Exception t) {
        t.printStackTrace();
        throw t;
    } finally {
        transactions.removeTransactionsListener(listener);
    }
    // put back the right values in the domain to avoid test collisions
    ConfigSupport.apply(new SingleConfigCode<Http>() {

        public Object run(Http param) {
            param.setMaxConnections("250");
            return null;
        }
    }, http);
}
Also used : TransactionListener(org.jvnet.hk2.config.TransactionListener) Transactions(org.jvnet.hk2.config.Transactions) PropertyChangeEvent(java.beans.PropertyChangeEvent) HttpService(com.sun.enterprise.config.serverbeans.HttpService) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) Http(org.glassfish.grizzly.config.dom.Http) List(java.util.List) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Test(org.junit.Test)

Example 32 with NetworkConfig

use of org.glassfish.grizzly.config.dom.NetworkConfig in project Payara by payara.

the class UnprocessedEventsTest method unprocessedEventsTest.

@Test
public void unprocessedEventsTest() throws TransactionFailure {
    // let's find our target
    NetworkConfig service = habitat.getService(NetworkConfig.class);
    NetworkListener listener = service.getNetworkListener("http-listener-1");
    assertNotNull(listener);
    // Let's register a listener
    ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(listener);
    bean.addListener(this);
    Transactions transactions = getHabitat().getService(Transactions.class);
    try {
        transactions.addTransactionsListener(this);
        String originalPort = listener.getPort();
        try {
            ConfigSupport.apply(param -> {
                param.setPort("8908");
                return null;
            }, listener);
            // Check the result.
            assertEquals(listener.getPort(), "8908");
        } finally {
            // Restore the original port
            ConfigSupport.apply(param -> {
                param.setPort(originalPort);
                return null;
            }, listener);
        }
        // ensure events are delivered.
        transactions.waitForDrain();
        assertNotNull(unprocessed);
        // finally
        bean.removeListener(this);
    } finally {
        // check we recevied the event
        transactions.removeTransactionsListener(this);
    }
}
Also used : Transactions(org.jvnet.hk2.config.Transactions) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) ObservableBean(org.jvnet.hk2.config.ObservableBean) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Test(org.junit.Test)

Example 33 with NetworkConfig

use of org.glassfish.grizzly.config.dom.NetworkConfig in project Payara by payara.

the class GrizzlyConfigSchemaMigrator method normalizeThreadPools.

private void normalizeThreadPools() throws TransactionFailure {
    ThreadPools threadPools = currentConfig.getThreadPools();
    if (threadPools == null) {
        threadPools = createThreadPools();
    } else {
        final List<ThreadPool> list = threadPools.getThreadPool();
        boolean httpListenerFound = false;
        for (ThreadPool pool : list) {
            httpListenerFound |= HTTP_THREAD_POOL.equals(pool.getThreadPoolId()) || HTTP_THREAD_POOL.equals(pool.getName());
            if (pool.getName() == null) {
                ConfigSupport.apply(new SingleConfigCode<ThreadPool>() {

                    public Object run(ThreadPool param) {
                        param.setName(param.getThreadPoolId());
                        param.setThreadPoolId(null);
                        if (param.getMinThreadPoolSize() == null || Integer.parseInt(param.getMinThreadPoolSize()) < 2) {
                            param.setMinThreadPoolSize("2");
                        }
                        return null;
                    }
                }, pool);
            }
        }
        if (!httpListenerFound) {
            ConfigSupport.apply(new SingleConfigCode<ThreadPools>() {

                public Object run(ThreadPools param) throws TransactionFailure {
                    final ThreadPool pool = param.createChild(ThreadPool.class);
                    pool.setName(HTTP_THREAD_POOL);
                    param.getThreadPool().add(pool);
                    return null;
                }
            }, threadPools);
        }
    }
    final NetworkConfig networkConfig = currentConfig.getNetworkConfig();
    if (networkConfig != null) {
        final NetworkListeners networkListeners = networkConfig.getNetworkListeners();
        if (networkListeners != null) {
            if (networkListeners.getThreadPool() != null && !networkListeners.getThreadPool().isEmpty()) {
                ConfigSupport.apply(new SingleConfigCode<ThreadPools>() {

                    public Object run(ThreadPools param) throws TransactionFailure {
                        migrateThreadPools(param);
                        return null;
                    }
                }, threadPools);
            }
        }
    }
}
Also used : ThreadPools(com.sun.enterprise.config.serverbeans.ThreadPools) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ThreadPool(org.glassfish.grizzly.config.dom.ThreadPool) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners)

Aggregations

NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)33 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)21 Config (com.sun.enterprise.config.serverbeans.Config)18 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)16 Protocol (org.glassfish.grizzly.config.dom.Protocol)14 ActionReport (org.glassfish.api.ActionReport)10 CommandTarget (org.glassfish.config.support.CommandTarget)10 Target (org.glassfish.internal.api.Target)10 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)6 Protocols (org.glassfish.grizzly.config.dom.Protocols)6 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)5 HttpService (com.sun.enterprise.config.serverbeans.HttpService)4 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)4 PropertyVetoException (java.beans.PropertyVetoException)3 Http (org.glassfish.grizzly.config.dom.Http)3 Ssl (org.glassfish.grizzly.config.dom.Ssl)3 Transport (org.glassfish.grizzly.config.dom.Transport)3 JavaConfig (com.sun.enterprise.config.serverbeans.JavaConfig)2 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)2 Result (com.sun.enterprise.util.Result)2