alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Hibernate example source code file (EhcacheHibernateMbeanNames.java)

This example Hibernate source code file (EhcacheHibernateMbeanNames.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Hibernate tags/keywords

ehcache_hibernate_type, ehcache_hibernate_type, ehcachehibernatembeannames, ehcachehibernatestats, group_id, group_id, malformedobjectnameexception, management, objectname, objectname, string, string

The Hibernate EhcacheHibernateMbeanNames.java source code

/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * Copyright (c) 2011, Red Hat Inc. or third-party contributors as
 * indicated by the @author tags or express copyright attribution
 * statements applied by the authors.  All third-party contributions are
 * distributed under license by Red Hat Inc.
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, write to:
 * Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor
 * Boston, MA  02110-1301  USA
 */
package org.hibernate.cache.ehcache.management.impl;

import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;

/**
 * Utility class used for getting {@link javax.management.ObjectName}'s for ehcache hibernate MBeans
 * <p/>
 * <p/>
 *
 * @author <a href="mailto:asanoujam@terracottatech.com">Abhishek Sanoujam
 * @since 1.7
 */
public abstract class EhcacheHibernateMbeanNames {

	/**
	 * Group id for all sampled mbeans registered
	 */
	public static final String GROUP_ID = "net.sf.ehcache.hibernate";

	/**
	 * Type for the ehcache backed hibernate second level cache statistics mbean
	 */
	public static final String EHCACHE_HIBERNATE_TYPE = "EhcacheHibernateStats";

	/**
	 * Filter out invalid ObjectName characters from s.
	 *
	 * @param s
	 *
	 * @return A valid JMX ObjectName attribute value.
	 */
	public static String mbeanSafe(String s) {
		return s == null ? "" : s.replaceAll( ":|=|\n", "." );
	}

	/**
	 * Returns an ObjectName for the passed name
	 *
	 * @param name
	 *
	 * @return An {@link javax.management.ObjectName} using the input name of cache manager
	 *
	 * @throws javax.management.MalformedObjectNameException
	 */
	public static ObjectName getCacheManagerObjectName(String cacheManagerClusterUUID, String name)
			throws MalformedObjectNameException {
		ObjectName objectName = new ObjectName(
				GROUP_ID + ":type=" + EHCACHE_HIBERNATE_TYPE + ",name=" + mbeanSafe( name )
						+ getBeanNameSuffix( cacheManagerClusterUUID )
		);
		return objectName;
	}

	private static String getBeanNameSuffix(String cacheManagerClusterUUID) {
		String suffix = "";
		if ( !isBlank( cacheManagerClusterUUID ) ) {
			suffix = ",node=" + cacheManagerClusterUUID;
		}
		return suffix;
	}

	private static boolean isBlank(String param) {
		return param == null || "".equals( param.trim() );
	}
}

Other Hibernate examples (source code examples)

Here is a short list of links related to this Hibernate EhcacheHibernateMbeanNames.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.