001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel.health;
018
019import java.util.Collection;
020import java.util.Optional;
021import java.util.stream.Collectors;
022
023import org.apache.camel.CamelContextAware;
024import org.apache.camel.util.ObjectHelper;
025
026/**
027 * A registry for health checks.
028 * <p>
029 * Note that this registry can be superseded by the future camel context internal
030 * registry, @see <a href="https://issues.apache.org/jira/browse/CAMEL-10792"/>.
031 */
032public interface HealthCheckRegistry extends HealthCheckRepository, CamelContextAware {
033    /**
034     * Registers a service {@link HealthCheck}.
035     */
036    boolean register(HealthCheck check);
037
038    /**
039     * Unregisters a service {@link HealthCheck}.
040     */
041    boolean unregister(HealthCheck check);
042
043    /**
044     * Set the health check repositories to use..
045     */
046    void setRepositories(Collection<HealthCheckRepository> repositories);
047
048    /**
049     * Get a collection of health check repositories.
050     */
051    Collection<HealthCheckRepository> getRepositories();
052
053    /**
054     * Add an Health Check repository.
055     */
056    boolean addRepository(HealthCheckRepository repository);
057
058    /**
059     * Remove an Health Check repository.
060     */
061    boolean removeRepository(HealthCheckRepository repository);
062
063    /**
064     * A collection of health check IDs.
065     */
066    default Collection<String> getCheckIDs() {
067        return stream()
068            .map(HealthCheck::getId)
069            .collect(Collectors.toList());
070    }
071
072    /**
073     * Returns the check identified by the given <code>id</code> if available.
074     */
075    default Optional<HealthCheck> getCheck(String id) {
076        return stream()
077            .filter(check -> ObjectHelper.equal(check.getId(), id))
078            .findFirst();
079    }
080}