use of org.jvnet.hk2.config 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>() {
@Override
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 in project Payara by payara.
the class GrizzlyConfigSchemaMigrator method postConstruct.
@Override
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 in project Payara by payara.
the class TargetBasedResolver method getTarget.
private <T extends ConfigBeanProxy> T getTarget(Class<? extends ConfigBeanProxy> targetType, Class<T> type) throws ClassNotFoundException {
// when using the target based parameter, we look first for a configuration of that name,
// then we look for a cluster of that name and finally we look for a subelement of the right type
final String name = getName();
ConfigBeanProxy config = habitat.getService(targetType, target);
if (config != null) {
try {
return type.cast(config);
} catch (ClassCastException e) {
// ok we need to do more work to find which object is really requested.
}
Dom parentDom = Dom.unwrap(config);
String elementName = GenericCrudCommand.elementName(parentDom.document, targetType, type);
if (elementName == null) {
return null;
}
ConfigModel.Property property = parentDom.model.getElement(elementName);
if (property.isCollection()) {
Collection<Dom> collection;
synchronized (parentDom) {
collection = parentDom.nodeElements(elementName);
}
if (collection == null) {
return null;
}
for (Dom child : collection) {
if (name.equals(child.attribute("ref"))) {
return type.cast(child.<ConfigBeanProxy>createProxy());
}
}
}
}
return null;
}
use of org.jvnet.hk2.config in project Payara by payara.
the class BasicModularityTest method serializeConfigBean.
@Test
public void serializeConfigBean() {
Config config = habitat.<Config>getService(Config.class, ServerEnvironmentImpl.DEFAULT_INSTANCE_NAME);
ConfigBeanProxy prox = config.getExtensionByType(ConfigExtensionZero.class);
String content = configModularityUtils.serializeConfigBean(prox);
assertEquals("Cannot serialize config beans properly", "<config-extension-zero dummy=\"dummy-value\"></config-extension-zero>", content);
}
use of org.jvnet.hk2.config in project Payara by payara.
the class DeleteIiopListener method execute.
/**
* Executes the command with the command parameters passed as Properties
* where the keys are the parameter names and the values the parameter values
*
* @param context information
*/
@Override
public void execute(AdminCommandContext context) {
final Target targetUtil = services.getService(Target.class);
final Config config = targetUtil.getConfig(target);
ActionReport report = context.getActionReport();
IiopService iiopService = config.getExtensionByType(IiopService.class);
if (!isIIOPListenerExists(iiopService)) {
report.setMessage(localStrings.getLocalString("delete.iiop.listener" + ".notexists", "IIOP Listener {0} does not exist.", listener_id));
report.setActionExitCode(ExitCode.FAILURE);
return;
}
try {
ConfigSupport.apply(new SingleConfigCode<IiopService>() {
@Override
public Object run(IiopService param) throws PropertyVetoException, TransactionFailure {
List<IiopListener> listenerList = param.getIiopListener();
for (IiopListener listener : listenerList) {
String currListenerId = listener.getId();
if (currListenerId != null && currListenerId.equals(listener_id)) {
listenerList.remove(listener);
break;
}
}
return listenerList;
}
}, iiopService);
report.setActionExitCode(ExitCode.SUCCESS);
} catch (TransactionFailure e) {
String actual = e.getMessage();
report.setMessage(localStrings.getLocalString("delete.iiop.listener.fail", "failed", listener_id, actual));
report.setActionExitCode(ExitCode.FAILURE);
report.setFailureCause(e);
}
}
Aggregations