package com.netflix.discovery; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Set; import javax.inject.Provider; import com.google.inject.Inject; import com.netflix.appinfo.HealthCheckCallback; import com.netflix.appinfo.HealthCheckHandler; import com.netflix.discovery.shared.transport.TransportClientFactory; import com.netflix.discovery.shared.transport.jersey.EurekaJerseyClient; import com.netflix.discovery.shared.transport.jersey.TransportClientFactories; import com.netflix.eventbus.spi.EventBus; /** * <T> The type for client supplied filters (supports jersey1 and jersey2) */ public abstract class AbstractDiscoveryClientOptionalArgs<T> { Provider<HealthCheckCallback> healthCheckCallbackProvider; Provider<HealthCheckHandler> healthCheckHandlerProvider; Collection<T> additionalFilters; EurekaJerseyClient eurekaJerseyClient; TransportClientFactory transportClientFactory; TransportClientFactories transportClientFactories; private Set<EurekaEventListener> eventListeners; @Inject(optional = true) public void setEventListeners(Set<EurekaEventListener> listeners) { if (eventListeners == null) { eventListeners = new HashSet<>(); } eventListeners.addAll(listeners); } @Inject(optional = true) public void setEventBus(final EventBus eventBus) { if (eventListeners == null) { eventListeners = new HashSet<>(); } eventListeners.add(new EurekaEventListener() { @Override public void onEvent(EurekaEvent event) { eventBus.publish(event); } }); } @Inject(optional = true) public void setHealthCheckCallbackProvider(Provider<HealthCheckCallback> healthCheckCallbackProvider) { this.healthCheckCallbackProvider = healthCheckCallbackProvider; } @Inject(optional = true) public void setHealthCheckHandlerProvider(Provider<HealthCheckHandler> healthCheckHandlerProvider) { this.healthCheckHandlerProvider = healthCheckHandlerProvider; } @Inject(optional = true) public void setAdditionalFilters(Collection<T> additionalFilters) { this.additionalFilters = additionalFilters; } @Inject(optional = true) public void setEurekaJerseyClient(EurekaJerseyClient eurekaJerseyClient) { this.eurekaJerseyClient = eurekaJerseyClient; } Set<EurekaEventListener> getEventListeners() { return eventListeners == null ? Collections.<EurekaEventListener>emptySet() : eventListeners; } public TransportClientFactories getTransportClientFactories() { return transportClientFactories; } @Inject(optional = true) public void setTransportClientFactories(TransportClientFactories transportClientFactories) { this.transportClientFactories = transportClientFactories; } }