org.springframework.cloud.context.scope.refresh.RefreshScopeRefreshedEvent Java Examples

The following examples show how to use org.springframework.cloud.context.scope.refresh.RefreshScopeRefreshedEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TraceReactorAutoConfiguration.java    From spring-cloud-sleuth with Apache License 2.0 6 votes vote down vote up
@Override
public void onApplicationEvent(RefreshScopeRefreshedEvent event) {
	if (log.isDebugEnabled()) {
		log.debug("Context refreshed, will reset hooks and then re-register them");
	}
	Hooks.resetOnEachOperator(SLEUTH_TRACE_REACTOR_KEY);
	Hooks.resetOnLastOperator(SLEUTH_TRACE_REACTOR_KEY);
	if (this.reactorProperties.isDecorateOnEach()) {
		if (log.isTraceEnabled()) {
			log.trace("Decorating onEach operator instrumentation");
		}
		Hooks.onEachOperator(SLEUTH_TRACE_REACTOR_KEY,
				scopePassingSpanOperator(this.context));
	}
	else {
		if (log.isTraceEnabled()) {
			log.trace("Decorating onLast operator instrumentation");
		}
		Hooks.onLastOperator(SLEUTH_TRACE_REACTOR_KEY,
				scopePassingSpanOperator(this.context));
	}
}
 
Example #2
Source File: RefreshScopeIntegrationTests.java    From spring-cloud-commons with Apache License 2.0 6 votes vote down vote up
@Test
@DirtiesContext
public void testRefresh() throws Exception {
	then(this.service.getMessage()).isEqualTo("Hello scope!");
	String id1 = this.service.toString();
	// Change the dynamic property source...
	this.properties.setMessage("Foo");
	// ...and then refresh, so the bean is re-initialized:
	this.scope.refreshAll();
	String id2 = this.service.toString();
	then(this.service.getMessage()).isEqualTo("Foo");
	then(ExampleService.getInitCount()).isEqualTo(1);
	then(ExampleService.getDestroyCount()).isEqualTo(1);
	then(id2).isNotSameAs(id1);
	then(ExampleService.event).isNotNull();
	then(ExampleService.event.getName())
			.isEqualTo(RefreshScopeRefreshedEvent.DEFAULT_NAME);
}
 
Example #3
Source File: MultRegisterCenterServerMgmtConfig.java    From Moss with Apache License 2.0 5 votes vote down vote up
@EventListener(RefreshScopeRefreshedEvent.class)
public void onApplicationEvent(RefreshScopeRefreshedEvent event) {

    //This will force the creation of the EurkaClient bean if not already created
    //to make sure the client will be reregistered after a refresh event
    multRegisterCenter.multRegistrationMap.entrySet().forEach(e -> {
        MossEurekaAutoServiceRegistration autoRegistration = e.getValue();
        if (autoRegistration != null) {
            // register in case meta data changed
            autoRegistration.stop();
            autoRegistration.start();
        }
    });
}
 
Example #4
Source File: DSSSpringApplication.java    From DataSphereStudio with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    RuntimeDelegate.setInstance(new org.glassfish.jersey.internal.RuntimeDelegateImpl());
    final SpringApplication application = new SpringApplication(DSSSpringApplication.class);
    application.addListeners(new ApplicationListener<ApplicationPreparedEvent>(){
        public void onApplicationEvent(ApplicationPreparedEvent applicationPreparedEvent) {
            logger.info("add config from config server...");
            if(applicationContext == null) {
                applicationContext = applicationPreparedEvent.getApplicationContext();
                try {
                    setApplicationContext(applicationContext);
                } catch (Exception e) {
                    logger.error(e);
                }
            }
            addRemoteConfig();
            logger.info("initialize DataWorkCloud spring application...");
            initDWCApplication();
        }
    });
    application.addListeners(new ApplicationListener<RefreshScopeRefreshedEvent>() {
        public void onApplicationEvent(RefreshScopeRefreshedEvent applicationEvent) {
            logger.info("refresh config from config server...");
            updateRemoteConfig();
        }
    });
    String listeners = ServerConfiguration.BDP_SERVER_SPRING_APPLICATION_LISTENERS().getValue();
    if(StringUtils.isNotBlank(listeners)) {
        for (String listener : listeners.split(",")) {
            application.addListeners((ApplicationListener<?>) Class.forName(listener).newInstance());
        }
    }
    applicationContext = application.run(args);
    setApplicationContext(applicationContext);
}
 
Example #5
Source File: ContextRefreshLock.java    From rabbitmq-mock with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof RefreshScopeRefreshedEvent) {
        logger.info("Context refreshed !");
        semaphore.release();
    } else {
        logger.info("Notified of " + event);
    }
}
 
Example #6
Source File: RefreshEndpointTests.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationEvent(ApplicationEvent event) {
	if (event instanceof EnvironmentChangeEvent
			|| event instanceof RefreshScopeRefreshedEvent) {
		this.events.add(event);
	}
}
 
Example #7
Source File: EurekaDiscoveryClientConfiguration.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
public void onApplicationEvent(RefreshScopeRefreshedEvent event) {
	// This will force the creation of the EurkaClient bean if not already created
	// to make sure the client will be reregistered after a refresh event
	if (eurekaClient != null) {
		eurekaClient.getApplications();
	}
	if (autoRegistration != null) {
		// register in case meta data changed
		this.autoRegistration.stop();
		this.autoRegistration.start();
	}
}
 
Example #8
Source File: ConfigRefreshTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
// This test is used to verify that getApplications is called the correct number of
// times when a refresh event is fired. The getApplications call in
// EurekaClientConfigurationRefresher.onApplicationEvent
// ensures that the EurekaClient bean is recreated after a refresh event and that we
// reregister the client with the server
public void verifyGetApplications() {
	if (publisher != null) {
		publisher.publishEvent(new RefreshScopeRefreshedEvent());
	}
	verify(client, times(3)).getApplications();
}
 
Example #9
Source File: EurekaClientEventListener.java    From mPaaS with Apache License 2.0 4 votes vote down vote up
@EventListener
public void listen(RefreshScopeRefreshedEvent event) {
    log.info("实例[{}]注册事件", event.getName());
}
 
Example #10
Source File: EurekaServerListProcessor.java    From spring-cloud-gray with Apache License 2.0 4 votes vote down vote up
@Order
@EventListener(RefreshScopeRefreshedEvent.class)
public void onApplicationEvent(RefreshScopeRefreshedEvent event) {
    reloadAndRegister();
}
 
Example #11
Source File: ReservationServiceApplication.java    From training with Apache License 2.0 4 votes vote down vote up
@EventListener(RefreshScopeRefreshedEvent.class)
public void configRefreshed(RefreshScopeRefreshedEvent event) {
	System.out.println("something's changed! reconfiguring internal state now...");
}
 
Example #12
Source File: ReservationServiceApplication.java    From training with Apache License 2.0 4 votes vote down vote up
@EventListener(RefreshScopeRefreshedEvent.class)
public void configRefreshed(RefreshScopeRefreshedEvent event) {
	System.out.println("something's changed! reconfiguring internal state now...");
}
 
Example #13
Source File: RefreshEndpointTests.java    From spring-cloud-commons with Apache License 2.0 4 votes vote down vote up
@Override
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
	return EnvironmentChangeEvent.class.isAssignableFrom(eventType)
			|| RefreshScopeRefreshedEvent.class.isAssignableFrom(eventType);
}
 
Example #14
Source File: RefreshScopeIntegrationTests.java    From spring-cloud-commons with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(RefreshScopeRefreshedEvent e) {
	event = e;
}