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