/*
 * Druid - a distributed column store.
 * Copyright (C) 2012, 2013  Metamarkets Group Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package io.druid.guice;

import com.google.inject.Binder;
import com.google.inject.Key;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
import com.google.inject.multibindings.MapBinder;
import io.druid.cli.QueryJettyServerInitializer;
import io.druid.query.QuerySegmentWalker;
import io.druid.segment.realtime.DbSegmentPublisher;
import io.druid.segment.realtime.FireDepartment;
import io.druid.segment.realtime.NoopSegmentPublisher;
import io.druid.segment.realtime.RealtimeManager;
import io.druid.segment.realtime.SegmentPublisher;
import io.druid.server.QueryResource;
import io.druid.server.initialization.JettyServerInitializer;
import org.eclipse.jetty.server.Server;

import java.util.List;

/**
 */
public class RealtimeModule implements Module
{
  @Override
  public void configure(Binder binder)
  {
    PolyBind.createChoice(
        binder,
        "druid.publish.type",
        Key.get(SegmentPublisher.class),
        Key.get(DbSegmentPublisher.class)
    );
    final MapBinder<String, SegmentPublisher> publisherBinder = PolyBind.optionBinder(
        binder,
        Key.get(SegmentPublisher.class)
    );
    publisherBinder.addBinding("noop").to(NoopSegmentPublisher.class);
    binder.bind(DbSegmentPublisher.class).in(LazySingleton.class);

    JsonConfigProvider.bind(binder, "druid.realtime", RealtimeManagerConfig.class);
    binder.bind(new TypeLiteral<List<FireDepartment>>(){})
          .toProvider(FireDepartmentsProvider.class)
          .in(LazySingleton.class);

    binder.bind(QuerySegmentWalker.class).to(RealtimeManager.class).in(ManageLifecycle.class);
    binder.bind(NodeTypeConfig.class).toInstance(new NodeTypeConfig("realtime"));
    binder.bind(JettyServerInitializer.class).to(QueryJettyServerInitializer.class).in(LazySingleton.class);
    Jerseys.addResource(binder, QueryResource.class);
    LifecycleModule.register(binder, QueryResource.class);

    LifecycleModule.register(binder, Server.class);
  }
}

@@ -1364,32 +1364,242 @@
 gmentPublisher;%0A
+import io.druid.segment.realtime.firehose.ChatHandlerProvider;%0Aimport io.druid.segment.realtime.firehose.NoopChatHandlerProvider;%0Aimport io.druid.segment.realtime.firehose.ServiceAnnouncingChatHandlerProvider;%0A
 import io.druid.
@@ -2306,24 +2306,640 @@
 on.class);%0A%0A
+    PolyBind.createChoice(%0A        binder,%0A        %22druid.realtime.chathandler.type%22,%0A        Key.get(ChatHandlerProvider.class),%0A        Key.get(NoopChatHandlerProvider.class)%0A    );%0A    final MapBinder%3CString, ChatHandlerProvider%3E handlerProviderBinder = PolyBind.optionBinder(%0A        binder, Key.get(ChatHandlerProvider.class)%0A    );%0A    handlerProviderBinder.addBinding(%22announce%22)%0A                         .to(ServiceAnnouncingChatHandlerProvider.class).in(LazySingleton.class);%0A    handlerProviderBinder.addBinding(%22noop%22)%0A                         .to(NoopChatHandlerProvider.class).in(LazySingleton.class);%0A%0A
     JsonConf

add bindings for chat handler provider