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);
}
}
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);
}
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);
}
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());
}
}
Aggregations