1818package  org .apache .hadoop .hbase .client ;
1919
2020import  java .io .IOException ;
21+ import  java .net .InetSocketAddress ;
2122import  java .net .SocketAddress ;
2223import  java .security .PrivilegedExceptionAction ;
2324import  org .apache .hadoop .conf .Configuration ;
25+ import  org .apache .hadoop .hbase .regionserver .HRegionServer ;
2426import  org .apache .hadoop .hbase .security .User ;
2527import  org .apache .hadoop .hbase .util .FutureUtils ;
2628import  org .apache .hadoop .hbase .util .ReflectionUtils ;
@@ -38,18 +40,8 @@ public final class ClusterConnectionFactory {
3840  private  ClusterConnectionFactory () {
3941  }
4042
41-   /** 
42-    * Create a new {@link AsyncClusterConnection} instance. 
43-    * <p/> 
44-    * Unlike what we have done in {@link ConnectionFactory}, here we just return an 
45-    * {@link AsyncClusterConnection} instead of a {@link java.util.concurrent.CompletableFuture}, 
46-    * which means this method could block on fetching the cluster id. This is just used to simplify 
47-    * the implementation, as when starting new region servers, we do not need to be event-driven. Can 
48-    * change later if we want a {@link java.util.concurrent.CompletableFuture} here. 
49-    */ 
50-   public  static  AsyncClusterConnection  createAsyncClusterConnection (Configuration  conf ,
51-       SocketAddress  localAddress , User  user ) throws  IOException  {
52-     ConnectionRegistry  registry  = ConnectionRegistryFactory .getRegistry (conf );
43+   private  static  AsyncClusterConnection  createAsyncClusterConnection (Configuration  conf ,
44+     ConnectionRegistry  registry , SocketAddress  localAddress , User  user ) throws  IOException  {
5345    String  clusterId  = FutureUtils .get (registry .getClusterId ());
5446    Class <? extends  AsyncClusterConnection > clazz  =
5547      conf .getClass (HBASE_SERVER_CLUSTER_CONNECTION_IMPL , AsyncClusterConnectionImpl .class ,
@@ -62,4 +54,32 @@ public static AsyncClusterConnection createAsyncClusterConnection(Configuration
6254      throw  new  IOException (e );
6355    }
6456  }
57+ 
58+   /** 
59+    * Create a new {@link AsyncClusterConnection} instance. 
60+    * <p/> 
61+    * Unlike what we have done in {@link ConnectionFactory}, here we just return an 
62+    * {@link AsyncClusterConnection} instead of a {@link java.util.concurrent.CompletableFuture}, 
63+    * which means this method could block on fetching the cluster id. This is just used to simplify 
64+    * the implementation, as when starting new region servers, we do not need to be event-driven. Can 
65+    * change later if we want a {@link java.util.concurrent.CompletableFuture} here. 
66+    */ 
67+   public  static  AsyncClusterConnection  createAsyncClusterConnection (Configuration  conf ,
68+     SocketAddress  localAddress , User  user ) throws  IOException  {
69+     return  createAsyncClusterConnection (conf , ConnectionRegistryFactory .getRegistry (conf ),
70+       localAddress , user );
71+   }
72+ 
73+   /** 
74+    * Create a new {@link AsyncClusterConnection} instance for a region server. 
75+    */ 
76+   public  static  AsyncClusterConnection  createAsyncClusterConnection (HRegionServer  regionServer )
77+     throws  IOException  {
78+     RegionServerRegistry  registry  = new  RegionServerRegistry (regionServer );
79+     Configuration  conf  = regionServer .getConfiguration ();
80+     InetSocketAddress  localAddress  =
81+       new  InetSocketAddress (regionServer .getRSRpcServices ().getSocketAddress ().getAddress (), 0 );
82+     User  user  = regionServer .getUserProvider ().getCurrent ();
83+     return  createAsyncClusterConnection (conf , registry , localAddress , user );
84+   }
6585}
0 commit comments