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  package org.apache.hadoop.hbase.procedure;
19  
20  import java.io.IOException;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  import org.apache.hadoop.conf.Configuration;
25  import org.apache.hadoop.hbase.procedure.flush.RegionServerFlushTableProcedureManager;
26  import org.apache.hadoop.hbase.regionserver.HRegionServer;
27  import org.apache.hadoop.hbase.regionserver.RegionServerServices;
28  import org.apache.hadoop.hbase.regionserver.snapshot.RegionServerSnapshotManager;
29  import org.apache.zookeeper.KeeperException;
30  
31  /**
32   * Provides the globally barriered procedure framework and environment
33   * for region server oriented operations.  {@link HRegionServer} interacts
34   * with the loaded procedure manager through this class.
35   */
36  public class RegionServerProcedureManagerHost extends
37      ProcedureManagerHost<RegionServerProcedureManager> {
38  
39    private static final Log LOG = LogFactory
40        .getLog(RegionServerProcedureManagerHost.class);
41  
42    public void initialize(RegionServerServices rss) throws KeeperException {
43      for (RegionServerProcedureManager proc : procedures) {
44        LOG.debug("Procedure " + proc.getProcedureSignature() + " is initializing");
45        proc.initialize(rss);
46        LOG.debug("Procedure " + proc.getProcedureSignature() + " is initialized");
47      }
48    }
49  
50    public void start() {
51      for (RegionServerProcedureManager proc : procedures) {
52        LOG.debug("Procedure " + proc.getProcedureSignature() + " is starting");
53        proc.start();
54        LOG.debug("Procedure " + proc.getProcedureSignature() + " is started");
55      }
56    }
57  
58    public void stop(boolean force) {
59      for (RegionServerProcedureManager proc : procedures) {
60        try {
61          proc.stop(force);
62        } catch (IOException e) {
63          LOG.warn("Failed to close procedure " + proc.getProcedureSignature()
64              + " cleanly", e);
65        }
66      }
67    }
68  
69    @Override
70    public void loadProcedures(Configuration conf) {
71      loadUserProcedures(conf, REGIONSERVER_PROCEDURE_CONF_KEY);
72      // load the default snapshot manager
73      procedures.add(new RegionServerSnapshotManager());
74      // load the default flush region procedure manager
75      procedures.add(new RegionServerFlushTableProcedureManager());
76    }
77  
78  }