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