@Override
  public void configure(final Binder binder) {
    final ExportBuilder builder = MBeanModule.newExporter(binder);

    binder.bind(PersistentWriterFactory.class).to(EventSpoolWriterFactory.class).asEagerSingleton();

    Multibinder<EventSpoolProcessor> defaultSpoolProcessors =
        Multibinder.newSetBinder(binder, EventSpoolProcessor.class);

    MapBinder<String, EventSpoolProcessor> perEventSpoolDispatchers =
        MapBinder.newMapBinder(binder, String.class, EventSpoolProcessor.class).permitDuplicates();

    String spoolWriterClasses = config.getSpoolWriterClassNames();
    final Iterable<String> spoolDispatcherClasses;

    if (!Strings.isNullOrEmpty(spoolWriterClasses)) {
      spoolDispatcherClasses =
          Splitter.on(",").trimResults().omitEmptyStrings().split(spoolWriterClasses);
    } else {
      spoolDispatcherClasses = Lists.newArrayList();
    }

    // Bind the classes for default spoolClasses
    for (String className : spoolDispatcherClasses) {
      try {
        defaultSpoolProcessors
            .addBinding()
            .to(Class.forName(className).asSubclass(EventSpoolProcessor.class))
            .asEagerSingleton();
      } catch (ClassNotFoundException e) {
        log.error("Could not bind " + className, e);
      }
    }

    // Find and bind the classes used for per event spool writers
    Map<String, Iterable<String>> perEventSpoolWriterClasses = getSpoolWriterClassesByEventType();

    for (Map.Entry<String, Iterable<String>> eventToSpoolWriters :
        perEventSpoolWriterClasses.entrySet()) {
      for (String spoolWriterClass : eventToSpoolWriters.getValue()) {

        try {
          perEventSpoolDispatchers
              .addBinding(eventToSpoolWriters.getKey())
              .to(Class.forName(spoolWriterClass).asSubclass(EventSpoolProcessor.class));
        } catch (ClassNotFoundException ex) {
          log.error("Could not bind " + spoolWriterClass, ex);
        }
      }
    }

    builder
        .export(EventSpoolWriterFactory.class)
        .as("com.ning.metrics.collector:name=EventSpoolWriter");
  }
Example #2
0
  @Override
  public void configure(Binder binder) {
    binder.requireExplicitBindings();
    binder.disableCircularProxies();

    binder.bind(NodeInfo.class).in(Scopes.SINGLETON);
    ConfigurationModule.bindConfig(binder).to(NodeConfig.class);
    MBeanModule.newExporter(binder).export(NodeInfo.class).withGeneratedName();
  }