use of org.jvnet.hk2.config.TransactionFailure in project Payara by payara.
the class GrizzlyConfigSchemaMigrator method postConstruct.
public void postConstruct() {
for (Config config : configs.getConfig()) {
currentConfig = config;
try {
final NetworkConfig networkConfig = currentConfig.getNetworkConfig();
if (networkConfig == null) {
createFromScratch();
}
normalizeThreadPools();
if (currentConfig.getHttpService() != null) {
promoteHttpServiceProperties(currentConfig.getHttpService());
promoteVirtualServerProperties(currentConfig.getHttpService());
} else {
// this only happens during some unit tests
logger.log(Level.WARNING, ConfigApiLoggerInfo.nullHttpService, new String[] { currentConfig.getName() });
}
promoteSystemProperties();
addAsadminProtocol(currentConfig.getNetworkConfig());
} catch (TransactionFailure tf) {
logger.log(Level.SEVERE, ConfigApiLoggerInfo.failUpgradeDomain, tf);
throw new RuntimeException(tf);
}
}
}
use of org.jvnet.hk2.config.TransactionFailure in project Payara by payara.
the class GrizzlyConfigSchemaMigrator method addAsadminProtocol.
private void addAsadminProtocol(NetworkConfig config) throws TransactionFailure {
ensureAdminThreadPool();
final Protocols protocols = getProtocols(config);
Protocol adminProtocol = protocols.findProtocol(ASADMIN_LISTENER);
if (adminProtocol == null) {
adminProtocol = (Protocol) ConfigSupport.apply(new SingleConfigCode<Protocols>() {
public Object run(Protocols param) throws TransactionFailure {
final Protocol protocol = param.createChild(Protocol.class);
param.getProtocol().add(protocol);
protocol.setName(ASADMIN_LISTENER);
Http http = protocol.createChild(Http.class);
http.setFileCache(http.createChild(FileCache.class));
protocol.setHttp(http);
http.setDefaultVirtualServer(ASADMIN_VIRTUAL_SERVER);
http.setMaxConnections("250");
return protocol;
}
}, protocols);
}
for (NetworkListener listener : adminProtocol.findNetworkListeners()) {
ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {
@Override
public Object run(NetworkListener param) {
param.setThreadPool("admin-thread-pool");
return null;
}
}, listener);
}
}
use of org.jvnet.hk2.config.TransactionFailure in project Payara by payara.
the class ConfigListenerTest method removeListenerTest.
@Test
public void removeListenerTest() throws TransactionFailure {
Transactions transactions = getHabitat().getService(Transactions.class);
HttpListenerContainer container = registerAndCreateHttpListenerContainer(habitat);
ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(container.httpListener);
bean.removeListener(container);
ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {
@Override
public Object run(NetworkListener param) {
param.setPort("8989");
return null;
}
}, container.httpListener);
transactions.waitForDrain();
assertFalse(container.received);
// 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.jvnet.hk2.config.TransactionFailure in project Payara by payara.
the class ConfigPersistence method test.
@Test
public void test() throws TransactionFailure {
final DomDocument document = getDocument(getHabitat());
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.reset();
final ConfigurationPersistence testPersistence = new ConfigurationPersistence() {
public void save(DomDocument doc) throws IOException, XMLStreamException {
XMLOutputFactory factory = XMLOutputFactory.newInstance();
XMLStreamWriter writer = factory.createXMLStreamWriter(baos);
doc.writeTo(new IndentingXMLStreamWriter(writer));
writer.close();
}
};
TransactionListener testListener = new TransactionListener() {
public void transactionCommited(List<PropertyChangeEvent> changes) {
try {
testPersistence.save(document);
} catch (IOException e) {
// To change body of catch statement use File | Settings | File Templates.
e.printStackTrace();
} catch (XMLStreamException e) {
// To change body of catch statement use File | Settings | File Templates.
e.printStackTrace();
}
}
public void unprocessedTransactedEvents(List<UnprocessedChangeEvents> changes) {
}
};
Transactions transactions = getHabitat().getService(Transactions.class);
try {
transactions.addTransactionsListener(testListener);
doTest();
} catch (TransactionFailure f) {
f.printStackTrace();
throw f;
} finally {
transactions.waitForDrain();
transactions.removeTransactionsListener(testListener);
}
// now check if we persisted correctly...
final String resultingXml = baos.toString();
logger.fine(resultingXml);
assertTrue("assertResult from " + getClass().getName() + " was false from " + resultingXml, assertResult(resultingXml));
}
use of org.jvnet.hk2.config.TransactionFailure in project Payara by payara.
the class DirectAccessTest method doTest.
public void doTest() throws TransactionFailure {
NetworkConfig networkConfig = habitat.getService(NetworkConfig.class);
final NetworkListener listener = networkConfig.getNetworkListeners().getNetworkListener().get(0);
final Http http = listener.findHttpProtocol().getHttp();
ConfigBean config = (ConfigBean) ConfigBean.unwrap(http.getFileCache());
ConfigBean config2 = (ConfigBean) ConfigBean.unwrap(http);
Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
Map<String, String> configChanges = new HashMap<String, String>();
configChanges.put("max-age-seconds", "12543");
configChanges.put("max-cache-size-bytes", "1200");
Map<String, String> config2Changes = new HashMap<String, String>();
config2Changes.put("http2-enabled", "false");
changes.put(config, configChanges);
changes.put(config2, config2Changes);
JavaConfig javaConfig = habitat.getService(JavaConfig.class);
ConfigBean javaConfigBean = (ConfigBean) ConfigBean.unwrap(javaConfig);
Map<String, String> javaConfigChanges = new HashMap<String, String>();
javaConfigChanges.put("jvm-options", "-XFooBar=false");
changes.put(javaConfigBean, javaConfigChanges);
getHabitat().<ConfigSupport>getService(ConfigSupport.class).apply(changes);
}
Aggregations