io.datakernel.jmx.AttributeNodeForList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of datakernel-boot Show documentation
Show all versions of datakernel-boot Show documentation
An intelligent way of booting complex applications and services according to their dependencies
/*
* Copyright (C) 2015 SoftIndex LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.datakernel.jmx;
import javax.management.openmbean.*;
import java.lang.reflect.Array;
import java.util.*;
import static io.datakernel.util.CollectionUtils.first;
import static io.datakernel.util.Preconditions.checkArgument;
import static java.lang.String.format;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
final class AttributeNodeForList extends AttributeNodeForLeafAbstract {
private final AttributeNode subNode;
private final ArrayType> arrayType;
private final boolean isListOfJmxRefreshables;
public AttributeNodeForList(String name, String description, boolean visible, ValueFetcher fetcher, AttributeNode subNode,
boolean isListOfJmxRefreshables) {
super(name, description, fetcher, visible);
checkArgument(!name.isEmpty(), "List attribute cannot have empty name");
this.subNode = subNode;
this.arrayType = createArrayType(subNode, name);
this.isListOfJmxRefreshables = isListOfJmxRefreshables;
}
private static ArrayType> createArrayType(AttributeNode subNode, String name) {
String nodeName = "Attribute name = " + name;
Set visibleAttrs = subNode.getVisibleAttributes();
Map> attrTypes = subNode.getOpenTypes();
if (visibleAttrs.size() == 0) {
throw new IllegalArgumentException("Arrays must have at least one visible attribute. " + nodeName);
}
try {
OpenType> elementType;
if (visibleAttrs.size() == 1) {
String attr = first(visibleAttrs);
OpenType> openType = attrTypes.get(attr);
// TODO(vmykhalko): check this case
if (openType instanceof ArrayType) {
throw new IllegalArgumentException("Multidimensional arrays are note supported in JMX. " + nodeName);
}
elementType = openType;
} else {
List itemNames = new ArrayList<>();
List> itemTypes = new ArrayList<>();
for (String visibleAttr : visibleAttrs) {
OpenType> visibleAttrType = attrTypes.get(visibleAttr);
itemNames.add(visibleAttr);
itemTypes.add(visibleAttrType);
}
String[] itemNamesArr = itemNames.toArray(new String[itemNames.size()]);
OpenType>[] itemTypesArr = itemTypes.toArray(new OpenType>[itemTypes.size()]);
elementType =
new CompositeType("CompositeData", "CompositeData", itemNamesArr, itemNamesArr, itemTypesArr);
}
return new ArrayType
© 2015 - 2024 Weber Informatics LLC | Privacy Policy