001/* 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019package org.apache.hadoop.hbase; 020 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.MetaTableLocator; 026import org.apache.hadoop.hbase.zookeeper.ZKWatcher; 027import org.apache.yetus.audience.InterfaceAudience; 028 029import java.io.IOException; 030 031/** 032 * Defines a curated set of shared functions implemented by HBase servers (Masters 033 * and RegionServers). For use internally only. Be judicious adding API. Changes cause ripples 034 * through the code base. 035 */ 036@InterfaceAudience.Private 037public interface Server extends Abortable, Stoppable { 038 /** 039 * Gets the configuration object for this server. 040 */ 041 Configuration getConfiguration(); 042 043 /** 044 * Gets the ZooKeeper instance for this server. 045 */ 046 ZKWatcher getZooKeeper(); 047 048 /** 049 * Returns a reference to the servers' connection. 050 * 051 * Important note: this method returns a reference to Connection which is managed 052 * by Server itself, so callers must NOT attempt to close connection obtained. 053 */ 054 Connection getConnection(); 055 056 Connection createConnection(Configuration conf) throws IOException; 057 058 /** 059 * Returns a reference to the servers' cluster connection. Prefer {@link #getConnection()}. 060 * 061 * Important note: this method returns a reference to Connection which is managed 062 * by Server itself, so callers must NOT attempt to close connection obtained. 063 */ 064 ClusterConnection getClusterConnection(); 065 066 /** 067 * Returns instance of {@link org.apache.hadoop.hbase.zookeeper.MetaTableLocator} 068 * running inside this server. This MetaServerLocator is started and stopped by server, clients 069 * shouldn't manage it's lifecycle. 070 * @return instance of {@link MetaTableLocator} associated with this server. 071 */ 072 MetaTableLocator getMetaTableLocator(); 073 074 /** 075 * @return The unique server name for this server. 076 */ 077 ServerName getServerName(); 078 079 /** 080 * Get CoordinatedStateManager instance for this server. 081 */ 082 CoordinatedStateManager getCoordinatedStateManager(); 083 084 /** 085 * @return The {@link ChoreService} instance for this server 086 */ 087 ChoreService getChoreService(); 088 089 /** 090 * @return Return the FileSystem object used (can return null!). 091 */ 092 // TODO: On Master, return Master's. On RegionServer, return RegionServers. The FileSystems 093 // may differ. TODO. 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}