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;
019
020import java.io.IOException;
021import org.apache.hadoop.conf.Configuration;
022import org.apache.hadoop.fs.FileSystem;
023import org.apache.hadoop.hbase.client.ClusterConnection;
024import org.apache.hadoop.hbase.client.Connection;
025import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
026import org.apache.yetus.audience.InterfaceAudience;
027
028/**
029 * Defines a curated set of shared functions implemented by HBase servers (Masters and
030 * RegionServers). For use internally only. Be judicious adding API. Changes cause ripples through
031 * the code base.
032 */
033@InterfaceAudience.Private
034public interface Server extends Abortable, Stoppable {
035  /**
036   * Gets the configuration object for this server.
037   */
038  Configuration getConfiguration();
039
040  /**
041   * Gets the ZooKeeper instance for this server.
042   */
043  ZKWatcher getZooKeeper();
044
045  /**
046   * Returns a reference to the servers' connection. Important note: this method returns a reference
047   * to Connection which is managed by Server itself, so callers must NOT attempt to close
048   * connection obtained.
049   */
050  Connection getConnection();
051
052  Connection createConnection(Configuration conf) throws IOException;
053
054  /**
055   * Returns a reference to the servers' cluster connection. Prefer {@link #getConnection()}.
056   * Important note: this method returns a reference to Connection which is managed by Server
057   * itself, so callers must NOT attempt to close connection obtained.
058   */
059  ClusterConnection getClusterConnection();
060
061  /** Returns The unique server name for this server. */
062  ServerName getServerName();
063
064  /**
065   * Get CoordinatedStateManager instance for this server.
066   */
067  CoordinatedStateManager getCoordinatedStateManager();
068
069  /** Returns The {@link ChoreService} instance for this server */
070  ChoreService getChoreService();
071
072  /** Returns Return the FileSystem object used (can return null!). */
073  // TODO: Distinguish between "dataFs" and "walFs".
074  default FileSystem getFileSystem() {
075    // This default is pretty dodgy!
076    Configuration c = getConfiguration();
077    FileSystem fs = null;
078    try {
079      if (c != null) {
080        fs = FileSystem.get(c);
081      }
082    } catch (IOException e) {
083      // If an exception, just return null
084    }
085    return fs;
086  };
087
088  /** Returns True is the server is Stopping */
089  // Note: This method is not part of the Stoppable Interface.
090  default boolean isStopping() {
091    return false;
092  }
093}