content: /*
   * Copyright 2020 Alibaba Group Holding Limited.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package com.alibaba.graphscope.groot.servers.ir;
  
  import com.alibaba.graphscope.common.client.channel.ChannelFetcher;
  import com.alibaba.graphscope.groot.common.RoleType;
  import com.alibaba.graphscope.groot.rpc.ChannelManager;
  import com.alibaba.pegasus.RpcChannel;
  
  import java.util.ArrayList;
  import java.util.List;
  
  public class RpcChannelManagerFetcher implements ChannelFetcher<RpcChannel> {
      private final ChannelManager manager;
      private final int nodeCount;
      private final RoleType targetRole;
  
      public RpcChannelManagerFetcher(ChannelManager manager, int nodeCount, RoleType targetRole) {
          this.manager = manager;
          this.nodeCount = nodeCount;
          this.targetRole = targetRole;
          this.manager.registerRole(this.targetRole);
      }
  
      @Override
      public List<RpcChannel> fetch() {
          List<RpcChannel> channels = new ArrayList<>();
          for (int i = 0; i < nodeCount; ++i) {
              channels.add(new RpcChannel(manager.getChannel(this.targetRole, i)));
          }
          return channels;
      }
  
      @Override
      public Type getType() {
          return Type.RPC;
      }
  }
  