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 030 * and RegionServers). For use internally only. Be judicious adding API. Changes cause ripples 031 * through 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. 047 * 048 * Important note: this method returns a reference to Connection which is managed 049 * by Server itself, so callers must NOT attempt to close connection obtained. 050 */ 051 Connection getConnection(); 052 053 Connection createConnection(Configuration conf) throws IOException; 054 055 /** 056 * Returns a reference to the servers' cluster connection. Prefer {@link #getConnection()}. 057 * 058 * Important note: this method returns a reference to Connection which is managed 059 * by Server itself, so callers must NOT attempt to close connection obtained. 060 */ 061 ClusterConnection getClusterConnection(); 062 063 /** 064 * @return The unique server name for this server. 065 */ 066 ServerName getServerName(); 067 068 /** 069 * Get CoordinatedStateManager instance for this server. 070 */ 071 CoordinatedStateManager getCoordinatedStateManager(); 072 073 /** 074 * @return The {@link ChoreService} instance for this server 075 */ 076 ChoreService getChoreService(); 077 078 /** 079 * @return Return the FileSystem object used (can return null!). 080 */ 081 // TODO: On Master, return Master's. On RegionServer, return RegionServers. The FileSystems 082 // may differ. TODO. 083 default FileSystem getFileSystem() { 084 // This default is pretty dodgy! 085 Configuration c = getConfiguration(); 086 FileSystem fs = null; 087 try { 088 if (c != null) { 089 fs = FileSystem.get(c); 090 } 091 } catch (IOException e) { 092 // If an exception, just return null 093 } 094 return fs; 095 }; 096 097 /** 098 * @return True is the server is Stopping 099 */ 100 // Note: This method is not part of the Stoppable Interface. 101 default boolean isStopping() { 102 return false; 103 } 104}