org.weakref.jmx.guice.SetExportBinder Maven / Gradle / Ivy
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;
public class SetExportBinder
{
private final Multibinder> binder;
private final Class clazz;
SetExportBinder(Multibinder> binder, Class clazz)
{
this.binder = binder;
this.clazz = clazz;
}
public void withGeneratedName(final NamingFunction itemNamingFunction)
{
ObjectNameFunction objectNameFunction = new ObjectNameFunction()
{
public ObjectName name(T object)
{
try {
String itemName = itemNamingFunction.name(object);
return new ObjectName(ObjectNames.generatedNameOf(clazz, itemName));
}
catch (MalformedObjectNameException e) {
throw Throwables.propagate(e);
}
}
};
binder.addBinding().toInstance(new SetMapping(clazz, objectNameFunction));
}
public void withGeneratedName(final ObjectNameFunction itemNamingFunction)
{
ObjectNameFunction objectNameFunction = new ObjectNameFunction()
{
public ObjectName name(T object)
{
return itemNamingFunction.name(object);
}
};
binder.addBinding().toInstance(new SetMapping(clazz, objectNameFunction));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy