当前位置: 首页>>代码示例>>Java>>正文


Java ApplicationReadyEvent类代码示例

本文整理汇总了Java中org.springframework.boot.context.event.ApplicationReadyEvent的典型用法代码示例。如果您正苦于以下问题:Java ApplicationReadyEvent类的具体用法?Java ApplicationReadyEvent怎么用?Java ApplicationReadyEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ApplicationReadyEvent类属于org.springframework.boot.context.event包,在下文中一共展示了ApplicationReadyEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import org.springframework.boot.context.event.ApplicationReadyEvent; //导入依赖的package包/类
/**
 * Start the controller
 */
@EventListener(ApplicationReadyEvent.class)
public void start() {
	log.info("Starting sessions");
	// setup reconnect tasks
	for (final GroupSession group : groups.values()) {
		group.start();
		Runnable reconnectTask = new Runnable() {

			@Override
			public void run() {
				try {
					if (group.isStopped()) {
						group.stop();
						log.info("Attempting to reconnect...");
						group.start();
					}
				} catch (Exception e) {
					log.error(e.getLocalizedMessage());
				}
			}
		};
		Schedule.getInstance().at(reconnectTask, reconnectInterval, true);
	}

}
 
开发者ID:mshaw323,项目名称:stdds-monitor,代码行数:29,代码来源:StatusController.java

示例2: onApplicationReadyEvent

import org.springframework.boot.context.event.ApplicationReadyEvent; //导入依赖的package包/类
@EventListener
public void onApplicationReadyEvent(ApplicationReadyEvent event) {
	Flux
		.interval(Duration.ofMillis(1000))
		.flatMap(tick -> repository.findAll())
		.map(image -> {
			Comment comment = new Comment();
			comment.setImageId(image.getId());
			comment.setComment(
				"Comment #" + counter.getAndIncrement());
			return Mono.just(comment);
		})
		.flatMap(newComment ->
			Mono.defer(() ->
				controller.addComment(newComment)))
		.subscribe();
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:18,代码来源:CommentSimulator.java

示例3: simulateComments

import org.springframework.boot.context.event.ApplicationReadyEvent; //导入依赖的package包/类
@EventListener
public void simulateComments(ApplicationReadyEvent event) {
	Flux
		.interval(Duration.ofMillis(1000))
		.flatMap(tick -> repository.findAll())
		.map(image -> {
			Comment comment = new Comment();
			comment.setImageId(image.getId());
			comment.setComment(
				"Comment #" + counter.getAndIncrement());
			return Mono.just(comment);
		})
		.flatMap(newComment ->
			Mono.defer(() ->
				controller.addComment(newComment)))
		.subscribe();
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:18,代码来源:CommentSimulator.java

示例4: simulateComments

import org.springframework.boot.context.event.ApplicationReadyEvent; //导入依赖的package包/类
@EventListener
public void simulateComments(ApplicationReadyEvent event) {
	Flux
		.interval(Duration.ofMillis(1000))
		.flatMap(tick -> repository.findAll())
		.map(image -> {
			Comment comment = new Comment();
			comment.setImageId(image.getId());
			comment.setComment(
				"Comment #" + counter.getAndIncrement());
			return Mono.just(comment);
		})
		.flatMap(newComment ->
			Mono.defer(() ->
				commentController.addComment(newComment)))
		.subscribe();
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:18,代码来源:CommentSimulator.java

示例5: onApplicationEvent

import org.springframework.boot.context.event.ApplicationReadyEvent; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
  URI uri = URI.create("http://localhost:" + port);
  if (Desktop.isDesktopSupported()) {
    Desktop desktop = Desktop.getDesktop();
    if (desktop.isSupported(Desktop.Action.BROWSE)) {
      try {
        desktop.browse(uri);
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  } else if (IS_MAC) {
    openUrlInBrowser(uri.toString());
  }
}
 
开发者ID:Terracotta-OSS,项目名称:tinypounder,代码行数:18,代码来源:ApplicationReadyListener.java

示例6: onApplicationEvent

import org.springframework.boot.context.event.ApplicationReadyEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
    log.info("Checking subscriptions to {}", config.aws.topic.subscribeArn);

    String thisEndpoint = "http://" + appInfo.getPublicHostname() + SnsCamEchoResponseEndpoint.SNS_EP_CAM_ECHO_RESPONSE;

    List<Subscription> subscriptions = amazonSns.listSubscriptionsByTopic(config.aws.topic.subscribeArn).getSubscriptions();
    boolean notSubscribed = true;
    for (Subscription subscription : subscriptions) {
        if (thisEndpoint.equals(subscription.getEndpoint())) {
            log.info("Found subscription {} on topic {} for endpoint {}", subscription.getSubscriptionArn(), subscription.getTopicArn(), thisEndpoint);
            notSubscribed = false;
        }
    }

    if (notSubscribed) {
        log.info("Subscribing to topic {} with endpoint {}", config.aws.topic.subscribeArn, thisEndpoint);
        SubscribeResult subscribeResult = amazonSns.subscribe(config.aws.topic.subscribeArn, "http", thisEndpoint);
        log.info("Subscription: {}", subscribeResult.getSubscriptionArn());
    }
}
 
开发者ID:holisticon,项目名称:holunda,代码行数:22,代码来源:SnsCamEchoResponseEndpoint.java

示例7: onApplicationEvent

import org.springframework.boot.context.event.ApplicationReadyEvent; //导入依赖的package包/类
@Override
    public void onApplicationEvent(ApplicationReadyEvent event) {
        if (event.getApplicationContext().getParent() == null) {
//        	HystrixPlugins.getInstance().registerCommandExecutionHook(impl);
//        	HystrixPlugins.getInstance().getCommandExecutionHook();
//        	if(!(HystrixPlugins.getInstance().getCommandExecutionHook() instanceof SecurityContextRegistratorCommandHook)){
            try {
                HystrixPlugins.getInstance().registerCommandExecutionHook(new SecurityContextRegistratorCommandHook());
            } catch (Exception e) {
                // TODO: handle exception
            }

//        	}

            logger.debug("初始化HystrixPlugins完成");
        }
    }
 
开发者ID:zhaoqilong3031,项目名称:spring-cloud-samples,代码行数:18,代码来源:ApplicationReadyListenter.java

示例8: onApplicationEvent

import org.springframework.boot.context.event.ApplicationReadyEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationReadyEvent arg0) {

	Random n = new Random();
	int i = 1;
	int max = 40;

	System.out.println("SAVING SEATS...");
	// System.out.println("SAVING ATTENTIONS...");
	// System.out.println("SAVING HISTORY POINTS...");
	for (i = 1; i <= max; i++) {

		Seat seat = saveSeats(i);

		// saveAttentions(i, seat);
		// saveHistoryPoints(i, seat);
	}
	System.out.println("SAVING SEATS... COMPLETED");
	// System.out.println("SAVING ATTENTIONS... COMPLETED");
	// System.out.println("SAVING HISTORY POINTS... COMPLETED");

	saveQuestions();
}
 
开发者ID:edylle,项目名称:hockey-game,代码行数:24,代码来源:ApplicationStartup.java

示例9: customize

import org.springframework.boot.context.event.ApplicationReadyEvent; //导入依赖的package包/类
@Test
public void customize() throws LifecycleException {
	Context standardContext = mock(Context.class);
	StandardRoot webResourceRoot = new StandardRoot(standardContext);
	Mockito.when(standardContext.getResources()).thenReturn(webResourceRoot);
	Mockito.when(standardContext.getAddWebinfClassesResources()).thenReturn(Boolean.FALSE);

	JsfTomcatContextCustomizer jsfTomcatContextCustomizer = new JsfTomcatContextCustomizer();
	jsfTomcatContextCustomizer.customize(standardContext);

	JsfTomcatApplicationListener jsfTomcatApplicationListener = JsfTomcatApplicationListener
		.builder().context(jsfTomcatContextCustomizer.getContext()).build();
	jsfTomcatApplicationListener.onApplicationEvent(mock(ApplicationReadyEvent.class));
	assertThat(webResourceRoot.getPostResources().length)
		.isEqualTo(9);
}
 
开发者ID:joinfaces,项目名称:joinfaces,代码行数:17,代码来源:JsfTomcatApplicationListenerIT.java

示例10: resourcesNull

import org.springframework.boot.context.event.ApplicationReadyEvent; //导入依赖的package包/类
@Test
public void resourcesNull() throws LifecycleException {
	Context standardContext = mock(Context.class);
	Mockito.when(standardContext.getResources()).thenReturn(null);
	Mockito.when(standardContext.getAddWebinfClassesResources()).thenReturn(Boolean.FALSE);

	JsfTomcatContextCustomizer jsfTomcatContextCustomizer = new JsfTomcatContextCustomizer();
	jsfTomcatContextCustomizer.customize(standardContext);

	JsfTomcatApplicationListener jsfTomcatApplicationListener = JsfTomcatApplicationListener
		.builder().context(jsfTomcatContextCustomizer.getContext()).build();
	jsfTomcatApplicationListener.onApplicationEvent(mock(ApplicationReadyEvent.class));

	assertThat(jsfTomcatApplicationListener)
		.isNotNull();
}
 
开发者ID:joinfaces,项目名称:joinfaces,代码行数:17,代码来源:JsfTomcatApplicationListenerIT.java

示例11: jarResourcesNull

import org.springframework.boot.context.event.ApplicationReadyEvent; //导入依赖的package包/类
@Test
public void jarResourcesNull() throws LifecycleException {
	Context standardContext = mock(Context.class);
	WebResourceRoot webResourceRoot = mock(WebResourceRoot.class);
	Mockito.when(standardContext.getResources()).thenReturn(webResourceRoot);
	Mockito.when(standardContext.getAddWebinfClassesResources()).thenReturn(Boolean.FALSE);
	Mockito.when(webResourceRoot.getJarResources()).thenReturn(null);

	JsfTomcatContextCustomizer jsfTomcatContextCustomizer = new JsfTomcatContextCustomizer();
	jsfTomcatContextCustomizer.customize(standardContext);

	JsfTomcatApplicationListener jsfTomcatApplicationListener = JsfTomcatApplicationListener
		.builder().context(jsfTomcatContextCustomizer.getContext()).build();
	jsfTomcatApplicationListener.onApplicationEvent(mock(ApplicationReadyEvent.class));

	assertThat(jsfTomcatApplicationListener)
		.isNotNull();
}
 
开发者ID:joinfaces,项目名称:joinfaces,代码行数:19,代码来源:JsfTomcatApplicationListenerIT.java

示例12: applicationRunningEventListener

import org.springframework.boot.context.event.ApplicationReadyEvent; //导入依赖的package包/类
@Test
public void applicationRunningEventListener() {
	SpringApplication application = new SpringApplication(ExampleConfig.class);
	application.setWebEnvironment(false);
	final AtomicReference<SpringApplication> reference = new AtomicReference<SpringApplication>();
	class ApplicationReadyEventListener
			implements ApplicationListener<ApplicationReadyEvent> {
		@Override
		public void onApplicationEvent(ApplicationReadyEvent event) {
			reference.set(event.getSpringApplication());
		}
	}
	application.addListeners(new ApplicationReadyEventListener());
	this.context = application.run("--foo=bar");
	assertThat(application).isSameAs(reference.get());
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:SpringApplicationTests.java

示例13: eventsOrder

import org.springframework.boot.context.event.ApplicationReadyEvent; //导入依赖的package包/类
@Test
public void eventsOrder() {
	SpringApplication application = new SpringApplication(ExampleConfig.class);
	application.setWebEnvironment(false);
	final List<ApplicationEvent> events = new ArrayList<ApplicationEvent>();
	class ApplicationRunningEventListener
			implements ApplicationListener<ApplicationEvent> {
		@Override
		public void onApplicationEvent(ApplicationEvent event) {
			events.add((event));
		}
	}
	application.addListeners(new ApplicationRunningEventListener());
	this.context = application.run();
	assertThat(events).hasSize(5);
	assertThat(events.get(0)).isInstanceOf(ApplicationStartedEvent.class);
	assertThat(events.get(1)).isInstanceOf(ApplicationEnvironmentPreparedEvent.class);
	assertThat(events.get(2)).isInstanceOf(ApplicationPreparedEvent.class);
	assertThat(events.get(3)).isInstanceOf(ContextRefreshedEvent.class);
	assertThat(events.get(4)).isInstanceOf(ApplicationReadyEvent.class);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:22,代码来源:SpringApplicationTests.java

示例14: onApplicationEvent

import org.springframework.boot.context.event.ApplicationReadyEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationEvent event) {
	if (event instanceof ApplicationStartedEvent) {
		onApplicationStartedEvent((ApplicationStartedEvent) event);
	}
	if (event instanceof ApplicationPreparedEvent) {
		Restarter.getInstance()
				.prepare(((ApplicationPreparedEvent) event).getApplicationContext());
	}
	if (event instanceof ApplicationReadyEvent
			|| event instanceof ApplicationFailedEvent) {
		Restarter.getInstance().finish();
		if (event instanceof ApplicationFailedEvent) {
			Restarter.getInstance().prepare(null);
		}
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:RestartApplicationListener.java

示例15: testInitialize

import org.springframework.boot.context.event.ApplicationReadyEvent; //导入依赖的package包/类
private void testInitialize(boolean failed) {
	Restarter.clearInstance();
	RestartApplicationListener listener = new RestartApplicationListener();
	SpringApplication application = new SpringApplication();
	ConfigurableApplicationContext context = mock(
			ConfigurableApplicationContext.class);
	listener.onApplicationEvent(new ApplicationStartedEvent(application, ARGS));
	assertThat(Restarter.getInstance()).isNotEqualTo(nullValue());
	assertThat(Restarter.getInstance().isFinished()).isFalse();
	listener.onApplicationEvent(
			new ApplicationPreparedEvent(application, ARGS, context));
	if (failed) {
		listener.onApplicationEvent(new ApplicationFailedEvent(application, ARGS,
				context, new RuntimeException()));
	}
	else {
		listener.onApplicationEvent(
				new ApplicationReadyEvent(application, ARGS, context));
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:21,代码来源:RestartApplicationListenerTests.java


注:本文中的org.springframework.boot.context.event.ApplicationReadyEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。