use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class GrizzlyConfigSchemaMigrator method promoteVirtualServerProperties.
private void promoteVirtualServerProperties(HttpService service) throws TransactionFailure {
for (VirtualServer virtualServer : service.getVirtualServer()) {
ConfigSupport.apply(new SingleConfigCode<VirtualServer>() {
@Override
public Object run(VirtualServer param) throws PropertyVetoException {
if (param.getHttpListeners() != null && !"".equals(param.getHttpListeners())) {
param.setNetworkListeners(param.getHttpListeners());
}
param.setHttpListeners(null);
final List<Property> propertyList = new ArrayList<Property>(param.getProperty());
final Iterator<Property> it = propertyList.iterator();
while (it.hasNext()) {
final Property property = it.next();
if ("docroot".equals(property.getName())) {
param.setDocroot(property.getValue());
it.remove();
} else if ("accesslog".equals(property.getName())) {
param.setAccessLog(property.getValue());
it.remove();
} else if ("sso-enabled".equals(property.getName())) {
param.setSsoEnabled(property.getValue());
it.remove();
}
}
param.getProperty().clear();
param.getProperty().addAll(propertyList);
return null;
}
}, virtualServer);
}
}
use of org.jvnet.hk2.config.SingleConfigCode 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.SingleConfigCode 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.SingleConfigCode in project Payara by payara.
the class DuplicateKeyedElementTest method identicalKeyTest.
@Test(expected = TransactionFailure.class)
public void identicalKeyTest() throws TransactionFailure {
HttpService httpService = getHabitat().getService(HttpService.class);
assertNotNull(httpService);
// let's find a acceptable target.
VirtualServer target = null;
for (VirtualServer vs : httpService.getVirtualServer()) {
if (!vs.getProperty().isEmpty()) {
target = vs;
break;
}
}
assertNotNull(target);
Property newProp = (Property) ConfigSupport.apply(new SingleConfigCode<VirtualServer>() {
public Object run(VirtualServer param) throws PropertyVetoException, TransactionFailure {
// first one is fine...
Property firstProp = param.createChild(Property.class);
firstProp.setName("foo");
firstProp.setValue("bar");
param.getProperty().add(firstProp);
// this should fail...
Property secondProp = param.createChild(Property.class);
secondProp.setName("foo");
secondProp.setValue("bar");
param.getProperty().add(secondProp);
return secondProp;
}
}, target);
// if we arrive here, this is an error, we succeeded adding a property with
// the same key name.
assertTrue(false);
}
use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class HttpServiceTest method validTransaction.
@Test
public void validTransaction() throws TransactionFailure {
final String max = listener.findHttpProtocol().getHttp().getMaxConnections();
ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {
public Object run(NetworkListener okToChange) throws TransactionFailure {
final Http http = okToChange.createChild(Http.class);
http.setMaxConnections("100");
http.setTimeoutSeconds("65");
http.setFileCache(http.createChild(FileCache.class));
ConfigSupport.apply(new SingleConfigCode<Protocol>() {
@Override
public Object run(Protocol param) {
param.setHttp(http);
return null;
}
}, okToChange.findHttpProtocol());
return http;
}
}, listener);
ConfigSupport.apply(new SingleConfigCode<Http>() {
@Override
public Object run(Http param) {
param.setMaxConnections(max);
return null;
}
}, listener.findHttpProtocol().getHttp());
try {
ConfigSupport.apply(new SingleConfigCode<Http>() {
public Object run(Http param) throws TransactionFailure {
param.setMaxConnections("7");
throw new TransactionFailure("Sorry, changed my mind", null);
}
}, listener.findHttpProtocol().getHttp());
} catch (TransactionFailure e) {
logger.fine("good, got my exception about changing my mind");
}
}
Aggregations