use of org.wildfly.swarm.spi.api.config.ConfigKey in project wildfly-swarm by wildfly-swarm.
the class ConfigurableManager method scanSubresources.
protected void scanSubresources(ConfigKey prefix, Object instance) throws Exception {
Method method = getSubresourcesMethod(instance);
if (method == null) {
return;
}
Object subresources = method.invoke(instance);
Field[] fields = subresources.getClass().getDeclaredFields();
for (Field field : fields) {
if (field.getAnnotation(SubresourceInfo.class) == null && List.class.isAssignableFrom(field.getType())) {
continue;
}
field.setAccessible(true);
Object value = field.get(subresources);
ConfigKey subPrefix = prefix.append(nameFor(field));
if (seen(subPrefix)) {
continue;
}
if (value != null && value instanceof List) {
int index = 0;
Set<SimpleKey> seenKeys = new HashSet<>();
for (Object each : ((List) value)) {
SimpleKey key = getKey(each);
ConfigKey itemPrefix = null;
if (key != null) {
seenKeys.add(key);
itemPrefix = subPrefix.append(key);
} else {
itemPrefix = subPrefix.append("" + index);
}
scan(itemPrefix, each, true);
++index;
}
List<SimpleKey> keysWithConfiguration = this.configView.simpleSubkeys(subPrefix);
keysWithConfiguration.removeAll(seenKeys);
if (!keysWithConfiguration.isEmpty()) {
Method factoryMethod = getKeyedFactoryMethod(instance, field);
if (factoryMethod != null) {
for (SimpleKey key : keysWithConfiguration) {
ConfigKey itemPrefix = subPrefix.append(key);
Object lambda = createLambda(itemPrefix, factoryMethod);
if (lambda != null) {
factoryMethod.invoke(instance, key.name(), lambda);
}
}
}
}
} else {
// Singleton resources, without key
if (value == null) {
// configuration keys that imply we want it.
if (this.configView.hasKeyOrSubkeys(subPrefix)) {
Method factoryMethod = getNonKeyedFactoryMethod(instance, field);
if (factoryMethod != null) {
Object lambda = createLambda(subPrefix, factoryMethod);
if (lambda != null) {
factoryMethod.invoke(instance, lambda);
}
}
}
} else {
scan(subPrefix, value, true);
}
}
}
}
use of org.wildfly.swarm.spi.api.config.ConfigKey in project wildfly-swarm by wildfly-swarm.
the class ConfigurableManager method scanFraction.
protected void scanFraction(Fraction fraction) throws Exception {
ConfigKey prefix = nameFor(fraction);
scan(prefix, fraction, true);
}
use of org.wildfly.swarm.spi.api.config.ConfigKey in project wildfly-swarm by wildfly-swarm.
the class ConfigurableManager method createLambda.
protected Object createLambda(ConfigKey itemPrefix, Method factoryMethod) {
MethodHandles.Lookup lookup = MethodHandles.lookup();
// The consumer is the last parameter
Class<?> consumerType = factoryMethod.getParameterTypes()[factoryMethod.getParameterCount() - 1];
try {
Method acceptMethod = null;
for (Method method : consumerType.getMethods()) {
if (method.getName().equals(ACCEPT)) {
acceptMethod = method;
}
}
if (acceptMethod == null) {
return null;
}
MethodHandle target = lookup.findVirtual(ConfigurableManager.class, "subresourceAdded", MethodType.methodType(void.class, ConfigKey.class, Object.class));
MethodType samType = MethodType.methodType(void.class, acceptMethod.getParameterTypes()[0]);
MethodHandle mh = LambdaMetafactory.metafactory(lookup, ACCEPT, MethodType.methodType(consumerType, ConfigurableManager.class, ConfigKey.class), samType, target, samType).getTarget();
return mh.invoke(this, itemPrefix);
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
use of org.wildfly.swarm.spi.api.config.ConfigKey in project wildfly-swarm by wildfly-swarm.
the class NetworkConfigurer method applyConfiguration.
protected void applyConfiguration(ConfigKey root, SocketBinding binding) {
ConfigKey key = root.append(binding.name());
applyConfiguration(key.append("port"), (port) -> {
binding.port(port.toString());
});
applyConfiguration(key.append("multicast-port"), (port) -> {
binding.multicastPort(port.toString());
});
applyConfiguration(key.append("multicast-address"), (addr) -> {
binding.multicastAddress(addr.toString());
});
applyConfiguration(key.append("interface"), (iface) -> {
binding.iface(iface.toString());
});
}
use of org.wildfly.swarm.spi.api.config.ConfigKey in project wildfly-swarm by wildfly-swarm.
the class ConfigNode method valueOf.
/**
* Retrieve a value.
*
* @param key The possibly-complex key of the value to retrieve.
* @return The value of {@code null} if none.
*/
public Object valueOf(ConfigKey key) {
SimpleKey head = key.head();
if (head == ConfigKey.EMPTY) {
if (this.value == null && this.children != null) {
return this;
}
return this.value;
}
ConfigNode child = child(head);
if (child != null) {
ConfigKey rest = key.subkey(1);
return child.valueOf(rest);
}
return null;
}
Aggregations