refactor method and class name

pull/1907/head
theonefx 4 years ago
parent 6c0edee13e
commit eea48c73cc

@ -24,8 +24,9 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import com.alibaba.cloud.dubbo.autoconfigure.condition.MissingSpringCloudRegistryConfigPropertyCondition;
import com.alibaba.cloud.dubbo.metadata.DubboBootstrapCommandLineRunner;
import com.alibaba.cloud.dubbo.metadata.event.DubboBootstrapStartedEvent;
import com.alibaba.cloud.dubbo.bootstrap.DubboBootstrapStartCommandLineRunner;
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.registry.DubboServiceRegistrationEventPublishingAspect;
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.Import;
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.EUREKA_CLIENT_AUTO_CONFIGURATION_CLASS_NAME;
@ -72,10 +72,11 @@ import static org.springframework.util.ObjectUtils.isEmpty;
* Dubbo Service Registration Auto-{@link Configuration}.
*
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
*/
@Configuration(proxyBeanMethods = false)
@Import({ DubboServiceRegistrationEventPublishingAspect.class,
DubboBootstrapCommandLineRunner.class })
DubboBootstrapStartCommandLineRunner.class })
@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled",
matchIfMissing = true)
@AutoConfigureAfter(name = { EUREKA_CLIENT_AUTO_CONFIGURATION_CLASS_NAME,
@ -118,10 +119,9 @@ public class DubboServiceRegistrationAutoConfiguration {
private Map<ServiceRegistry<Registration>, Set<Registration>> registrations = new ConcurrentHashMap<>();
@Order
@EventListener(DubboBootstrapStartedEvent.class)
public void attachDubboMetadataAndRegistAgain(DubboBootstrapStartedEvent event) {
if (!event.getSource().isReady() || !event.getSource().isStarted()) {
public void onDubboBootstrapStarted(DubboBootstrapStartedEvent event) {
if (!event.getSource().isReady()) {
return;
}
registrations.forEach(
@ -181,9 +181,9 @@ public class DubboServiceRegistrationAutoConfiguration {
private ObjectProvider<Collection<ServiceBean>> serviceBeans;
@EventListener(DubboBootstrapStartedEvent.class)
public void onServiceInstancePreRegistered(DubboBootstrapStartedEvent event) {
DubboBootstrap bootstrap = event.getSource();
if (!bootstrap.isReady() || !bootstrap.isStarted()) {
public void onDubboBootstrapStarted(DubboBootstrapStartedEvent event) {
DubboBootstrapWrapper wrapper = event.getSource();
if (!wrapper.isReady()) {
return;
}
registrations.forEach(
@ -263,7 +263,7 @@ public class DubboServiceRegistrationAutoConfiguration {
@EventListener(DubboBootstrapStartedEvent.class)
public void attachURLsIntoMetadataBeforeReRegist(
DubboBootstrapStartedEvent event) {
if (!event.getSource().isReady() || !event.getSource().isStarted()) {
if (!event.getSource().isReady()) {
return;
}
registrations.entrySet().removeIf(entry -> {

@ -14,10 +14,9 @@
* 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 org.apache.dubbo.config.bootstrap.DubboBootstrap;
import com.alibaba.cloud.dubbo.bootstrap.event.DubboBootstrapStartedEvent;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ApplicationEventPublisher;
@ -25,13 +24,13 @@ import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;
/**
* @see com.alibaba.cloud.dubbo.metadata.event.DubboBootstrapPreStartEvent
* @see com.alibaba.cloud.dubbo.metadata.event.DubboBootstrapStartedEvent
* publish Dubbo microsystem startup finish event.
*
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
*/
@Component
public class DubboBootstrapCommandLineRunner
public class DubboBootstrapStartCommandLineRunner
implements CommandLineRunner, ApplicationEventPublisherAware {
private ApplicationEventPublisher applicationEventPublisher;
@ -45,7 +44,7 @@ public class DubboBootstrapCommandLineRunner
@Override
public void run(String... args) {
applicationEventPublisher.publishEvent(
new DubboBootstrapStartedEvent(DubboBootstrap.getInstance()));
new DubboBootstrapStartedEvent(DubboBootstrapWrapper.getInstance()));
}
}

@ -14,22 +14,34 @@
* 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>
*/
public class DubboBootstrapPreStartEvent extends ApplicationEvent {
/**
* 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})
*/
public DubboBootstrapPreStartEvent(Object source) {
super(source);
public final class DubboBootstrapWrapper {
private DubboBootstrapWrapper() {
}
private static final DubboBootstrapWrapper INSTANCE = new DubboBootstrapWrapper();
public static DubboBootstrapWrapper getInstance() {
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.
*/
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;
/**
* Dubbo microsytem start finish event, every thing is ready.
*
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
*/
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
* event is associated (never {@code null})
*/
public DubboBootstrapStartedEvent(Object source) {
public DubboBootstrapStartedEvent(DubboBootstrapWrapper source) {
super(source);
}
@Override
public DubboBootstrap getSource() {
return (DubboBootstrap) super.getSource();
public DubboBootstrapWrapper getSource() {
return (DubboBootstrapWrapper) super.getSource();
}
}
Loading…
Cancel
Save