org.weakref.jmx.guice.StringMapExportBinder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jmxutils Show documentation
Show all versions of jmxutils Show documentation
Exporting JMX mbeans made easy
package org.weakref.jmx.guice;
import org.weakref.jmx.internal.guava.base.Throwables;
import com.google.inject.multibindings.Multibinder;
import org.weakref.jmx.ObjectNames;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import java.util.Map;
import java.util.Map.Entry;
public class StringMapExportBinder
extends MapExportBinder
{
private final Class valueClass;
StringMapExportBinder(Multibinder> binder, Class valueClass)
{
super(binder, String.class, valueClass);
this.valueClass = valueClass;
}
public void withGeneratedName()
{
ObjectNameFunction> namingFunction = new ObjectNameFunction>()
{
public ObjectName name(Map.Entry entry)
{
try {
return new ObjectName(ObjectNames.generatedNameOf(valueClass, entry.getKey()));
}
catch (MalformedObjectNameException e) {
throw Throwables.propagate(e);
}
}
};
binder.addBinding().toInstance(new MapMapping(String.class, valueClass, namingFunction));
}
}