-
Notifications
You must be signed in to change notification settings - Fork 720
Create a ServiceRegistry interface. #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
aa8318e
2996c2f
60896a3
8d10450
2c95bd2
802dd8f
81993a4
0558fc6
20eaeae
dd39bfb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Created AbstractAutoServiceRegistration with new methods and reference to ServiceRegistry. It extends AbstractDiscoveryLifecycle.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,16 +33,14 @@ | |
| import org.springframework.core.env.Environment; | ||
|
|
||
| /** | ||
| * Lifecycle methods that may be useful and common to {@link ServiceRegistry} implementations. | ||
| * Lifecycle methods that may be useful and common to various DiscoveryClient implementations. | ||
| * | ||
| * TODO: document the lifecycle | ||
| * | ||
| * @param <R> registration type passed to the {@link ServiceRegistry}. | ||
| * @deprecated use {@link org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration} instead. This class will be removed in the next release train. | ||
| * | ||
| * @author Spencer Gibb | ||
| */ | ||
| //TODO: rename to AbstractServiceRegistryLifecycle or AbstractAutoServiceRegistration? | ||
| public abstract class AbstractDiscoveryLifecycle<R> implements DiscoveryLifecycle, | ||
| @Deprecated | ||
| public abstract class AbstractDiscoveryLifecycle implements DiscoveryLifecycle, | ||
| ApplicationContextAware, ApplicationListener<EmbeddedServletContainerInitializedEvent> { | ||
|
|
||
| private static final Log logger = LogFactory.getLog(AbstractDiscoveryLifecycle.class); | ||
|
|
@@ -59,12 +57,6 @@ public abstract class AbstractDiscoveryLifecycle<R> implements DiscoveryLifecycl | |
|
|
||
| private AtomicInteger port = new AtomicInteger(0); | ||
|
|
||
| private ServiceRegistry<R> serviceRegistry; | ||
|
|
||
| protected AbstractDiscoveryLifecycle(ServiceRegistry<R> serviceRegistry) { | ||
| this.serviceRegistry = serviceRegistry; | ||
| } | ||
|
|
||
| protected ApplicationContext getContext() { | ||
| return context; | ||
| } | ||
|
|
@@ -140,40 +132,27 @@ protected boolean shouldRegisterManagement() { | |
| */ | ||
| protected abstract Object getConfiguration(); | ||
|
|
||
| protected abstract R getRegistration(); | ||
|
|
||
| protected abstract R getManagementRegistration(); | ||
|
|
||
| protected ServiceRegistry<R> getServiceRegistry() { | ||
| return this.serviceRegistry; | ||
| } | ||
|
|
||
| /** | ||
| * Register the local service with the {@link ServiceRegistry} | ||
| * Register the local service with the DiscoveryClient | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this doc need to be changed now?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, |
||
| */ | ||
| protected void register() { | ||
| this.serviceRegistry.register(getRegistration()); | ||
| } | ||
| protected abstract void register(); | ||
|
|
||
| /** | ||
| * Register the local management service with the {@link ServiceRegistry} | ||
| * Register the local management service with the DiscoveryClient | ||
| */ | ||
| protected void registerManagement() { | ||
| this.serviceRegistry.register(getManagementRegistration()); | ||
| } | ||
|
|
||
| /** | ||
| * De-register the local service with the {@link ServiceRegistry} | ||
| * De-register the local service with the DiscoveryClient | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
| */ | ||
| protected void deregister() { | ||
| this.serviceRegistry.deregister(getRegistration()); | ||
| } | ||
| protected abstract void deregister(); | ||
|
|
||
| /** | ||
| * De-register the local management service with the {@link ServiceRegistry} | ||
| * De-register the local management service with the DiscoveryClient | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
| */ | ||
| protected void deregisterManagement() { | ||
| this.serviceRegistry.deregister(getManagementRegistration()); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -231,6 +210,10 @@ public boolean isRunning() { | |
| return this.running.get(); | ||
| } | ||
|
|
||
| protected AtomicBoolean getRunning() { | ||
| return running; | ||
| } | ||
|
|
||
| @Override | ||
| public int getOrder() { | ||
| return this.order; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package org.springframework.cloud.client.serviceregistry; | ||
|
|
||
| import org.springframework.cloud.client.discovery.AbstractDiscoveryLifecycle; | ||
|
|
||
| /** | ||
| * Lifecycle methods that may be useful and common to {@link ServiceRegistry} implementations. | ||
| * | ||
| * TODO: document the lifecycle | ||
| * | ||
| * @param <R> registration type passed to the {@link ServiceRegistry}. | ||
| * | ||
| * @author Spencer Gibb | ||
| */ | ||
| @SuppressWarnings("deprecation") | ||
| public abstract class AbstractAutoServiceRegistration<R> extends AbstractDiscoveryLifecycle { | ||
|
|
||
| private ServiceRegistry<R> serviceRegistry; | ||
|
|
||
| protected AbstractAutoServiceRegistration(ServiceRegistry<R> serviceRegistry) { | ||
| this.serviceRegistry = serviceRegistry; | ||
| } | ||
|
|
||
| protected ServiceRegistry<R> getServiceRegistry() { | ||
| return this.serviceRegistry; | ||
| } | ||
|
|
||
| protected abstract R getRegistration(); | ||
|
|
||
| protected abstract R getManagementRegistration(); | ||
|
|
||
| /** | ||
| * Register the local service with the {@link ServiceRegistry} | ||
| */ | ||
| @Override | ||
| protected void register() { | ||
| this.serviceRegistry.register(getRegistration()); | ||
| } | ||
|
|
||
| /** | ||
| * Register the local management service with the {@link ServiceRegistry} | ||
| */ | ||
| @Override | ||
| protected void registerManagement() { | ||
| this.serviceRegistry.register(getManagementRegistration()); | ||
| } | ||
|
|
||
| /** | ||
| * De-register the local service with the {@link ServiceRegistry} | ||
| */ | ||
| @Override | ||
| protected void deregister() { | ||
| this.serviceRegistry.deregister(getRegistration()); | ||
| } | ||
|
|
||
| /** | ||
| * De-register the local management service with the {@link ServiceRegistry} | ||
| */ | ||
| @Override | ||
| protected void deregisterManagement() { | ||
| this.serviceRegistry.deregister(getManagementRegistration()); | ||
| } | ||
|
|
||
| @Override | ||
| public void stop() { | ||
| if (this.getRunning().compareAndSet(true, false) && isEnabled()) { | ||
| deregister(); | ||
| if (shouldRegisterManagement()) { | ||
| deregisterManagement(); | ||
| } | ||
| this.serviceRegistry.close(); | ||
| } | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it still various? or is registration (the
Rtype) intended to work only with one sort of client now? I'd probably doc the type param regardless of whether it stays a marker or not.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rwill be specific to the impl (though it won't extendRegistration).