public static ApiKeys forId(int id) { if (!hasId(id)) throw new IllegalArgumentException(String.format("Unexpected ApiKeys id `%s`, it should be between `%s` " + "and `%s` (inclusive)", id, MIN_API_KEY, MAX_API_KEY)); return ID_TO_TYPE[id]; }
public NodeApiVersions(Collection<ApiVersion> nodeApiVersions) { for (ApiVersion nodeApiVersion : nodeApiVersions) { if (ApiKeys.hasId(nodeApiVersion.apiKey)) { ApiKeys nodeApiKey = ApiKeys.forId(nodeApiVersion.apiKey); supportedVersions.put(nodeApiKey, nodeApiVersion); } else { // Newer brokers may support ApiKeys we don't know about unknownApis.add(nodeApiVersion); } } }
private String apiVersionToText(ApiVersion apiVersion) { StringBuilder bld = new StringBuilder(); ApiKeys apiKey = null; if (ApiKeys.hasId(apiVersion.apiKey)) { apiKey = ApiKeys.forId(apiVersion.apiKey); bld.append(apiKey.name).append("(").append(apiKey.id).append("): "); } else { bld.append("UNKNOWN(").append(apiVersion.apiKey).append("): "); } if (apiVersion.minVersion == apiVersion.maxVersion) { bld.append(apiVersion.minVersion); } else { bld.append(apiVersion.minVersion).append(" to ").append(apiVersion.maxVersion); } if (apiKey != null) { ApiVersion supportedVersion = supportedVersions.get(apiKey); if (apiKey.latestVersion() < supportedVersion.minVersion) { bld.append(" [unusable: node too new]"); } else if (supportedVersion.maxVersion < apiKey.oldestVersion()) { bld.append(" [unusable: node too old]"); } else { short latestUsableVersion = Utils.min(apiKey.latestVersion(), supportedVersion.maxVersion); bld.append(" [usable: ").append(latestUsableVersion).append("]"); } } return bld.toString(); }
public RequestHeader(Struct struct) { short apiKey = struct.getShort(API_KEY_FIELD_NAME); if (!ApiKeys.hasId(apiKey)) throw new InvalidRequestException("Unknown API key " + apiKey); this.apiKey = ApiKeys.forId(apiKey); apiVersion = struct.getShort(API_VERSION_FIELD_NAME); // only v0 of the controlled shutdown request is missing the clientId if (struct.hasField(CLIENT_ID_FIELD_NAME)) clientId = struct.getString(CLIENT_ID_FIELD_NAME); else clientId = ""; correlationId = struct.getInt(CORRELATION_ID_FIELD_NAME); }