001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.replication;
019
020import java.util.List;
021import java.util.Map;
022import java.util.Set;
023import org.apache.hadoop.conf.Configuration;
024import org.apache.hadoop.hbase.HBaseInterfaceAudience;
025import org.apache.hadoop.hbase.TableName;
026import org.apache.yetus.audience.InterfaceAudience;
027
028/**
029 * ReplicationPeer manages enabled / disabled state for the peer.
030 */
031@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.REPLICATION)
032public interface ReplicationPeer {
033
034  /**
035   * State of the peer, whether it is enabled or not
036   */
037  @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.REPLICATION)
038  enum PeerState {
039    ENABLED,
040    DISABLED
041  }
042
043  /**
044   * Get the identifier of this peer
045   * @return string representation of the id
046   */
047  String getId();
048
049  /**
050   * Returns the state of the peer by reading local cache.
051   * @return the enabled state
052   */
053  PeerState getPeerState();
054
055  /**
056   * Returns the sync replication state of the peer by reading local cache.
057   * <p>
058   * If the peer is not a synchronous replication peer, a {@link SyncReplicationState#NONE} will be
059   * returned.
060   * @return the sync replication state
061   */
062  SyncReplicationState getSyncReplicationState();
063
064  /**
065   * Test whether the peer is enabled.
066   * @return {@code true} if enabled, otherwise {@code false}.
067   */
068  default boolean isPeerEnabled() {
069    return getPeerState() == PeerState.ENABLED;
070  }
071
072  /**
073   * Get the peer config object
074   * @return the ReplicationPeerConfig for this peer
075   */
076  ReplicationPeerConfig getPeerConfig();
077
078  /**
079   * Get the configuration object required to communicate with this peer
080   * @return configuration object
081   */
082  Configuration getConfiguration();
083
084  /**
085   * Get replicable (table, cf-list) map of this peer
086   * @return the replicable (table, cf-list) map
087   */
088  Map<TableName, List<String>> getTableCFs();
089
090  /**
091   * Get replicable namespace set of this peer
092   * @return the replicable namespaces set
093   */
094  Set<String> getNamespaces();
095
096  /**
097   * Get the per node bandwidth upper limit for this peer
098   * @return the bandwidth upper limit
099   */
100  long getPeerBandwidth();
101
102  /**
103   * Register a peer config listener to catch the peer config change event.
104   * @param listener listener to catch the peer config change event.
105   */
106  void registerPeerConfigListener(ReplicationPeerConfigListener listener);
107
108  /**
109   * @deprecated since 2.1.0 and will be removed in 4.0.0. Use
110   *             {@link #registerPeerConfigListener(ReplicationPeerConfigListener)} instead.
111   * @see #registerPeerConfigListener(ReplicationPeerConfigListener)
112   * @see <a href="https://issues.apache.org/jira/browse/HBASE-10573">HBASE-19573</a>
113   */
114  @Deprecated
115  default void trackPeerConfigChanges(ReplicationPeerConfigListener listener) {
116    registerPeerConfigListener(listener);
117  }
118}