All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.netflix.discovery.InternalEurekaStatusModule Maven / Gradle / Ivy

There is a newer version: 2.0.4
Show newest version
package com.netflix.discovery;

import javax.inject.Inject;
import javax.inject.Singleton;

import com.google.common.base.Supplier;
import com.google.inject.AbstractModule;
import com.google.inject.Provider;
import com.google.inject.TypeLiteral;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.governator.annotations.binding.DownStatus;
import com.netflix.governator.annotations.binding.UpStatus;

/**
 * Specific bindings for eureka status checker.
 *
 * Note that this is an internal modules and ASSUMES that a binding for
 * DiscoveryClient was already set.
 *
 * Exposed bindings,
 *
 * @UpStatus   Supplier
 * @DownStatus Supplier
 * @UpStatus   Observable
 *
 * @author elandau
 *
 */
@Singleton
public class InternalEurekaStatusModule extends AbstractModule {
    @Singleton
    public static class UpStatusProvider implements Provider> {
        @Inject
        private Provider upStatus;

        @Override
        public Supplier get() {
            final EurekaUpStatusResolver resolver = upStatus.get();
            return new Supplier() {
                @Override
                public Boolean get() {
                    return resolver.getStatus().equals(InstanceInfo.InstanceStatus.UP);
                }
            };
        }
    }

    @Singleton
    public static class DownStatusProvider implements Provider> {
        @Inject
        private Provider upStatus;

        @Override
        public Supplier get() {
            final EurekaUpStatusResolver resolver = upStatus.get();
            return new Supplier() {
                @Override
                public Boolean get() {
                    return !resolver.getStatus().equals(InstanceInfo.InstanceStatus.UP);
                }
            };
        }
    }

    @Override
    protected void configure() {
        bind(new TypeLiteral>() {
        })
                .annotatedWith(UpStatus.class)
                .toProvider(UpStatusProvider.class);

        bind(new TypeLiteral>() {
        })
                .annotatedWith(DownStatus.class)
                .toProvider(DownStatusProvider.class);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy