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 /** Returns The unique server name for this server. */ 076 ServerName getServerName(); 077 078 /** 079 * Get CoordinatedStateManager instance for this server. 080 */ 081 CoordinatedStateManager getCoordinatedStateManager(); 082 083 /** Returns The {@link ChoreService} instance for this server */ 084 ChoreService getChoreService(); 085 086 /** Returns Return the FileSystem object used (can return null!). */ 087 // TODO: Distinguish between "dataFs" and "walFs". 088 default FileSystem getFileSystem() { 089 // This default is pretty dodgy! 090 Configuration c = getConfiguration(); 091 FileSystem fs = null; 092 try { 093 if (c != null) { 094 fs = FileSystem.get(c); 095 } 096 } catch (IOException e) { 097 // If an exception, just return null 098 } 099 return fs; 100 } 101 102 /** Returns True is the server is Stopping */ 103 // Note: This method is not part of the Stoppable Interface. 104 default boolean isStopping() { 105 return false; 106 } 107}