io.activej.jmx.JmxBeanSettings Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of activej-jmx Show documentation
Show all versions of activej-jmx Show documentation
Implementation of ActiveJ JMX API.
/*
* Copyright (C) 2020 ActiveJ 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.activej.jmx;
import io.activej.jmx.DynamicMBeanFactory.JmxCustomTypeAdapter;
import java.lang.reflect.Type;
import java.util.*;
import static io.activej.common.Checks.checkArgument;
@SuppressWarnings("UnusedReturnValue")
public final class JmxBeanSettings {
private final Set includedOptionals = new HashSet<>();
private final Map> modifiers = new HashMap<>();
private final Map> customTypes = new HashMap<>();
private JmxBeanSettings(Set includedOptionals, Map> modifiers, Map> customTypes) {
this.includedOptionals.addAll(includedOptionals);
this.modifiers.putAll(modifiers);
this.customTypes.putAll(customTypes);
}
public static JmxBeanSettings of(Set includedOptionals,
Map> modifiers,
Map> customTypes) {
return new JmxBeanSettings(includedOptionals, modifiers, customTypes);
}
public static JmxBeanSettings create() {
return new JmxBeanSettings(new HashSet<>(), new HashMap<>(), new HashMap<>());
}
public static JmxBeanSettings defaultSettings() {
return new JmxBeanSettings(Collections.emptySet(), Collections.emptyMap(), Collections.emptyMap());
}
public void merge(JmxBeanSettings otherSettings) {
includedOptionals.addAll(otherSettings.includedOptionals);
modifiers.putAll(otherSettings.modifiers);
customTypes.putAll(otherSettings.customTypes);
}
public JmxBeanSettings withIncludedOptional(String attrName) {
includedOptionals.add(attrName);
return this;
}
public JmxBeanSettings withModifier(String attrName, AttributeModifier> modifier) {
checkArgument(!modifiers.containsKey(attrName), "cannot add two modifiers for one attribute");
modifiers.put(attrName, modifier);
return this;
}
public JmxBeanSettings withCustomTypes(Map> customTypes) {
this.customTypes.putAll(customTypes);
return this;
}
public Set getIncludedOptionals() {
return includedOptionals;
}
public Map> getModifiers() {
return modifiers;
}
public Map> getCustomTypes() {
return customTypes;
}
}