Skip to content

Commit

Permalink
Merge pull request #543 from harti2006/check-class-presence
Browse files Browse the repository at this point in the history
Check if Tracer is on classpath
  • Loading branch information
whiskeysierra authored Jan 14, 2019
2 parents c509487 + 0e22f59 commit 24c8502
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -394,15 +394,20 @@ private Optional<String> getHost(final Client client) {
}

private BeanMetadataElement trace(final String executor) {
if (registry.isRegistered("tracer")) {
return genericBeanDefinition(TracingExecutors.class)
.setFactoryMethod("preserve")
.addConstructorArgReference(executor)
.addConstructorArgReference("tracer")
.getBeanDefinition();
} else {
return ref(executor);
}
final Optional<BeanMetadataElement> result = ifPresent("org.zalando.tracer.concurrent.TracingExecutors",
() -> {
if (registry.isRegistered("tracer")) {
return genericBeanDefinition(TracingExecutors.class)
.setFactoryMethod("preserve")
.addConstructorArgReference(executor)
.addConstructorArgReference("tracer")
.getBeanDefinition();
} else {
return null;
}
});

return result.orElseGet(() -> ref(executor));
}

private String registerHttpClient(final String id, final Client client) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.zalando.riptide.spring;

import java.util.Optional;
import java.util.function.Supplier;

import static org.springframework.util.ClassUtils.getDefaultClassLoader;
import static org.springframework.util.ClassUtils.isPresent;

Expand All @@ -10,8 +13,17 @@ private Dependencies() {
}

static void ifPresent(final String name, final Runnable runnable) {
if (isPresent(name, getDefaultClassLoader())) {
ifPresent(name, () -> {
runnable.run();
return null;
});
}

static <T> Optional<T> ifPresent(final String name, final Supplier<T> supplier) {
if (isPresent(name, getDefaultClassLoader())) {
return Optional.ofNullable(supplier.get());
} else {
return Optional.empty();
}
}

Expand Down

0 comments on commit 24c8502

Please sign in to comment.