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