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

com.carmatechnologies.commons.jmx.JmxConcurrentMap Maven / Gradle / Ivy

Go to download

Library of utilities to assist with developing applications monitored via JMX.

The newest version!
/*******************************************************************************
 * Copyright 2013 Marc CARRE (https://github.com/marccarre/commons-jmx)
 * 
 * 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 com.carmatechnologies.commons.jmx;

import static com.google.common.base.Preconditions.checkNotNull;

import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;

import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanRegistrationException;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;

import com.carmatechnologies.commons.jmx.MBeans.Builder;
import com.carmatechnologies.commons.jmx.mbeans.IJmxMap;

public class JmxConcurrentMap implements ConcurrentMap, IJmxMap {
	private final ConcurrentMap map;
	private final ObjectName objectName;

	public JmxConcurrentMap(final ConcurrentMap concurrentMap) throws InstanceAlreadyExistsException, MBeanRegistrationException,
			NotCompliantMBeanException, MalformedObjectNameException {
		checkNotNull(concurrentMap, "Concurrent map must NOT be null in order to be JMX-decorated.");
		this.map = concurrentMap;
		final Builder builder = new Builder(this);
		this.objectName = new ObjectName(builder.objectName());
		MBeans.register(builder);
	}

	public JmxConcurrentMap(final ConcurrentMap concurrentMap, final Builder builder) throws InstanceAlreadyExistsException, MBeanRegistrationException,
			NotCompliantMBeanException, MalformedObjectNameException {
		checkNotNull(concurrentMap, "Concurrent map must NOT be null in order to be JMX-decorated.");
		checkNotNull(builder, "MBean builder must NOT be null.");
		this.map = concurrentMap;
		this.objectName = new ObjectName(builder.mbean(this).objectName());
		MBeans.register(builder);
	}

	@Override
	public void clear() {
		map.clear();
	}

	@Override
	public boolean containsKey(final Object key) {
		return map.containsKey(key);
	}

	@Override
	public boolean containsValue(final Object value) {
		return map.containsValue(value);
	}

	@Override
	public Set> entrySet() {
		return map.entrySet();
	}

	@Override
	public V get(final Object key) {
		return map.get(key);
	}

	@Override
	public boolean isEmpty() {
		return map.isEmpty();
	}

	@Override
	public Set keySet() {
		return map.keySet();
	}

	@Override
	public V put(final K key, final V value) {
		return map.put(key, value);
	}

	@Override
	public void putAll(final Map m) {
		map.putAll(m);
	}

	@Override
	public V remove(final Object key) {
		return map.remove(key);
	}

	@Override
	public int size() {
		return map.size();
	}

	@Override
	public Collection values() {
		return map.values();
	}

	@Override
	public V putIfAbsent(final K key, final V value) {
		return map.putIfAbsent(key, value);
	}

	@Override
	public boolean remove(final Object key, final Object value) {
		return map.remove(key, value);
	}

	@Override
	public V replace(final K key, final V value) {
		return map.replace(key, value);
	}

	@Override
	public boolean replace(final K key, final V oldValue, final V newValue) {
		return map.replace(key, oldValue, newValue);
	}

	@Override
	public int getSize() {
		return size();
	}

	@Override
	public ObjectName objectName() {
		return objectName;
	}

	@Override
	public Map getItems() {
		final Map items = new LinkedHashMap();
		for (final Entry kvp : map.entrySet()) {
			items.put(kvp.getKey().toString(), kvp.getValue().toString());
		}
		return items;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy