1 /* 2 * Copyright 2010 The Apache Software Foundation 3 * 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 package org.apache.hadoop.hbase.replication; 21 22 import java.util.ArrayList; 23 import java.util.List; 24 import java.util.concurrent.atomic.AtomicBoolean; 25 26 import org.apache.hadoop.conf.Configuration; 27 import org.apache.hadoop.hbase.HServerAddress; 28 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher; 29 30 /** 31 * This class acts as a wrapper for all the objects used to identify and 32 * communicate with remote peers. Everything needs to be created for objects 33 * of this class as it doesn't encapsulate any specific functionality e.g. 34 * it's a container class. 35 */ 36 public class ReplicationPeer { 37 38 private final String clusterKey; 39 private final String id; 40 private List<HServerAddress> regionServers = 41 new ArrayList<HServerAddress>(0); 42 private final AtomicBoolean peerEnabled = new AtomicBoolean(); 43 // Cannot be final since a new object needs to be recreated when session fails 44 private ZooKeeperWatcher zkw; 45 private final Configuration conf; 46 47 /** 48 * Constructor that takes all the objects required to communicate with the 49 * specified peer, except for the region server addresses. 50 * @param conf configuration object to this peer 51 * @param key cluster key used to locate the peer 52 * @param id string representation of this peer's identifier 53 * @param zkw zookeeper connection to the peer 54 */ 55 public ReplicationPeer(Configuration conf, String key, 56 String id, ZooKeeperWatcher zkw) { 57 this.conf = conf; 58 this.clusterKey = key; 59 this.id = id; 60 this.zkw = zkw; 61 } 62 63 /** 64 * Get the cluster key of that peer 65 * @return string consisting of zk ensemble addresses, client port 66 * and root znode 67 */ 68 public String getClusterKey() { 69 return clusterKey; 70 } 71 72 /** 73 * Get the state of this peer 74 * @return atomic boolean that holds the status 75 */ 76 public AtomicBoolean getPeerEnabled() { 77 return peerEnabled; 78 } 79 80 /** 81 * Get a list of all the addresses of all the region servers 82 * for this peer cluster 83 * @return list of addresses 84 */ 85 public List<HServerAddress> getRegionServers() { 86 return regionServers; 87 } 88 89 /** 90 * Set the list of region servers for that peer 91 * @param regionServers list of addresses for the region servers 92 */ 93 public void setRegionServers(List<HServerAddress> regionServers) { 94 this.regionServers = regionServers; 95 } 96 97 /** 98 * Get the ZK connection to this peer 99 * @return zk connection 100 */ 101 public ZooKeeperWatcher getZkw() { 102 return zkw; 103 } 104 105 /** 106 * Get the identifier of this peer 107 * @return string representation of the id (short) 108 */ 109 public String getId() { 110 return id; 111 } 112 113 /** 114 * Get the configuration object required to communicate with this peer 115 * @return configuration object 116 */ 117 public Configuration getConfiguration() { 118 return conf; 119 } 120 }