001/**
002 * Copyright 2015 DuraSpace, Inc.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * 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,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.fcrepo.metrics;
017
018import javax.servlet.annotation.WebListener;
019
020import com.codahale.metrics.MetricRegistry;
021import com.codahale.metrics.health.HealthCheckRegistry;
022import com.codahale.metrics.servlets.AdminServletContextListener;
023
024/**
025 * A ServletContextListener to set the ServletContext attributes that the
026 * Metrics servlets expect.
027 * 
028 * @author Edwin Shin
029 * @see <a
030 *      href="http://metrics.codahale.com/manual/servlets/">http://metrics.codahale.com/manual/servlets/</a>
031 */
032@WebListener
033public class MetricsContextListener extends AdminServletContextListener {
034
035    /**
036     * Get the metrics registry for fcrepo
037     * @return the metrics registry
038     */
039    @Override
040    protected MetricRegistry getMetricRegistry() {
041        return RegistryService.getInstance().getMetrics();
042    }
043
044    /**
045     * Provide a health-check registry
046     * TODO actually populate the health-check registry with checks
047     * @return a new health check registry
048     */
049    @Override
050    protected HealthCheckRegistry getHealthCheckRegistry() {
051        return new HealthCheckRegistry();
052    }
053}