001    /*
002     * Copyright 2010-2011 Ning, Inc.
003     *
004     * Ning licenses this file to you under the Apache License, version 2.0
005     * (the "License"); you may not use this file except in compliance with the
006     * License.  You may obtain a copy of the License at:
007     *
008     *    http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012     * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
013     * License for the specific language governing permissions and limitations
014     * under the License.
015     */
016    
017    package com.ning.metrics.eventtracker;
018    
019    import org.slf4j.Logger;
020    import org.slf4j.LoggerFactory;
021    
022    /**
023     * Wires all pieces related to talking to the Collector core.
024     * See http://github.com/pierre/collector
025     * <p/>
026     * Note that Guice injection is optional, you can directly instantiate a CollectorController
027     * via the factories.
028     */
029    public class CollectorControllerHttpModule extends CollectorControllerModule
030    {
031        private static final Logger log = LoggerFactory.getLogger(CollectorControllerHttpModule.class);
032    
033        @Override
034        protected void configure()
035        {
036            super.configure();
037    
038            switch (eventTrackerConfig.getType()) {
039                case COLLECTOR:
040                    final EventSender httpSender = new HttpSender(
041                        eventTrackerConfig.getCollectorHost(),
042                        eventTrackerConfig.getCollectorPort(),
043                        eventTrackerConfig.getEventType(),
044                        eventTrackerConfig.getHttpMaxWaitTimeInMillis()
045                    );
046                    bind(EventSender.class).toInstance(httpSender);
047                    log.info("Enabled HTTP Event Logging");
048                    break;
049                case NO_LOGGING:
050                    bind(EventSender.class).to(NoLoggingSender.class).asEagerSingleton();
051                    log.info("Disabled Event Logging");
052                    break;
053                default:
054                    throw new IllegalStateException("Unknown type " + eventTrackerConfig.getType());
055            }
056        }
057    }