Skip to content

Commit

Permalink
Use computeIfAbsent
Browse files Browse the repository at this point in the history
Signed-off-by: Pierangelo Di Pilato <pierangelodipilato@gmail.com>
  • Loading branch information
pierDipi committed Jan 28, 2021
1 parent 7f8e969 commit b4e5c97
Showing 1 changed file with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,30 +183,29 @@ private Future<Void> onNewIngress(final DataPlaneContract.Resource resource,
}
producerProps.setProperty(CloudEventSerializer.EVENT_FORMAT_CONFIG, JsonFormat.CONTENT_TYPE);

// Get the rc and increment it
if (!this.producerReferences.containsKey(producerProps)) {
try {
try {
// Get the rc and increment it
final ReferenceCounter<ProducerHolder<K, V>> rc = this.producerReferences.computeIfAbsent(producerProps, props -> {
final var producer = producerCreator.apply(producerProps);
this.producerReferences.put(producerProps, new ReferenceCounter<>(new ProducerHolder<>(producer)));
} catch (final Exception ex) {
return Future.failedFuture(ex);
}
}
return new ReferenceCounter<>(new ProducerHolder<>(producer));
});
rc.increment();

final ReferenceCounter<ProducerHolder<K, V>> rc = this.producerReferences.get(producerProps);
rc.increment();
final var ingressInfo = new IngressInfo<>(
rc.getValue().getProducer(),
resource.getTopics(0),
ingress.getPath(),
producerProps
);

final var ingressInfo = new IngressInfo<>(
rc.getValue().getProducer(),
resource.getTopics(0),
ingress.getPath(),
producerProps
);
this.pathMapper.put(ingress.getPath(), ingressInfo);
this.ingressInfos.put(resource.getUid(), ingressInfo);

this.pathMapper.put(ingress.getPath(), ingressInfo);
this.ingressInfos.put(resource.getUid(), ingressInfo);
return Future.succeededFuture();

return Future.succeededFuture();
} catch (final Exception ex) {
return Future.failedFuture(ex);
}
}

@Override
Expand Down

0 comments on commit b4e5c97

Please sign in to comment.