• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 The gRPC Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package io.grpc.grpclb;
18 
19 import io.grpc.Attributes;
20 import io.grpc.EquivalentAddressGroup;
21 import io.grpc.LoadBalancer.Helper;
22 import io.grpc.LoadBalancer.Subchannel;
23 import java.util.concurrent.ScheduledExecutorService;
24 import javax.annotation.concurrent.NotThreadSafe;
25 
26 /**
27  * Manages life-cycle of Subchannels for {@link GrpclbState}.
28  *
29  * <p>All methods are run from the ChannelExecutor that the helper uses.
30  */
31 @NotThreadSafe
32 interface SubchannelPool {
33   /**
34    * Pass essential utilities.
35    */
init(Helper helper, ScheduledExecutorService timerService)36   void init(Helper helper, ScheduledExecutorService timerService);
37 
38   /**
39    * Takes a {@link Subchannel} from the pool for the given {@code eag} if there is one available.
40    * Otherwise, creates and returns a new {@code Subchannel} with the given {@code eag} and {@code
41    * defaultAttributes}.
42    */
takeOrCreateSubchannel(EquivalentAddressGroup eag, Attributes defaultAttributes)43   Subchannel takeOrCreateSubchannel(EquivalentAddressGroup eag, Attributes defaultAttributes);
44 
45   /**
46    * Puts a {@link Subchannel} back to the pool.  From this point the Subchannel is owned by the
47    * pool.
48    */
returnSubchannel(Subchannel subchannel)49   void returnSubchannel(Subchannel subchannel);
50 
51   /**
52    * Shuts down all subchannels in the pool immediately.
53    */
clear()54   void clear();
55 }
56