@Override public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) { short versionId = version(); switch (versionId) { case 0: case 1: return new JoinGroupResponse( Errors.forException(e), JoinGroupResponse.UNKNOWN_GENERATION_ID, JoinGroupResponse.UNKNOWN_PROTOCOL, JoinGroupResponse.UNKNOWN_MEMBER_ID, // memberId JoinGroupResponse.UNKNOWN_MEMBER_ID, // leaderId Collections.emptyMap()); case 2: case 3: case 4: return new JoinGroupResponse( throttleTimeMs, Errors.forException(e), JoinGroupResponse.UNKNOWN_GENERATION_ID, JoinGroupResponse.UNKNOWN_PROTOCOL, JoinGroupResponse.UNKNOWN_MEMBER_ID, // memberId JoinGroupResponse.UNKNOWN_MEMBER_ID, // leaderId Collections.emptyMap()); default: throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d", versionId, this.getClass().getSimpleName(), ApiKeys.JOIN_GROUP.latestVersion())); } }
@Override protected Struct toStruct() { short version = version(); Struct struct = new Struct(ApiKeys.JOIN_GROUP.requestSchema(version)); struct.set(GROUP_ID, groupId); struct.set(SESSION_TIMEOUT_KEY_NAME, sessionTimeout); if (version >= 1) { struct.set(REBALANCE_TIMEOUT_KEY_NAME, rebalanceTimeout); } struct.set(MEMBER_ID, memberId); struct.set(PROTOCOL_TYPE_KEY_NAME, protocolType); List<Struct> groupProtocolsList = new ArrayList<>(groupProtocols.size()); for (ProtocolMetadata protocol : groupProtocols) { Struct protocolStruct = struct.instance(GROUP_PROTOCOLS_KEY_NAME); protocolStruct.set(PROTOCOL_NAME_KEY_NAME, protocol.name); protocolStruct.set(PROTOCOL_METADATA_KEY_NAME, protocol.metadata); groupProtocolsList.add(protocolStruct); } struct.set(GROUP_PROTOCOLS_KEY_NAME, groupProtocolsList.toArray()); return struct; } }