Search in sources :

Example 1 with SlotsResponseCommand

use of com.alipay.sofa.jraft.test.atomic.command.SlotsResponseCommand 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)

Example 2 with SlotsResponseCommand

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

the class GetSlotsCommandProcessor method handleRequest.

@Override
public void handleRequest(final RpcContext rpcCtx, final GetSlotsCommand request) {
    final SlotsResponseCommand response = new SlotsResponseCommand();
    response.setMap(this.server.getGroups());
    rpcCtx.sendResponse(response);
}
Also used : SlotsResponseCommand(com.alipay.sofa.jraft.test.atomic.command.SlotsResponseCommand)

Aggregations

SlotsResponseCommand (com.alipay.sofa.jraft.test.atomic.command.SlotsResponseCommand)2 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