
io.scalecube.services.Reflect Maven / Gradle / Ivy
package io.scalecube.services;
import static java.util.Objects.requireNonNull;
import io.scalecube.services.annotations.Inject;
import io.scalecube.services.annotations.RequestType;
import io.scalecube.services.annotations.Service;
import io.scalecube.services.annotations.ServiceMethod;
import io.scalecube.services.api.ServiceMessage;
import io.scalecube.services.exceptions.BadRequestException;
import com.google.common.base.Strings;
import com.google.common.base.Throwables;
import org.reactivestreams.Publisher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
/**
* Service Injector scan and injects beans to a given Microservices instance.
*
*/
public class Reflect {
private static final Logger LOGGER = LoggerFactory.getLogger(Reflect.class);
/**
* Injector builder.
*
* @param microservices instance to be injected.
* @return Builder for injection.
*/
public static Builder builder(Microservices microservices) {
return new Builder(microservices);
}
static class Builder {
private Microservices microservices;
private Builder(Microservices ms) {
this.microservices = ms;
}
/**
* inject instances to the microservices instance. either Microservices or ServiceProxy.
*
* @return injected microservices instance.
*/
public Microservices inject() {
this.inject(this.microservices.services());
return this.microservices;
}
/**
* scan all local service instances and inject a service proxy.
*/
private void inject(Collection
© 2015 - 2025 Weber Informatics LLC | Privacy Policy