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.hadoop.hbase.classification.InterfaceAudience;
25 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
26 import com.google.common.collect.Lists;
27 import com.google.common.util.concurrent.AbstractService;
28
29 /**
30 * A Base implementation for {@link ReplicationEndpoint}s. Users should consider extending this
31 * class rather than implementing {@link ReplicationEndpoint} directly for better backwards
32 * compatibility.
33 */
34 @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.REPLICATION)
35 public abstract class BaseReplicationEndpoint extends AbstractService
36 implements ReplicationEndpoint {
37
38 protected Context ctx;
39
40 @Override
41 public void init(Context context) throws IOException {
42 this.ctx = context;
43 }
44
45 /** Returns a default set of filters */
46 @Override
47 public WALEntryFilter getWALEntryfilter() {
48 ArrayList<WALEntryFilter> filters = Lists.newArrayList();
49 WALEntryFilter scopeFilter = getScopeWALEntryFilter();
50 if (scopeFilter != null) {
51 filters.add(scopeFilter);
52 }
53 WALEntryFilter tableCfFilter = getTableCfWALEntryFilter();
54 if (tableCfFilter != null) {
55 filters.add(tableCfFilter);
56 }
57 return filters.isEmpty() ? null : new ChainWALEntryFilter(filters);
58 }
59
60 /** Returns a WALEntryFilter for checking the scope. Subclasses can
61 * return null if they don't want this filter */
62 protected WALEntryFilter getScopeWALEntryFilter() {
63 return new ScopeWALEntryFilter();
64 }
65
66 /** Returns a WALEntryFilter for checking replication per table and CF. Subclasses can
67 * return null if they don't want this filter */
68 protected WALEntryFilter getTableCfWALEntryFilter() {
69 return new TableCfWALEntryFilter(ctx.getReplicationPeer());
70 }
71
72 @Override
73 public boolean canReplicateToSameCluster() {
74 return false;
75 }
76
77 }