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