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

com.carmatechnologies.commons.jmx.JmxLinkedBlockingQueue 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.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

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.IJmxSequence;

public class JmxLinkedBlockingQueue extends LinkedBlockingQueue implements Iterable, Collection, BlockingQueue, Queue, IJmxSequence {
	private static final long serialVersionUID = 2961777229338139054L;

	private final LinkedBlockingQueue queue;
	private final ObjectName objectName;

	public JmxLinkedBlockingQueue(final LinkedBlockingQueue queue) throws InstanceAlreadyExistsException, MBeanRegistrationException,
			NotCompliantMBeanException, MalformedObjectNameException {
		checkNotNull(queue, "Linked blocking queue must NOT be null in order to be JMX-decorated.");
		this.queue = queue;
		final Builder builder = new Builder(this);
		this.objectName = new ObjectName(builder.objectName());
		MBeans.register(builder);
	}

	public JmxLinkedBlockingQueue(LinkedBlockingQueue queue, Builder builder) throws InstanceAlreadyExistsException, MBeanRegistrationException,
			NotCompliantMBeanException, MalformedObjectNameException {
		checkNotNull(queue, "Linked blocking queue must NOT be null in order to be JMX-decorated.");
		checkNotNull(builder, "MBean builder must NOT be null.");
		this.queue = queue;
		this.objectName = new ObjectName(builder.mbean(this).objectName());
		MBeans.register(builder);
	}

	@Override
	public E element() {
		return queue.element();
	}

	@Override
	public E peek() {
		return queue.peek();
	}

	@Override
	public E poll() {
		return queue.poll();
	}

	@Override
	public E remove() {
		return queue.remove();
	}

	@Override
	public int drainTo(Collection c) {
		return queue.drainTo(c);
	}

	@Override
	public int drainTo(Collection c, int maxElements) {
		return queue.drainTo(c, maxElements);
	}

	@Override
	public boolean offer(E e) {
		return queue.offer(e);
	}

	@Override
	public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException {
		return queue.offer(e, timeout, unit);
	}

	@Override
	public E poll(long timeout, TimeUnit unit) throws InterruptedException {
		return queue.poll(timeout, unit);
	}

	@Override
	public void put(E e) throws InterruptedException {
		queue.put(e);
	}

	@Override
	public int remainingCapacity() {
		return queue.remainingCapacity();
	}

	@Override
	public E take() throws InterruptedException {
		return queue.take();
	}

	@Override
	public boolean add(E e) {
		return queue.add(e);
	}

	@Override
	public boolean addAll(Collection c) {
		return queue.addAll(c);
	}

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

	@Override
	public boolean contains(Object o) {
		return queue.contains(o);
	}

	@Override
	public boolean containsAll(Collection c) {
		return queue.containsAll(c);
	}

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

	@Override
	public boolean remove(Object o) {
		return queue.remove(o);
	}

	@Override
	public boolean removeAll(Collection c) {
		return queue.removeAll(c);
	}

	@Override
	public boolean retainAll(Collection c) {
		return queue.retainAll(c);
	}

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

	@Override
	public Object[] toArray() {
		return queue.toArray();
	}

	@Override
	public  T[] toArray(T[] a) {
		return queue.toArray(a);
	}

	@Override
	public Iterator iterator() {
		return queue.iterator();
	}

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

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

	@Override
	public List getItems() {
		final List items = new ArrayList();
		for (final E item : queue) {
			items.add(item.toString());
		}
		return items;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy