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