View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.hadoop.hbase.replication;
20  
21  import java.io.IOException;
22  import java.util.ArrayList;
23  
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  import org.apache.hadoop.hbase.classification.InterfaceAudience;
27  import org.apache.hadoop.hbase.HBaseInterfaceAudience;
28  import com.google.common.collect.Lists;
29  import com.google.common.util.concurrent.AbstractService;
30  
31  /**
32   * A Base implementation for {@link ReplicationEndpoint}s. Users should consider extending this
33   * class rather than implementing {@link ReplicationEndpoint} directly for better backwards
34   * compatibility.
35   */
36  @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.REPLICATION)
37  public abstract class BaseReplicationEndpoint extends AbstractService
38    implements ReplicationEndpoint {
39  
40    private static final Log LOG = LogFactory.getLog(BaseReplicationEndpoint.class);
41    protected Context ctx;
42  
43    @Override
44    public void init(Context context) throws IOException {
45      this.ctx = context;
46  
47      if (this.ctx != null){
48        ReplicationPeer peer = this.ctx.getReplicationPeer();
49        if (peer != null){
50          peer.trackPeerConfigChanges(this);
51        } else {
52          LOG.warn("Not tracking replication peer config changes for Peer Id " + this.ctx.getPeerId() +
53              " because there's no such peer");
54        }
55      }
56    }
57  
58    @Override
59    /**
60     * No-op implementation for subclasses to override if they wish to execute logic if their config changes
61     */
62    public void peerConfigUpdated(ReplicationPeerConfig rpc){
63  
64    }
65  
66    /** Returns a default set of filters */
67    @Override
68    public WALEntryFilter getWALEntryfilter() {
69      ArrayList<WALEntryFilter> filters = Lists.newArrayList();
70      WALEntryFilter scopeFilter = getScopeWALEntryFilter();
71      if (scopeFilter != null) {
72        filters.add(scopeFilter);
73      }
74      WALEntryFilter tableCfFilter = getTableCfWALEntryFilter();
75      if (tableCfFilter != null) {
76        filters.add(tableCfFilter);
77      }
78      return filters.isEmpty() ? null : new ChainWALEntryFilter(filters);
79    }
80  
81    /** Returns a WALEntryFilter for checking the scope. Subclasses can
82     * return null if they don't want this filter */
83    protected WALEntryFilter getScopeWALEntryFilter() {
84      return new ScopeWALEntryFilter();
85    }
86  
87    /** Returns a WALEntryFilter for checking replication per table and CF. Subclasses can
88     * return null if they don't want this filter */
89    protected WALEntryFilter getTableCfWALEntryFilter() {
90      return new TableCfWALEntryFilter(ctx.getReplicationPeer());
91    }
92  
93    @Override
94    public boolean canReplicateToSameCluster() {
95      return false;
96    }
97  
98  }