All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.datakernel.jmx.MBeanSettings Maven / Gradle / Ivy

Go to download

An intelligent way of booting complex applications and services according to their dependencies

There is a newer version: 3.1.0
Show newest version
/*
 * 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 io.datakernel.jmx.JmxMBeans.JmxCustomTypeAdapter;

import java.lang.reflect.Type;
import java.util.*;

import static io.datakernel.util.Preconditions.checkArgument;

public final class MBeanSettings {
	private final Set includedOptionals = new HashSet<>();
	private final Map> modifiers = new HashMap<>();
	private final Map> customTypes = new HashMap<>();

	private MBeanSettings(Set includedOptionals, Map> modifiers, Map> customTypes) {
		this.includedOptionals.addAll(includedOptionals);
		this.modifiers.putAll(modifiers);
		this.customTypes.putAll(customTypes);
	}

	public static MBeanSettings of(Set includedOptionals,
	                               Map> modifiers,
	                               Map> customTypes) {
		return new MBeanSettings(includedOptionals, modifiers, customTypes);
	}

	public static MBeanSettings defaultSettings() {
		return new MBeanSettings(new HashSet<>(), new HashMap<>(), Collections.emptyMap());
	}

	public void merge(MBeanSettings otherSettings) {
		includedOptionals.addAll(otherSettings.includedOptionals);
		modifiers.putAll(otherSettings.modifiers);
		customTypes.putAll(otherSettings.customTypes);
	}

	public MBeanSettings withIncludedOptional(String attrName) {
		includedOptionals.add(attrName);
		return this;
	}

	public MBeanSettings withModifier(String attrName, AttributeModifier modifier) {
		checkArgument(!modifiers.containsKey(attrName), "cannot add two modifiers for one attribute");
		modifiers.put(attrName, modifier);
		return this;
	}

	public MBeanSettings withCustomTypes(Map> customTypes) {
		this.customTypes.putAll(customTypes);
		return this;
	}

	public Set getIncludedOptionals() {
		return includedOptionals;
	}

	public Map> getModifiers() {
		return modifiers;
	}

	public Map> getCustomTypes() {
		return customTypes;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy