Skip to content

Commit

Permalink
Replace orElse with orElseGet to avoid calling too many times. (apach…
Browse files Browse the repository at this point in the history
  • Loading branch information
Technoboy- authored Aug 5, 2021
1 parent 92a3ac7 commit 27855f8
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public void getDeduplicationSnapshotInterval(@Suspended final AsyncResponse asyn
preValidation(authoritative)
.thenCompose(__ -> getTopicPoliciesAsyncWithRetry(topicName))
.thenAccept(op -> {
TopicPolicies topicPolicies = op.orElse(new TopicPolicies());
TopicPolicies topicPolicies = op.orElseGet(TopicPolicies::new);
asyncResponse.resume(topicPolicies.getDeduplicationSnapshotIntervalSeconds());
})
.exceptionally(ex -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private SchemaHash(HashCode hash, SchemaType schemaType) {

public static SchemaHash of(Schema schema) {
Optional<SchemaInfo> schemaInfo = Optional.ofNullable(schema).map(Schema::getSchemaInfo);
return of(schemaInfo.map(SchemaInfo::getSchema).orElse(new byte[0]),
return of(schemaInfo.map(SchemaInfo::getSchema).orElseGet(() -> new byte[0]),
schemaInfo.map(SchemaInfo::getType).orElse(null));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public Schema<?> getSchema(String topic, Class<?> clazz, ConsumerConfig conf, bo
public Schema<?> getSchema(String topic, Class<?> clazz, Optional<SchemaType> schemaType) {
return cachedSchemas.computeIfAbsent(topic, key -> {
// If schema type was not provided, try to get it from schema registry, or fallback to default types
SchemaType type = schemaType.orElse(getSchemaTypeOrDefault(topic, clazz));
SchemaType type = schemaType.orElseGet(() -> getSchemaTypeOrDefault(topic, clazz));
return newSchemaInstance(clazz, type);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void setConf(Configuration conf) {
}

try {
BookiesRackConfiguration racks = bookieMappingCache.get(BOOKIE_INFO_ROOT_PATH).orElse(new BookiesRackConfiguration());
BookiesRackConfiguration racks = bookieMappingCache.get(BOOKIE_INFO_ROOT_PATH).orElseGet(BookiesRackConfiguration::new);
updateRacksWithHost(racks);
} catch (Exception e) {
throw new RuntimeException(e);
Expand Down Expand Up @@ -185,7 +185,7 @@ private String getRack(String bookieAddress) {
try {
// Trigger load of z-node in case it didn't exist
Optional<BookiesRackConfiguration> racks = bookieMappingCache.get(BOOKIE_INFO_ROOT_PATH);
updateRacksWithHost(racks.orElse(new BookiesRackConfiguration()));
updateRacksWithHost(racks.orElseGet(BookiesRackConfiguration::new));
if (!racks.isPresent()) {
// since different placement policy will have different default rack,
// don't be smart here and just return null
Expand Down

0 comments on commit 27855f8

Please sign in to comment.