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.ha;
018
019import java.util.Collection;
020import java.util.List;
021import java.util.Optional;
022
023import org.apache.camel.CamelContextAware;
024import org.apache.camel.Service;
025
026/**
027 * Represents the View of the cluster at some given period of time.
028 */
029public interface CamelClusterView extends Service, CamelContextAware {
030    /**
031     * @return the cluster.
032     */
033    CamelClusterService getClusterService();
034
035    /**
036     * @return the namespace for this view.
037     */
038    String getNamespace();
039
040    /**
041     * Provides the master member if elected.
042     *
043     * @return the master member.
044     */
045    Optional<CamelClusterMember> getMaster();
046
047    /**
048     * Provides the local member.
049     *
050     * @return the local member.
051     */
052    CamelClusterMember getLocalMember();
053
054    /**
055     * Provides the list of members of the cluster.
056     *
057     * @return the list of members.
058     */
059    List<CamelClusterMember> getMembers();
060
061    /**
062     * Add an event listener.
063     *
064     * @param listener the event listener.
065     */
066    void addEventListener(CamelClusterEventListener listener);
067
068    /**
069     * Remove the event listener.
070     *
071     * @param listener the event listener.
072     */
073    void removeEventListener(CamelClusterEventListener listener);
074
075    /**
076     * Access the underlying concrete CamelClusterView implementation to
077     * provide access to further features.
078     *
079     * @param clazz the proprietary class or interface of the underlying concrete CamelClusterView.
080     * @return an instance of the underlying concrete CamelClusterView as the required type.
081     */
082    default <T extends CamelClusterView> T unwrap(Class<T> clazz) {
083        if (CamelClusterView.class.isAssignableFrom(clazz)) {
084            return clazz.cast(this);
085        }
086
087        throw new IllegalArgumentException(
088            "Unable to unwrap this CamelClusterView type (" + getClass() + ") to the required type (" + clazz + ")"
089        );
090    }
091}