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
…e#11542) (apache#11542)

(cherry picked from commit 27855f8)
  • Loading branch information
Technoboy- authored and nicoloboschi committed Oct 29, 2021
1 parent 36132a1 commit eb9c46c
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 @@ -384,7 +384,7 @@ public void getDeduplicationSnapshotInterval(@Suspended final AsyncResponse asyn
@PathParam("topic") @Encoded String encodedTopic) {
validateTopicName(tenant, namespace, encodedTopic);
preValidation();
TopicPolicies topicPolicies = getTopicPolicies(topicName).orElse(new TopicPolicies());
TopicPolicies topicPolicies = getTopicPolicies(topicName).orElseGet(TopicPolicies::new);
if (topicPolicies.isDeduplicationSnapshotIntervalSecondsSet()) {
asyncResponse.resume(topicPolicies.getDeduplicationSnapshotIntervalSeconds());
} else {
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 @@ -75,7 +75,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 @@ -91,7 +91,7 @@ private void updateRacksWithHost(BookiesRackConfiguration racks) {
try {
BookieId bookieId = BookieId.parse(addr);
BookieAddressResolver addressResolver = getBookieAddressResolver();
if (addressResolver == null) {
if (addressResolver ==PersistentTopics.java null) {

This comment has been minimized.

Copy link
@lhotari

lhotari Nov 1, 2021

@nicoloboschi @eolivelli It looks like there was some issue in cherry-picking.

LOG.warn("Bookie address resolver not yet initialized, skipping resolution");
} else {
BookieSocketAddress bsa = addressResolver.resolve(bookieId);
Expand Down Expand Up @@ -186,7 +186,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 eb9c46c

Please sign in to comment.