Example usage for com.google.common.reflect ClassPath.ClassInfo getClass

List of usage examples for com.google.common.reflect ClassPath.ClassInfo getClass

Introduction

In this page you can find the example usage for com.google.common.reflect ClassPath.ClassInfo getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:io.flood.rpc.registry.ResourceRegistry.java

private synchronized static Registry getRegistry() {
    final ClassLoader loader = Thread.currentThread().getContextClassLoader();

    try {/*from   w  ww.  ja v  a  2s. c o  m*/
        ImmutableSet<ClassPath.ClassInfo> classes = ClassPath.from(loader).getTopLevelClasses("io.flood");
        Optional<ClassPath.ClassInfo> registryClassInfoOp = classes.stream().filter(classInfo -> {
            if (classInfo.getClass().getAnnotation(RegistryAction.class) != null) {
                return true;
            }
            return false;
        }).sorted(((cla, clb) -> {
            RegistryAction aa = cla.getClass().getAnnotation(RegistryAction.class);
            RegistryAction ab = clb.getClass().getAnnotation(RegistryAction.class);
            return aa.order() - ab.order();
        })).findFirst();

        ClassPath.ClassInfo registryClassInfo = registryClassInfoOp.orElseThrow(Exception::new);
        RegistryAction action = registryClassInfo.getClass().getAnnotation(RegistryAction.class);

        Registry registry = (Registry) Class.forName(registryClassInfo.getName()).<Registry>newInstance();
        Configuration.configObject(registry);
        LOG.info("instance {} registry", action.value());
        return registry;

    } catch (Exception e) {
        LOG.error("");
        System.exit(-1);
    }

    return null;
}