in commons/src/main/java/com/epam/eco/schemacatalog/client/EcoCachedSchemaRegistryClient.java [268:304]
protected RegisterSchemaResponse registerWithResponse(
String subject,
ParsedSchema schema,
int version,
int id,
boolean normalize) throws IOException, RestClientException {
Validate.notBlank(subject, "Subject is blank");
Validate.notNull(schema, "Schema is null");
SubjectCache subjectCache = getSubjectCache(subject);
subjectCache.lock();
try {
RegisterSchemaResponse cachedResponse = subjectCache.getRegisterSchemaBySchema(schema);
if (cachedResponse != null) {
if (id >= 0 && id != cachedResponse.getId()) {
throw new IllegalStateException(
"Schema already registered with id " + cachedResponse.getId() + " instead of input id " + id);
}
return cachedResponse;
}
RegisterSchemaResponse retrievedResponse =
id >= 0 ?
registerAndGetResponse(subject, schema, version, id, normalize) :
registerAndGetResponse(subject, schema, normalize);
if (id < 0) {
//newly registered schema
idToSchemaCache.put(retrievedResponse.getId(), schema);
}
subjectCache.addSchemaWithRegisterResponse(schema, retrievedResponse);
return retrievedResponse;
} finally {
subjectCache.unlock();
}
}