use of org.jvnet.hk2.config.Attribute in project Payara by payara.
the class LogManagerService method generateAttributeChangeEvent.
public void generateAttributeChangeEvent(String property, String propertyDetail, Map props) {
PropertyChangeEvent pce = new PropertyChangeEvent(this, property, propertyDetail, props.get(property));
UnprocessedChangeEvents ucel = new UnprocessedChangeEvents(new UnprocessedChangeEvent(pce, "server log file attribute " + property + " changed."));
List<UnprocessedChangeEvents> b = new ArrayList();
b.add(ucel);
ucl.unprocessedTransactedEvents(b);
}
use of org.jvnet.hk2.config.Attribute in project Payara by payara.
the class ResourceUtil method getMethodMetaData2.
public static MethodMetaData getMethodMetaData2(Dom parent, ConfigModel childModel, int parameterType) {
MethodMetaData methodMetaData = new MethodMetaData();
List<Class<?>> interfaces = new ArrayList<Class<?>>();
Map<String, ParameterMetaData> params = new HashMap<String, ParameterMetaData>();
try {
Class<? extends ConfigBeanProxy> configBeanProxy = (Class<? extends ConfigBeanProxy>) childModel.classLoaderHolder.loadClass(childModel.targetTypeName);
getInterfaces(configBeanProxy, interfaces);
Set<String> attributeNames = childModel.getAttributeNames();
for (String attributeName : attributeNames) {
String methodName = ResourceUtil.getAttributeMethodName(attributeName);
// camelCase the attributeName before passing out
attributeName = Util.eleminateHypen(attributeName);
ParameterMetaData parameterMetaData = params.get(attributeName);
if (parameterMetaData == null) {
parameterMetaData = new ParameterMetaData();
params.put(attributeName, parameterMetaData);
}
// Check parent interfaces
for (int i = interfaces.size() - 1; i >= 0; i--) {
Class<?> intf = interfaces.get(i);
try {
Method method = intf.getMethod(methodName);
Attribute attribute = method.getAnnotation(Attribute.class);
if (attribute != null) {
ParameterMetaData localParam = ResourceUtil.getParameterMetaData(attribute);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.DEFAULT_VALUE);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.KEY);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.TYPE);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.OPTIONAL);
}
} catch (NoSuchMethodException e) {
}
}
// Check ConfigBean
try {
Method method = configBeanProxy.getMethod(methodName);
Attribute attribute = method.getAnnotation(Attribute.class);
if (attribute != null) {
ParameterMetaData localParam = ResourceUtil.getParameterMetaData(attribute);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.DEFAULT_VALUE);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.KEY);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.TYPE);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.OPTIONAL);
}
} catch (NoSuchMethodException e) {
}
methodMetaData.putParameterMetaData(attributeName, parameterMetaData);
}
} catch (MultiException cnfe) {
throw new RuntimeException(cnfe);
}
return methodMetaData;
}
use of org.jvnet.hk2.config.Attribute in project Payara by payara.
the class ResourceUtil method getMethodMetaData.
/**
* Constructs and returns the resource method meta-data. This method is
* called to get meta-data in case of update method (POST).
*
* @param configBeanModel the config bean associated with the resource.
* @return MethodMetaData the meta-data store for the resource method.
*/
public static MethodMetaData getMethodMetaData(ConfigModel configBeanModel) {
MethodMetaData methodMetaData = new MethodMetaData();
Class<? extends ConfigBeanProxy> configBeanProxy = null;
try {
configBeanProxy = (Class<? extends ConfigBeanProxy>) configBeanModel.classLoaderHolder.loadClass(configBeanModel.targetTypeName);
Set<String> attributeNames = configBeanModel.getAttributeNames();
for (String attributeName : attributeNames) {
String methodName = getAttributeMethodName(attributeName);
Method method = null;
try {
method = configBeanProxy.getMethod(methodName);
} catch (NoSuchMethodException e) {
// Method not found, so let's try a brute force method if the method
// can't be found via the method above. For example: for
// Ssl.getSSLInactivityTimeout(), we calculate getSslInactivityTimeout,
// which doesn't match due to case.
String booleanMethodName = getAttributeBooleanMethodName(attributeName);
for (Method m : configBeanProxy.getMethods()) {
if (m.getName().equalsIgnoreCase(methodName) || m.getName().equalsIgnoreCase(booleanMethodName)) {
method = m;
}
}
}
Attribute attribute = method.getAnnotation(Attribute.class);
if (attribute != null) {
ParameterMetaData parameterMetaData = getParameterMetaData(attribute);
if (method.getAnnotation(Deprecated.class) != null) {
parameterMetaData.putAttribute(Constants.DEPRECATED, "true");
}
// camelCase the attributeName before passing out
attributeName = eleminateHypen(attributeName);
methodMetaData.putParameterMetaData(attributeName, parameterMetaData);
}
}
} catch (MultiException e) {
e.printStackTrace();
}
return methodMetaData;
}
use of org.jvnet.hk2.config.Attribute in project Payara by payara.
the class DynamicConfigListener method changed.
@Override
public synchronized UnprocessedChangeEvents changed(final PropertyChangeEvent[] events) {
return ConfigSupport.sortAndDispatch(events, new Changed() {
@Override
public <T extends ConfigBeanProxy> NotProcessed changed(TYPE type, Class<T> tClass, T t) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "NetworkConfig changed {0} {1} {2}", new Object[] { type, tClass, t });
}
if (tClass == NetworkListener.class && t instanceof NetworkListener) {
return processNetworkListener(type, (NetworkListener) t, events);
} else if (tClass == Http.class && t instanceof Http) {
return processProtocol(type, (Protocol) t.getParent(), events);
} else if (tClass == FileCache.class && t instanceof FileCache) {
return processProtocol(type, (Protocol) t.getParent().getParent(), null);
} else if (tClass == Ssl.class && t instanceof Ssl) {
/*
* Make sure the SSL parent is in fact a protocol. It could
* be a jmx-connector.
*/
final ConfigBeanProxy parent = t.getParent();
if (parent instanceof Protocol) {
return processProtocol(type, (Protocol) parent, null);
}
} else if (tClass == Protocol.class && t instanceof Protocol) {
return processProtocol(type, (Protocol) t, null);
} else if (tClass == ThreadPool.class && t instanceof ThreadPool) {
NotProcessed notProcessed = null;
ThreadPool threadPool = (ThreadPool) t;
for (NetworkListener listener : threadPool.findNetworkListeners()) {
notProcessed = processNetworkListener(type, listener, null);
}
// Throw an unprocessed event change if one hasn't already if HTTP or ThreadPool monitoring is enabled.
MonitoringService ms = config.getMonitoringService();
String threadPoolLevel = ms.getModuleMonitoringLevels().getThreadPool();
String httpServiceLevel = ms.getModuleMonitoringLevels().getHttpService();
if (((threadPoolLevel != null && !threadPoolLevel.equals(OFF)) || (httpServiceLevel != null && !httpServiceLevel.equals(OFF))) && notProcessed == null) {
notProcessed = new NotProcessed("Monitoring statistics will be incorrect for " + threadPool.getName() + " until restart due to changed attribute(s).");
}
return notProcessed;
} else if (tClass == Transport.class && t instanceof Transport) {
NotProcessed notProcessed = null;
for (NetworkListener listener : ((Transport) t).findNetworkListeners()) {
notProcessed = processNetworkListener(type, listener, null);
}
return notProcessed;
} else if (tClass == VirtualServer.class && t instanceof VirtualServer && !grizzlyService.hasMapperUpdateListener()) {
return processVirtualServer(type, (VirtualServer) t);
} else if (tClass == SystemProperty.class && t instanceof SystemProperty) {
NetworkConfig networkConfig = config.getNetworkConfig();
if ((networkConfig != null) && ((SystemProperty) t).getName().endsWith("LISTENER_PORT")) {
for (NetworkListener listener : networkConfig.getNetworkListeners().getNetworkListener()) {
if (listener.getPort().equals(((SystemProperty) t).getValue())) {
return processNetworkListener(Changed.TYPE.CHANGE, listener, events);
}
}
}
return null;
}
return null;
}
}, logger);
}
use of org.jvnet.hk2.config.Attribute in project Payara by payara.
the class SetCommand method set.
private boolean set(AdminCommandContext context, SetOperation op) {
String pattern = op.pattern;
String value = op.value;
String target = op.target;
String attrName = op.attrName;
boolean isProperty = op.isProperty;
// now
// first let's get the parent for this pattern.
TreeNode[] parentNodes = getAliasedParent(domain, pattern);
// reset the pattern.
String prefix;
boolean lookAtSubNodes = true;
if (parentNodes[0].relativeName.length() == 0 || parentNodes[0].relativeName.equals("domain")) {
// handle the case where the pattern references an attribute of the top-level node
prefix = "";
// pattern is already set properly
lookAtSubNodes = false;
} else if (!pattern.startsWith(parentNodes[0].relativeName)) {
prefix = pattern.substring(0, pattern.indexOf(parentNodes[0].relativeName));
pattern = parentNodes[0].relativeName;
} else {
prefix = "";
pattern = parentNodes[0].relativeName;
}
String targetName = prefix + pattern;
if (modularityHelper != null) {
synchronized (utils) {
boolean oldv = utils.isCommandInvocation();
utils.setCommandInvocation(true);
modularityHelper.getLocationForDottedName(targetName);
utils.setCommandInvocation(oldv);
}
}
Map<Dom, String> matchingNodes;
boolean applyOverrideRules = false;
Map<Dom, String> dottedNames = new HashMap<Dom, String>();
if (lookAtSubNodes) {
for (TreeNode parentNode : parentNodes) {
dottedNames.putAll(getAllDottedNodes(parentNode.node));
}
matchingNodes = getMatchingNodes(dottedNames, pattern);
applyOverrideRules = true;
} else {
matchingNodes = new HashMap<Dom, String>();
for (TreeNode parentNode : parentNodes) {
matchingNodes.put(parentNode.node, pattern);
}
}
if (matchingNodes.isEmpty()) {
// it's possible they are trying to create a property object.. lets check this.
// strip out the property name
pattern = target.substring(0, trueLastIndexOf(target, '.'));
if (pattern.endsWith("property")) {
// need to find the right parent.
Dom parentNode = null;
if ("property".equals(pattern)) {
// create and set the property
try {
final String fname = attrName;
final String fvalue = value;
ConfigSupport.apply(new SingleConfigCode<Domain>() {
@Override
public Object run(Domain domain) throws PropertyVetoException, TransactionFailure {
Property p = domain.createChild(Property.class);
p.setName(fname);
p.setValue(fvalue);
domain.getProperty().add(p);
return p;
}
}, domain);
success(context, targetName, value);
runLegacyChecks(context);
if (targetService.isThisDAS() && !replicateSetCommand(context, target, value)) {
return false;
}
return true;
} catch (TransactionFailure transactionFailure) {
// fail(context, "Could not change the attributes: " +
// transactionFailure.getMessage(), transactionFailure);
fail(context, localStrings.getLocalString("admin.set.attribute.change.failure", "Could not change the attributes: {0}", transactionFailure.getMessage()), transactionFailure);
return false;
}
} else {
pattern = pattern.substring(0, trueLastIndexOf(pattern, '.'));
parentNodes = getAliasedParent(domain, pattern);
}
pattern = parentNodes[0].relativeName;
matchingNodes = getMatchingNodes(dottedNames, pattern);
if (matchingNodes.isEmpty()) {
// fail(context, "No configuration found for " + targetName);
fail(context, localStrings.getLocalString("admin.set.configuration.notfound", "No configuration found for {0}", targetName));
return false;
}
for (Map.Entry<Dom, String> node : matchingNodes.entrySet()) {
if (node.getValue().equals(pattern)) {
parentNode = node.getKey();
}
}
if (parentNode == null) {
// fail(context, "No configuration found for " + targetName);
fail(context, localStrings.getLocalString("admin.set.configuration.notfound", "No configuration found for {0}", targetName));
return false;
}
if (value == null || value.length() == 0) {
// setting to the empty string means to remove the property, so don't create it
success(context, targetName, value);
return true;
}
// create and set the property
Map<String, String> attributes = new HashMap<String, String>();
attributes.put("value", value);
attributes.put("name", attrName);
try {
if (!(parentNode instanceof ConfigBean)) {
final ClassCastException cce = new ClassCastException(parentNode.getClass().getName());
fail(context, localStrings.getLocalString("admin.set.attribute.change.failure", "Could not change the attributes: {0}", cce.getMessage(), cce));
return false;
}
ConfigSupport.createAndSet((ConfigBean) parentNode, Property.class, attributes);
success(context, targetName, value);
runLegacyChecks(context);
if (targetService.isThisDAS() && !replicateSetCommand(context, target, value)) {
return false;
}
return true;
} catch (TransactionFailure transactionFailure) {
// fail(context, "Could not change the attributes: " +
// transactionFailure.getMessage(), transactionFailure);
fail(context, localStrings.getLocalString("admin.set.attribute.change.failure", "Could not change the attributes: {0}", transactionFailure.getMessage()), transactionFailure);
return false;
}
}
}
Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
boolean setElementSuccess = false;
boolean delPropertySuccess = false;
boolean delProperty = false;
Map<String, String> attrChanges = new HashMap<String, String>();
if (isProperty) {
attrName = "value";
if ((value == null) || (value.length() == 0)) {
delProperty = true;
}
attrChanges.put(attrName, value);
}
List<Map.Entry> mNodes = new ArrayList(matchingNodes.entrySet());
if (applyOverrideRules) {
mNodes = applyOverrideRules(mNodes);
}
for (Map.Entry<Dom, String> node : mNodes) {
final Dom targetNode = node.getKey();
for (String name : targetNode.model.getAttributeNames()) {
String finalDottedName = node.getValue() + "." + name;
if (matches(finalDottedName, pattern)) {
if (attrName.equals(name) || attrName.replace('_', '-').equals(name.replace('_', '-'))) {
if (isDeprecatedAttr(targetNode, name)) {
warning(context, localStrings.getLocalString("admin.set.deprecated", "Warning: The attribute {0} is deprecated.", finalDottedName));
}
if (!isProperty) {
targetName = prefix + finalDottedName;
if (value != null && value.length() > 0) {
attrChanges.put(name, value);
} else {
attrChanges.put(name, null);
}
} else {
targetName = prefix + node.getValue();
}
if (delProperty) {
// delete property element
String str = node.getValue();
if (trueLastIndexOf(str, '.') != -1) {
str = str.substring(trueLastIndexOf(str, '.') + 1);
}
try {
if (str != null) {
ConfigSupport.deleteChild((ConfigBean) targetNode.parent(), (ConfigBean) targetNode);
delPropertySuccess = true;
}
} catch (IllegalArgumentException ie) {
fail(context, localStrings.getLocalString("admin.set.delete.property.failure", "Could not delete the property: {0}", ie.getMessage()), ie);
return false;
} catch (TransactionFailure transactionFailure) {
fail(context, localStrings.getLocalString("admin.set.attribute.change.failure", "Could not change the attributes: {0}", transactionFailure.getMessage()), transactionFailure);
return false;
}
} else {
changes.put((ConfigBean) node.getKey(), attrChanges);
}
}
}
}
for (String name : targetNode.model.getLeafElementNames()) {
String finalDottedName = node.getValue() + "." + name;
if (matches(finalDottedName, pattern)) {
if (attrName.equals(name) || attrName.replace('_', '-').equals(name.replace('_', '-'))) {
if (isDeprecatedAttr(targetNode, name)) {
warning(context, localStrings.getLocalString("admin.set.elementdeprecated", "Warning: The element {0} is deprecated.", finalDottedName));
}
try {
setLeafElement((ConfigBean) targetNode, name, value);
} catch (TransactionFailure ex) {
fail(context, localStrings.getLocalString("admin.set.badelement", "Cannot change the element: {0}", ex.getMessage()), ex);
return false;
}
setElementSuccess = true;
break;
}
}
}
}
if (!changes.isEmpty()) {
try {
config.apply(changes);
success(context, targetName, value);
runLegacyChecks(context);
} catch (TransactionFailure transactionFailure) {
// fail(context, "Could not change the attributes: " +
// transactionFailure.getMessage(), transactionFailure);
fail(context, localStrings.getLocalString("admin.set.attribute.change.failure", "Could not change the attributes: {0}", transactionFailure.getMessage()), transactionFailure);
return false;
}
} else if (delPropertySuccess || setElementSuccess) {
success(context, targetName, value);
} else {
fail(context, localStrings.getLocalString("admin.set.configuration.notfound", "No configuration found for {0}", targetName));
return false;
}
if (targetService.isThisDAS() && !replicateSetCommand(context, target, value)) {
return false;
}
return true;
}
Aggregations