org.weakref.jmx.guice.ExportBinder 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 com.google.inject.Binder;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
import com.google.inject.multibindings.Multibinder;
import static com.google.inject.multibindings.Multibinder.newSetBinder;
public class ExportBinder
{
private final Multibinder binder;
private final Multibinder> collectionBinder;
private final Multibinder> mapBinder;
ExportBinder(Multibinder binder, Multibinder> collectionBinder, Multibinder> mapBinder)
{
this.binder = binder;
this.collectionBinder = collectionBinder;
this.mapBinder = mapBinder;
}
public static ExportBinder newExporter(Binder binder)
{
Multibinder> collectionBinder = newSetBinder(binder, new TypeLiteral>() {});
Multibinder> mapBinder = newSetBinder(binder, new TypeLiteral>() {});
return new ExportBinder(newSetBinder(binder, Mapping.class), collectionBinder, mapBinder);
}
public AnnotatedExportBinder export(Class> clazz)
{
return new AnnotatedExportBinder(binder, Key.get(clazz));
}
public NamedExportBinder export(Key> key)
{
return new NamedExportBinder(binder, key);
}
public SetExportBinder exportSet(Class clazz)
{
return new SetExportBinder(collectionBinder, clazz);
}
public StringMapExportBinder exportMap(Class valueClass)
{
return new StringMapExportBinder(mapBinder, valueClass);
}
public MapExportBinder exportMap(Class keyClass, Class valueClass)
{
return new MapExportBinder(mapBinder, keyClass, valueClass);
}
}