Commit 6435b73f by Spencer Gibb

remove EurekaHeartbeatEvent

parent 81bc8331
...@@ -20,7 +20,7 @@ import lombok.extern.apachecommons.CommonsLog; ...@@ -20,7 +20,7 @@ import lombok.extern.apachecommons.CommonsLog;
import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation; import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.framework.ProxyFactory;
import org.springframework.cloud.client.discovery.DiscoveryHeartbeatEvent; import org.springframework.cloud.client.discovery.event.HeartbeatEvent;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import com.netflix.appinfo.DataCenterInfo; import com.netflix.appinfo.DataCenterInfo;
...@@ -160,7 +160,7 @@ public class DataCenterAwareMarshallingStrategy implements MarshallingStrategy { ...@@ -160,7 +160,7 @@ public class DataCenterAwareMarshallingStrategy implements MarshallingStrategy {
if ("setVersion".equals(invocation.getMethod().getName())) { if ("setVersion".equals(invocation.getMethod().getName())) {
Long version = Long.class.cast(invocation.getArguments()[0]); Long version = Long.class.cast(invocation.getArguments()[0]);
log.debug("Applications.setVersion() called with version: " + version); log.debug("Applications.setVersion() called with version: " + version);
this.context.publishEvent(new DiscoveryHeartbeatEvent(invocation this.context.publishEvent(new HeartbeatEvent(invocation
.getThis(), version)); .getThis(), version));
} }
return ret; return ret;
......
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
package org.springframework.cloud.netflix.eureka; package org.springframework.cloud.netflix.eureka;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -25,8 +28,9 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean ...@@ -25,8 +28,9 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.builder.ParentContextApplicationContextInitializer; import org.springframework.boot.builder.ParentContextApplicationContextInitializer;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.discovery.DiscoveryHeartbeatEvent; import org.springframework.cloud.client.discovery.event.HeartbeatEvent;
import org.springframework.cloud.client.discovery.NoopDiscoveryClientAutoConfiguration; import org.springframework.cloud.client.discovery.event.ParentHeartbeatEvent;
import org.springframework.cloud.client.discovery.noop.NoopDiscoveryClientAutoConfiguration;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
...@@ -38,9 +42,6 @@ import com.netflix.discovery.EurekaClientConfig; ...@@ -38,9 +42,6 @@ import com.netflix.discovery.EurekaClientConfig;
import com.netflix.discovery.converters.JsonXStream; import com.netflix.discovery.converters.JsonXStream;
import com.netflix.discovery.converters.XmlXStream; import com.netflix.discovery.converters.XmlXStream;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/** /**
* @author Dave Syer * @author Dave Syer
*/ */
...@@ -78,9 +79,9 @@ public class EurekaClientAutoConfiguration implements ApplicationListener<Parent ...@@ -78,9 +79,9 @@ public class EurekaClientAutoConfiguration implements ApplicationListener<Parent
/** /**
* propagate DiscoveryHeartbeatEvent from parent to child. * propagate HeartbeatEvent from parent to child. Do it via a
* Do it via a EurekaHeartbeatEvent since events get published to the * ParentHeartbeatEvent since events get published to the parent context,
* parent context, otherwise results in a stack overflow * otherwise results in a stack overflow
* @param event * @param event
*/ */
@Override @Override
...@@ -93,10 +94,11 @@ public class EurekaClientAutoConfiguration implements ApplicationListener<Parent ...@@ -93,10 +94,11 @@ public class EurekaClientAutoConfiguration implements ApplicationListener<Parent
if (listenerAdded.putIfAbsent(childId, childId) == null) { if (listenerAdded.putIfAbsent(childId, childId) == null) {
@SuppressWarnings("resource") @SuppressWarnings("resource")
ConfigurableApplicationContext ctx = (ConfigurableApplicationContext) parent; ConfigurableApplicationContext ctx = (ConfigurableApplicationContext) parent;
ctx.addApplicationListener(new ApplicationListener<DiscoveryHeartbeatEvent>() { ctx.addApplicationListener(new ApplicationListener<HeartbeatEvent>() {
@Override @Override
public void onApplicationEvent(DiscoveryHeartbeatEvent dhe) { public void onApplicationEvent(HeartbeatEvent dhe) {
context.publishEvent(new EurekaHeartbeatEvent(dhe)); context.publishEvent(new ParentHeartbeatEvent(dhe
.getSource(), dhe.getValue()));
} }
}); });
} }
......
...@@ -33,7 +33,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; ...@@ -33,7 +33,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent; import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.InstanceRegisteredEvent; import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.context.SmartLifecycle; import org.springframework.context.SmartLifecycle;
......
...@@ -25,7 +25,7 @@ import org.springframework.boot.actuate.health.Health.Builder; ...@@ -25,7 +25,7 @@ import org.springframework.boot.actuate.health.Health.Builder;
import org.springframework.boot.actuate.health.Status; import org.springframework.boot.actuate.health.Status;
import org.springframework.boot.actuate.metrics.Metric; import org.springframework.boot.actuate.metrics.Metric;
import org.springframework.boot.actuate.metrics.reader.MetricReader; import org.springframework.boot.actuate.metrics.reader.MetricReader;
import org.springframework.cloud.client.discovery.DiscoveryHealthIndicator; import org.springframework.cloud.client.discovery.health.DiscoveryHealthIndicator;
import com.netflix.appinfo.EurekaInstanceConfig; import com.netflix.appinfo.EurekaInstanceConfig;
import com.netflix.discovery.DiscoveryClient; import com.netflix.discovery.DiscoveryClient;
......
package org.springframework.cloud.netflix.eureka;
import org.springframework.cloud.client.discovery.DiscoveryHeartbeatEvent;
import org.springframework.context.ApplicationEvent;
/**
* Specifically used when eureka is in the parent bootstrap context to relay the DiscoveryHeartbeatEvent to the child. Avoids stack overflow
* @author Spencer Gibb
*
* TODO: create a ParentDiscoveryHeartbeatEvent in s-c-commons rather than eureka, so eureka doesn't leak into zuul (so zuul can be used with consul for example)
*/
@SuppressWarnings("serial")
public class EurekaHeartbeatEvent extends ApplicationEvent {
private final Object value;
public EurekaHeartbeatEvent(DiscoveryHeartbeatEvent e) {
super(e.getSource());
value = e.getValue();
}
public Object getValue() {
return value;
}
}
...@@ -27,8 +27,8 @@ import org.springframework.context.annotation.Import; ...@@ -27,8 +27,8 @@ import org.springframework.context.annotation.Import;
/** /**
* Sets up a Zuul server endpoint and installs some reverse proxy filters in it, so it can * Sets up a Zuul server endpoint and installs some reverse proxy filters in it, so it can
* forward requests to backend servers. The backends can be registered manually through * * forward requests to backend servers. The backends can be registered manually through
* configuration or via Eureka. * * configuration or via DiscoveryClient.
* *
* @see EnableZuulServer for how to get a Zuul server without any proxying * @see EnableZuulServer for how to get a Zuul server without any proxying
* *
...@@ -41,5 +41,4 @@ import org.springframework.context.annotation.Import; ...@@ -41,5 +41,4 @@ import org.springframework.context.annotation.Import;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Import(ZuulProxyConfiguration.class) @Import(ZuulProxyConfiguration.class)
public @interface EnableZuulProxy { public @interface EnableZuulProxy {
} }
...@@ -23,10 +23,10 @@ import org.springframework.boot.actuate.endpoint.Endpoint; ...@@ -23,10 +23,10 @@ import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.boot.actuate.trace.TraceRepository; import org.springframework.boot.actuate.trace.TraceRepository;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.DiscoveryHeartbeatEvent; import org.springframework.cloud.client.discovery.event.HeartbeatEvent;
import org.springframework.cloud.client.discovery.InstanceRegisteredEvent; import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent;
import org.springframework.cloud.client.discovery.event.ParentHeartbeatEvent;
import org.springframework.cloud.context.scope.refresh.RefreshScopeRefreshedEvent; import org.springframework.cloud.context.scope.refresh.RefreshScopeRefreshedEvent;
import org.springframework.cloud.netflix.eureka.EurekaHeartbeatEvent;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory; import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.cloud.netflix.zuul.filters.ProxyRequestHelper; import org.springframework.cloud.netflix.zuul.filters.ProxyRequestHelper;
import org.springframework.cloud.netflix.zuul.filters.ProxyRouteLocator; import org.springframework.cloud.netflix.zuul.filters.ProxyRouteLocator;
...@@ -130,12 +130,12 @@ public class ZuulProxyConfiguration extends ZuulConfiguration { ...@@ -130,12 +130,12 @@ public class ZuulProxyConfiguration extends ZuulConfiguration {
|| event instanceof RoutesRefreshedEvent) { || event instanceof RoutesRefreshedEvent) {
reset(); reset();
} }
else if (event instanceof EurekaHeartbeatEvent) { else if (event instanceof ParentHeartbeatEvent) {
EurekaHeartbeatEvent e = (EurekaHeartbeatEvent) event; ParentHeartbeatEvent e = (ParentHeartbeatEvent) event;
resetIfNeeded(e.getValue()); resetIfNeeded(e.getValue());
} }
else if (event instanceof DiscoveryHeartbeatEvent) { else if (event instanceof HeartbeatEvent) {
DiscoveryHeartbeatEvent e = (DiscoveryHeartbeatEvent) event; HeartbeatEvent e = (HeartbeatEvent) event;
resetIfNeeded(e.getValue()); resetIfNeeded(e.getValue());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment