mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
refactor method and class name
This commit is contained in:
parent
6c0edee13e
commit
eea48c73cc
@ -24,8 +24,9 @@ import java.util.Set;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import com.alibaba.cloud.dubbo.autoconfigure.condition.MissingSpringCloudRegistryConfigPropertyCondition;
|
import com.alibaba.cloud.dubbo.autoconfigure.condition.MissingSpringCloudRegistryConfigPropertyCondition;
|
||||||
import com.alibaba.cloud.dubbo.metadata.DubboBootstrapCommandLineRunner;
|
import com.alibaba.cloud.dubbo.bootstrap.DubboBootstrapStartCommandLineRunner;
|
||||||
import com.alibaba.cloud.dubbo.metadata.event.DubboBootstrapStartedEvent;
|
import com.alibaba.cloud.dubbo.bootstrap.DubboBootstrapWrapper;
|
||||||
|
import com.alibaba.cloud.dubbo.bootstrap.event.DubboBootstrapStartedEvent;
|
||||||
import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository;
|
import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository;
|
||||||
import com.alibaba.cloud.dubbo.registry.DubboServiceRegistrationEventPublishingAspect;
|
import com.alibaba.cloud.dubbo.registry.DubboServiceRegistrationEventPublishingAspect;
|
||||||
import com.alibaba.cloud.dubbo.registry.event.ServiceInstancePreDeregisteredEvent;
|
import com.alibaba.cloud.dubbo.registry.event.ServiceInstancePreDeregisteredEvent;
|
||||||
@ -60,7 +61,6 @@ import org.springframework.context.annotation.Conditional;
|
|||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.context.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
import org.springframework.core.annotation.Order;
|
|
||||||
|
|
||||||
import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.CONSUL_AUTO_SERVICE_AUTO_CONFIGURATION_CLASS_NAME;
|
import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.CONSUL_AUTO_SERVICE_AUTO_CONFIGURATION_CLASS_NAME;
|
||||||
import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.EUREKA_CLIENT_AUTO_CONFIGURATION_CLASS_NAME;
|
import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.EUREKA_CLIENT_AUTO_CONFIGURATION_CLASS_NAME;
|
||||||
@ -72,10 +72,11 @@ import static org.springframework.util.ObjectUtils.isEmpty;
|
|||||||
* Dubbo Service Registration Auto-{@link Configuration}.
|
* Dubbo Service Registration Auto-{@link Configuration}.
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||||
|
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
|
||||||
*/
|
*/
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@Import({ DubboServiceRegistrationEventPublishingAspect.class,
|
@Import({ DubboServiceRegistrationEventPublishingAspect.class,
|
||||||
DubboBootstrapCommandLineRunner.class })
|
DubboBootstrapStartCommandLineRunner.class })
|
||||||
@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled",
|
@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled",
|
||||||
matchIfMissing = true)
|
matchIfMissing = true)
|
||||||
@AutoConfigureAfter(name = { EUREKA_CLIENT_AUTO_CONFIGURATION_CLASS_NAME,
|
@AutoConfigureAfter(name = { EUREKA_CLIENT_AUTO_CONFIGURATION_CLASS_NAME,
|
||||||
@ -118,10 +119,9 @@ public class DubboServiceRegistrationAutoConfiguration {
|
|||||||
|
|
||||||
private Map<ServiceRegistry<Registration>, Set<Registration>> registrations = new ConcurrentHashMap<>();
|
private Map<ServiceRegistry<Registration>, Set<Registration>> registrations = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Order
|
|
||||||
@EventListener(DubboBootstrapStartedEvent.class)
|
@EventListener(DubboBootstrapStartedEvent.class)
|
||||||
public void attachDubboMetadataAndRegistAgain(DubboBootstrapStartedEvent event) {
|
public void onDubboBootstrapStarted(DubboBootstrapStartedEvent event) {
|
||||||
if (!event.getSource().isReady() || !event.getSource().isStarted()) {
|
if (!event.getSource().isReady()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
registrations.forEach(
|
registrations.forEach(
|
||||||
@ -181,9 +181,9 @@ public class DubboServiceRegistrationAutoConfiguration {
|
|||||||
private ObjectProvider<Collection<ServiceBean>> serviceBeans;
|
private ObjectProvider<Collection<ServiceBean>> serviceBeans;
|
||||||
|
|
||||||
@EventListener(DubboBootstrapStartedEvent.class)
|
@EventListener(DubboBootstrapStartedEvent.class)
|
||||||
public void onServiceInstancePreRegistered(DubboBootstrapStartedEvent event) {
|
public void onDubboBootstrapStarted(DubboBootstrapStartedEvent event) {
|
||||||
DubboBootstrap bootstrap = event.getSource();
|
DubboBootstrapWrapper wrapper = event.getSource();
|
||||||
if (!bootstrap.isReady() || !bootstrap.isStarted()) {
|
if (!wrapper.isReady()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
registrations.forEach(
|
registrations.forEach(
|
||||||
@ -263,7 +263,7 @@ public class DubboServiceRegistrationAutoConfiguration {
|
|||||||
@EventListener(DubboBootstrapStartedEvent.class)
|
@EventListener(DubboBootstrapStartedEvent.class)
|
||||||
public void attachURLsIntoMetadataBeforeReRegist(
|
public void attachURLsIntoMetadataBeforeReRegist(
|
||||||
DubboBootstrapStartedEvent event) {
|
DubboBootstrapStartedEvent event) {
|
||||||
if (!event.getSource().isReady() || !event.getSource().isStarted()) {
|
if (!event.getSource().isReady()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
registrations.entrySet().removeIf(entry -> {
|
registrations.entrySet().removeIf(entry -> {
|
||||||
|
@ -14,10 +14,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.alibaba.cloud.dubbo.metadata;
|
package com.alibaba.cloud.dubbo.bootstrap;
|
||||||
|
|
||||||
import com.alibaba.cloud.dubbo.metadata.event.DubboBootstrapStartedEvent;
|
import com.alibaba.cloud.dubbo.bootstrap.event.DubboBootstrapStartedEvent;
|
||||||
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
|
|
||||||
|
|
||||||
import org.springframework.boot.CommandLineRunner;
|
import org.springframework.boot.CommandLineRunner;
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
@ -25,13 +24,13 @@ import org.springframework.context.ApplicationEventPublisherAware;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see com.alibaba.cloud.dubbo.metadata.event.DubboBootstrapPreStartEvent
|
* publish Dubbo microsystem startup finish event.
|
||||||
* @see com.alibaba.cloud.dubbo.metadata.event.DubboBootstrapStartedEvent
|
*
|
||||||
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
|
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class DubboBootstrapCommandLineRunner
|
public class DubboBootstrapStartCommandLineRunner
|
||||||
implements CommandLineRunner, ApplicationEventPublisherAware {
|
implements CommandLineRunner, ApplicationEventPublisherAware {
|
||||||
|
|
||||||
private ApplicationEventPublisher applicationEventPublisher;
|
private ApplicationEventPublisher applicationEventPublisher;
|
||||||
@ -45,7 +44,7 @@ public class DubboBootstrapCommandLineRunner
|
|||||||
@Override
|
@Override
|
||||||
public void run(String... args) {
|
public void run(String... args) {
|
||||||
applicationEventPublisher.publishEvent(
|
applicationEventPublisher.publishEvent(
|
||||||
new DubboBootstrapStartedEvent(DubboBootstrap.getInstance()));
|
new DubboBootstrapStartedEvent(DubboBootstrapWrapper.getInstance()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -14,22 +14,34 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.alibaba.cloud.dubbo.metadata.event;
|
package com.alibaba.cloud.dubbo.bootstrap;
|
||||||
|
|
||||||
import org.springframework.context.ApplicationEvent;
|
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Wrapper DubboBootstrap operation.
|
||||||
|
*
|
||||||
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
|
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
|
||||||
*/
|
*/
|
||||||
public class DubboBootstrapPreStartEvent extends ApplicationEvent {
|
public final class DubboBootstrapWrapper {
|
||||||
|
|
||||||
/**
|
private DubboBootstrapWrapper() {
|
||||||
* Create a new {@code ApplicationEvent}.
|
}
|
||||||
* @param source the object on which the event initially occurred or with which the
|
|
||||||
* event is associated (never {@code null})
|
private static final DubboBootstrapWrapper INSTANCE = new DubboBootstrapWrapper();
|
||||||
*/
|
|
||||||
public DubboBootstrapPreStartEvent(Object source) {
|
public static DubboBootstrapWrapper getInstance() {
|
||||||
super(source);
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isReady() {
|
||||||
|
return DubboBootstrap.getInstance().isStarted()
|
||||||
|
&& DubboBootstrap.getInstance().isReady()
|
||||||
|
&& DubboBootstrap.getInstance().isInitialized();
|
||||||
|
}
|
||||||
|
|
||||||
|
public DubboBootstrap getDubboBootstrap() {
|
||||||
|
return DubboBootstrap.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -14,29 +14,31 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.alibaba.cloud.dubbo.metadata.event;
|
package com.alibaba.cloud.dubbo.bootstrap.event;
|
||||||
|
|
||||||
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
|
import com.alibaba.cloud.dubbo.bootstrap.DubboBootstrapWrapper;
|
||||||
|
|
||||||
import org.springframework.context.ApplicationEvent;
|
import org.springframework.context.ApplicationEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Dubbo microsytem start finish event, every thing is ready.
|
||||||
|
*
|
||||||
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
|
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
|
||||||
*/
|
*/
|
||||||
public class DubboBootstrapStartedEvent extends ApplicationEvent {
|
public class DubboBootstrapStartedEvent extends ApplicationEvent {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@code ApplicationEvent}.
|
* Create a new {@code DubboBootstrapStartedEvent}.
|
||||||
* @param source the object on which the event initially occurred or with which the
|
* @param source the object on which the event initially occurred or with which the
|
||||||
* event is associated (never {@code null})
|
* event is associated (never {@code null})
|
||||||
*/
|
*/
|
||||||
public DubboBootstrapStartedEvent(Object source) {
|
public DubboBootstrapStartedEvent(DubboBootstrapWrapper source) {
|
||||||
super(source);
|
super(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DubboBootstrap getSource() {
|
public DubboBootstrapWrapper getSource() {
|
||||||
return (DubboBootstrap) super.getSource();
|
return (DubboBootstrapWrapper) super.getSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user