Skip to content

Commit

Permalink
refactor: 部分类调整非公开、SpringEventHandlerFactory返回AggregateEventHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
livk-cloud committed Feb 19, 2024
1 parent 5078598 commit d3391c7
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
*
* @author livk
*/
public class ClassPathDisruptorScanner extends ClassPathBeanDefinitionScanner {
class ClassPathDisruptorScanner extends ClassPathBeanDefinitionScanner {

private final BeanNameGenerator beanNameGenerator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* @author livk
*/
@Slf4j
public class DisruptorRegistrar implements ImportBeanDefinitionRegistrar {
class DisruptorRegistrar implements ImportBeanDefinitionRegistrar {

@Override
public void registerBeanDefinitions(@NonNull AnnotationMetadata importingClassMetadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.livk.core.disruptor.support.DisruptorCustomizer;
import com.livk.core.disruptor.support.SpringDisruptor;
import com.livk.core.disruptor.support.SpringEventHandler;
import com.lmax.disruptor.WaitStrategy;
import com.lmax.disruptor.dsl.ProducerType;
import java.util.concurrent.ThreadFactory;
Expand Down Expand Up @@ -89,12 +88,11 @@ private WaitStrategy createWaitStrategy() {
public void afterPropertiesSet() {
SpringEventFactory<T> factory = new SpringEventFactory<>();
ResolvableType disruptorCustomizerType = ResolvableType.forClassWithGenerics(DisruptorCustomizer.class, type);
SpringEventHandler<T> springEventHandler = new SpringEventHandler<>(beanFactory, type);
int bufferSize = attributes.getNumber("bufferSize").intValue();
ProducerType producerType = attributes.getEnum("type");
disruptor = new SpringDisruptor<>(factory, bufferSize, createThreadFactory(), producerType,
createWaitStrategy());
disruptor.handleEventsWith(springEventHandler);
disruptor.handleEventsWith(SpringEventHandlerFactory.create(beanFactory, type));
beanFactory.<DisruptorCustomizer<T>>getBeanProvider(disruptorCustomizerType)
.forEach(customizer -> customizer.customize(disruptor));
disruptor.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/**
* @author livk
*/
public class SpringEventFactory<T> implements EventFactory<DisruptorEventWrapper<T>> {
class SpringEventFactory<T> implements EventFactory<DisruptorEventWrapper<T>> {

public DisruptorEventWrapper<T> newInstance() {
return new DisruptorEventWrapper<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2021-2024 spring-boot-extension the original author or authors.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.livk.core.disruptor.factory;

import com.livk.core.disruptor.DisruptorEventConsumer;
import com.livk.core.disruptor.support.DisruptorEventWrapper;
import com.lmax.disruptor.AggregateEventHandler;
import com.lmax.disruptor.EventHandler;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.core.ResolvableType;

/**
* The type Spring event handler.
*
* @author livk
*/

final class SpringEventHandlerFactory {

@SuppressWarnings("unchecked")
public static <T> EventHandler<DisruptorEventWrapper<T>> create(BeanFactory beanFactory, Class<T> type){
ResolvableType resolvableType = ResolvableType.forClassWithGenerics(DisruptorEventConsumer.class, type);
ObjectProvider<DisruptorEventConsumer<T>> disruptorEventConsumers = beanFactory.getBeanProvider(resolvableType);
return new AggregateEventHandler<>(disruptorEventConsumers.orderedStream().toArray(DisruptorEventConsumer[]::new));
}
}

This file was deleted.

0 comments on commit d3391c7

Please sign in to comment.