Search in sources :

Example 1 with MDCCleanerThreadPoolExecutor

use of com.sequenceiq.cloudbreak.logger.concurrent.MDCCleanerThreadPoolExecutor in project cloudbreak by hortonworks.

the class ContextClosedEventHandlerTest method testHandleContextClosedEventShouldStopExecutor.

@Test
public void testHandleContextClosedEventShouldStopExecutor() {
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
    applicationContext.getEnvironment().setActiveProfiles(TEST_PROFILE);
    applicationContext.register(EventBusConfig.class, ContextClosedEventHandler.class, FlowRegister.class, TestMetricService.class);
    applicationContext.refresh();
    MDCCleanerThreadPoolExecutor eventBusThreadPoolExecutor = applicationContext.getBean("eventBusThreadPoolExecutor", MDCCleanerThreadPoolExecutor.class);
    Assertions.assertFalse(eventBusThreadPoolExecutor.isShutdown());
    EventBus eventBus = applicationContext.getBean(EventBus.class);
    Assertions.assertTrue(eventBus.getDispatcher().alive());
    applicationContext.close();
    Assertions.assertTrue(eventBusThreadPoolExecutor.isShutdown());
    Assertions.assertFalse(eventBus.getDispatcher().alive());
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MDCCleanerThreadPoolExecutor(com.sequenceiq.cloudbreak.logger.concurrent.MDCCleanerThreadPoolExecutor) EventBus(reactor.bus.EventBus) Test(org.junit.jupiter.api.Test)

Example 2 with MDCCleanerThreadPoolExecutor

use of com.sequenceiq.cloudbreak.logger.concurrent.MDCCleanerThreadPoolExecutor in project cloudbreak by hortonworks.

the class EventBusConfig method reactor.

@Bean
public EventBus reactor(MDCCleanerThreadPoolExecutor threadPoolExecutor, Environment env) {
    ThreadPoolExecutorDispatcher dispatcher = new ThreadPoolExecutorDispatcher(eventBusThreadPoolBacklogSize, eventBusThreadPoolCoreSize, threadPoolExecutor);
    EventBus eventBus = new EventBusSpec().env(env).dispatcher(dispatcher).traceEventPath().dispatchErrorHandler(throwable -> {
        handleFlowFail(throwable, dispatcher);
        LOGGER.error("Exception happened in dispatcher", throwable);
    }).uncaughtErrorHandler(throwable -> {
        handleFlowFail(throwable, dispatcher);
        LOGGER.error("Uncaught exception happened", throwable);
    }).consumerNotFoundHandler(new ConsumerNotFoundHandler()).get();
    return new ConsumerCheckerEventBus(eventBus);
}
Also used : Arrays(java.util.Arrays) EventCanNotBeDeliveredException(com.sequenceiq.flow.reactor.eventbus.EventCanNotBeDeliveredException) ConsumerNotFoundHandler(com.sequenceiq.flow.reactor.handler.ConsumerNotFoundHandler) Timer(reactor.fn.timer.Timer) LoggerFactory(org.slf4j.LoggerFactory) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) ConsumerCheckerEventBus(com.sequenceiq.flow.reactor.eventbus.ConsumerCheckerEventBus) NamedDaemonThreadFactory(reactor.core.support.NamedDaemonThreadFactory) ApplicationFlowInformation(com.sequenceiq.flow.core.ApplicationFlowInformation) Event(reactor.bus.Event) ThreadPoolExecutorDispatcher(reactor.core.dispatch.ThreadPoolExecutorDispatcher) LinkedHashSet(java.util.LinkedHashSet) Logger(org.slf4j.Logger) EventBus(reactor.bus.EventBus) EventBusSpec(reactor.bus.spec.EventBusSpec) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) MDCCleanerThreadPoolExecutor(com.sequenceiq.cloudbreak.logger.concurrent.MDCCleanerThreadPoolExecutor) TimeUnit(java.util.concurrent.TimeUnit) Configuration(org.springframework.context.annotation.Configuration) Exceptions(reactor.core.support.Exceptions) Lazy(org.springframework.context.annotation.Lazy) FlowLogDBService(com.sequenceiq.flow.service.flowlog.FlowLogDBService) Bean(org.springframework.context.annotation.Bean) Environment(reactor.Environment) EventBusSpec(reactor.bus.spec.EventBusSpec) ThreadPoolExecutorDispatcher(reactor.core.dispatch.ThreadPoolExecutorDispatcher) ConsumerCheckerEventBus(com.sequenceiq.flow.reactor.eventbus.ConsumerCheckerEventBus) EventBus(reactor.bus.EventBus) ConsumerNotFoundHandler(com.sequenceiq.flow.reactor.handler.ConsumerNotFoundHandler) ConsumerCheckerEventBus(com.sequenceiq.flow.reactor.eventbus.ConsumerCheckerEventBus) Bean(org.springframework.context.annotation.Bean)

Aggregations

MDCCleanerThreadPoolExecutor (com.sequenceiq.cloudbreak.logger.concurrent.MDCCleanerThreadPoolExecutor)2 EventBus (reactor.bus.EventBus)2 MDCBuilder (com.sequenceiq.cloudbreak.logger.MDCBuilder)1 ApplicationFlowInformation (com.sequenceiq.flow.core.ApplicationFlowInformation)1 ConsumerCheckerEventBus (com.sequenceiq.flow.reactor.eventbus.ConsumerCheckerEventBus)1 EventCanNotBeDeliveredException (com.sequenceiq.flow.reactor.eventbus.EventCanNotBeDeliveredException)1 ConsumerNotFoundHandler (com.sequenceiq.flow.reactor.handler.ConsumerNotFoundHandler)1 FlowLogDBService (com.sequenceiq.flow.service.flowlog.FlowLogDBService)1 Arrays (java.util.Arrays)1 LinkedHashSet (java.util.LinkedHashSet)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 Test (org.junit.jupiter.api.Test)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Value (org.springframework.beans.factory.annotation.Value)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 Bean (org.springframework.context.annotation.Bean)1