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.procedure;
019
020import java.io.IOException;
021import org.apache.hadoop.conf.Configuration;
022import org.apache.hadoop.hbase.procedure.flush.RegionServerFlushTableProcedureManager;
023import org.apache.hadoop.hbase.regionserver.RegionServerServices;
024import org.apache.hadoop.hbase.regionserver.snapshot.RegionServerSnapshotManager;
025import org.apache.yetus.audience.InterfaceAudience;
026import org.apache.zookeeper.KeeperException;
027import org.slf4j.Logger;
028import org.slf4j.LoggerFactory;
029
030/**
031 * Provides the globally barriered procedure framework and environment
032 * for region server oriented operations.
033 * {@link org.apache.hadoop.hbase.regionserver.HRegionServer} interacts
034 * with the loaded procedure manager through this class.
035 */
036@InterfaceAudience.Private
037public class RegionServerProcedureManagerHost extends
038    ProcedureManagerHost<RegionServerProcedureManager> {
039
040  private static final Logger LOG = LoggerFactory
041      .getLogger(RegionServerProcedureManagerHost.class);
042
043  public void initialize(RegionServerServices rss) throws KeeperException {
044    for (RegionServerProcedureManager proc : procedures) {
045      LOG.debug("Procedure {} initializing", proc.getProcedureSignature());
046      proc.initialize(rss);
047      LOG.debug("Procedure {} initialized", proc.getProcedureSignature());
048    }
049  }
050
051  public void start() {
052    for (RegionServerProcedureManager proc : procedures) {
053      LOG.debug("Procedure {} starting", proc.getProcedureSignature());
054      proc.start();
055      LOG.debug("Procedure {} started", proc.getProcedureSignature());
056    }
057  }
058
059  public void stop(boolean force) {
060    for (RegionServerProcedureManager proc : procedures) {
061      try {
062        proc.stop(force);
063      } catch (IOException e) {
064        LOG.warn("Failed to close procedure " + proc.getProcedureSignature()
065            + " cleanly", e);
066      }
067    }
068  }
069
070  @Override
071  public void loadProcedures(Configuration conf) {
072    loadUserProcedures(conf, REGIONSERVER_PROCEDURE_CONF_KEY);
073    // load the default snapshot manager
074    procedures.add(new RegionServerSnapshotManager());
075    // load the default flush region procedure manager
076    procedures.add(new RegionServerFlushTableProcedureManager());
077  }
078
079}