Search in sources :

Example 1 with GetSlotsCommand

use of com.alipay.sofa.jraft.test.atomic.command.GetSlotsCommand in project sofa-jraft by sofastack.

the class AtomicClient method start.

public void start() throws InterruptedException, TimeoutException {
    cliOptions = new CliOptions();
    this.cliClientService.init(cliOptions);
    this.rpcClient = this.cliClientService.getRpcClient();
    if (conf != null) {
        final Set<PeerId> peers = conf.getPeerSet();
        for (final PeerId peer : peers) {
            try {
                final BooleanCommand cmd = (BooleanCommand) this.rpcClient.invokeSync(peer.getEndpoint(), new GetSlotsCommand(), cliOptions.getRpcDefaultTimeout());
                if (cmd instanceof SlotsResponseCommand) {
                    groups = ((SlotsResponseCommand) cmd).getMap();
                    break;
                } else {
                    LOG.warn("Fail to get slots from peer {}, error: {}", peer, cmd.getErrorMsg());
                }
            } catch (final Throwable t) {
                LOG.warn("Fail to get slots from peer {}, error: {}", peer, t.getMessage());
            // continue;
            }
        }
        if (groups == null || groups.isEmpty()) {
            throw new IllegalArgumentException("Can't get slots from any peers");
        } else {
            LOG.info("All groups  is {}", groups);
        }
        for (final String groupId : groups.values()) {
            RouteTable.getInstance().updateConfiguration(groupId, conf);
            refreshLeader(groupId);
            refreshConf(groupId);
        }
    }
}
Also used : GetSlotsCommand(com.alipay.sofa.jraft.test.atomic.command.GetSlotsCommand) BooleanCommand(com.alipay.sofa.jraft.test.atomic.command.BooleanCommand) SlotsResponseCommand(com.alipay.sofa.jraft.test.atomic.command.SlotsResponseCommand) CliOptions(com.alipay.sofa.jraft.option.CliOptions) PeerId(com.alipay.sofa.jraft.entity.PeerId)

Aggregations

PeerId (com.alipay.sofa.jraft.entity.PeerId)1 CliOptions (com.alipay.sofa.jraft.option.CliOptions)1 BooleanCommand (com.alipay.sofa.jraft.test.atomic.command.BooleanCommand)1 GetSlotsCommand (com.alipay.sofa.jraft.test.atomic.command.GetSlotsCommand)1 SlotsResponseCommand (com.alipay.sofa.jraft.test.atomic.command.SlotsResponseCommand)1