Search in sources :

Example 71 with NetworkListener

use of org.glassfish.grizzly.config.dom.NetworkListener 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 72 with NetworkListener

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

the class ConfigListenerTest method changedTest.

@Test
public void changedTest() throws TransactionFailure {
    Transactions transactions = getHabitat().getService(Transactions.class);
    HttpListenerContainer container = registerAndCreateHttpListenerContainer(habitat);
    ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {

        @Override
        public Object run(NetworkListener param) {
            param.setPort("8989");
            return null;
        }
    }, container.httpListener);
    transactions.waitForDrain();
    assertTrue(container.received);
    ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(container.httpListener);
    bean.removeListener(container);
    // put back the right values in the domain to avoid test collisions
    ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {

        @Override
        public Object run(NetworkListener param) {
            param.setPort("8080");
            return null;
        }
    }, container.httpListener);
}
Also used : Transactions(org.jvnet.hk2.config.Transactions) ObservableBean(org.jvnet.hk2.config.ObservableBean) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Test(org.junit.Test)

Example 73 with NetworkListener

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

the class HttpListenerTest method setup.

@Before
public void setup() {
    NetworkListeners service = getHabitat().getService(NetworkListeners.class);
    assertTrue(service != null);
    for (NetworkListener item : service.getNetworkListener()) {
        if ("http-listener-1".equals(item.getName())) {
            listener = item;
            break;
        }
    }
    logger.fine("listener = " + listener);
    assertTrue(listener != null);
}
Also used : NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Before(org.junit.Before)

Example 74 with NetworkListener

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

the class WebContainerImpl method removeListener.

private void removeListener(String name) {
    try {
        NetworkListeners networkListeners = networkConfig.getNetworkListeners();
        final NetworkListener listenerToBeRemoved = networkConfig.getNetworkListener(name);
        final Protocols protocols = networkConfig.getProtocols();
        final Protocol protocol = networkConfig.findProtocol(name);
        if (listenerToBeRemoved == null) {
            log.severe("Network Listener " + name + " doesn't exist");
        } else {
            final com.sun.enterprise.config.serverbeans.VirtualServer virtualServer = httpService.getVirtualServerByName(listenerToBeRemoved.findHttpProtocol().getHttp().getDefaultVirtualServer());
            ConfigSupport.apply(new ConfigCode() {

                public Object run(ConfigBeanProxy... params) throws PropertyVetoException {
                    final NetworkListeners listeners = (NetworkListeners) params[0];
                    final com.sun.enterprise.config.serverbeans.VirtualServer server = (com.sun.enterprise.config.serverbeans.VirtualServer) params[1];
                    listeners.getNetworkListener().remove(listenerToBeRemoved);
                    server.removeNetworkListener(listenerToBeRemoved.getName());
                    return listenerToBeRemoved;
                }
            }, networkListeners, virtualServer);
            ConfigSupport.apply(new ConfigCode() {

                public Object run(ConfigBeanProxy... params) throws PropertyVetoException {
                    final Protocols protocols = (Protocols) params[0];
                    final Protocol protocol = (Protocol) params[1];
                    protocols.getProtocol().remove(protocol);
                    return protocol;
                }
            }, protocols, protocol);
        }
    } catch (TransactionFailure e) {
        log.severe("Remove listener " + name + " failed " + e.getMessage());
    }
}
Also used : Protocols(org.glassfish.grizzly.config.dom.Protocols) VirtualServer(org.glassfish.embeddable.web.VirtualServer) PropertyVetoException(java.beans.PropertyVetoException) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) Protocol(org.glassfish.grizzly.config.dom.Protocol) org.jvnet.hk2.config(org.jvnet.hk2.config) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Aggregations

NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)74 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)21 Protocol (org.glassfish.grizzly.config.dom.Protocol)18 Config (com.sun.enterprise.config.serverbeans.Config)17 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)14 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)12 Test (org.junit.Test)11 ActionReport (org.glassfish.api.ActionReport)10 CommandTarget (org.glassfish.config.support.CommandTarget)9 Target (org.glassfish.internal.api.Target)9 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)8 HttpService (com.sun.enterprise.config.serverbeans.HttpService)7 ArrayList (java.util.ArrayList)7 Protocols (org.glassfish.grizzly.config.dom.Protocols)7 ObservableBean (org.jvnet.hk2.config.ObservableBean)7 Transactions (org.jvnet.hk2.config.Transactions)7 IOException (java.io.IOException)6 Http (org.glassfish.grizzly.config.dom.Http)6 PropertyVetoException (java.beans.PropertyVetoException)5 ThreadPool (org.glassfish.grizzly.config.dom.ThreadPool)5