阿里巴巴代码规约扫描修改.

pull/110/head
chen.ma 3 years ago
parent c9dbeaab3b
commit 0f3287403d

@ -9,7 +9,7 @@ import java.util.concurrent.atomic.AtomicLong;
* @author chen.ma * @author chen.ma
* @date 2021/6/23 18:59 * @date 2021/6/23 18:59
*/ */
public abstract class Event implements Serializable { public abstract class AbstractEvent implements Serializable {
private static final AtomicLong SEQUENCE = new AtomicLong(0); private static final AtomicLong SEQUENCE = new AtomicLong(0);

@ -6,7 +6,7 @@ package cn.hippo4j.config.event;
* @author chen.ma * @author chen.ma
* @date 2021/6/23 19:05 * @date 2021/6/23 19:05
*/ */
public abstract class SlowEvent extends Event { public abstract class AbstractSlowEvent extends AbstractEvent {
@Override @Override
public long sequence() { public long sequence() {

@ -8,7 +8,7 @@ import org.springframework.util.StringUtils;
* @author chen.ma * @author chen.ma
* @date 2021/6/24 23:35 * @date 2021/6/24 23:35
*/ */
public class ConfigDataChangeEvent extends Event { public class ConfigDataChangeEvent extends AbstractEvent {
public final String tenantId; public final String tenantId;

@ -6,7 +6,7 @@ package cn.hippo4j.config.event;
* @author chen.ma * @author chen.ma
* @date 2021/6/23 19:13 * @date 2021/6/23 19:13
*/ */
public class LocalDataChangeEvent extends Event { public class LocalDataChangeEvent extends AbstractEvent {
/** /**
* ++线 * ++线

@ -1,8 +1,8 @@
package cn.hippo4j.config.notify; package cn.hippo4j.config.notify;
import cn.hippo4j.config.event.AbstractEvent;
import cn.hutool.core.collection.ConcurrentHashSet; import cn.hutool.core.collection.ConcurrentHashSet;
import cn.hippo4j.config.notify.listener.Subscriber; import cn.hippo4j.config.notify.listener.AbstractSubscriber;
import cn.hippo4j.config.event.Event;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -20,9 +20,9 @@ import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
@Slf4j @Slf4j
public class DefaultPublisher extends Thread implements EventPublisher { public class DefaultPublisher extends Thread implements EventPublisher {
protected final ConcurrentHashSet<Subscriber> subscribers = new ConcurrentHashSet(); protected final ConcurrentHashSet<AbstractSubscriber> subscribers = new ConcurrentHashSet();
private BlockingQueue<Event> queue; private BlockingQueue<AbstractEvent> queue;
private volatile boolean initialized = false; private volatile boolean initialized = false;
@ -36,7 +36,7 @@ public class DefaultPublisher extends Thread implements EventPublisher {
.newUpdater(DefaultPublisher.class, Long.class, "lastEventSequence"); .newUpdater(DefaultPublisher.class, Long.class, "lastEventSequence");
@Override @Override
public void init(Class<? extends Event> type, int bufferSize) { public void init(Class<? extends AbstractEvent> type, int bufferSize) {
setDaemon(true); setDaemon(true);
setName("dynamic.thread-pool.publisher-" + type.getName()); setName("dynamic.thread-pool.publisher-" + type.getName());
this.queueMaxSize = bufferSize; this.queueMaxSize = bufferSize;
@ -80,7 +80,7 @@ public class DefaultPublisher extends Thread implements EventPublisher {
if (shutdown) { if (shutdown) {
break; break;
} }
final Event event = queue.take(); final AbstractEvent event = queue.take();
receiveEvent(event); receiveEvent(event);
UPDATER.compareAndSet(this, lastEventSequence, Math.max(lastEventSequence, event.sequence())); UPDATER.compareAndSet(this, lastEventSequence, Math.max(lastEventSequence, event.sequence()));
} }
@ -90,12 +90,12 @@ public class DefaultPublisher extends Thread implements EventPublisher {
} }
@Override @Override
public void addSubscriber(Subscriber subscriber) { public void addSubscriber(AbstractSubscriber subscriber) {
subscribers.add(subscriber); subscribers.add(subscriber);
} }
@Override @Override
public boolean publish(Event event) { public boolean publish(AbstractEvent event) {
boolean success = this.queue.offer(event); boolean success = this.queue.offer(event);
if (!success) { if (!success) {
log.warn("Unable to plug in due to interruption, synchronize sending time, event :: {}", event); log.warn("Unable to plug in due to interruption, synchronize sending time, event :: {}", event);
@ -106,7 +106,7 @@ public class DefaultPublisher extends Thread implements EventPublisher {
} }
@Override @Override
public void notifySubscriber(Subscriber subscriber, Event event) { public void notifySubscriber(AbstractSubscriber subscriber, AbstractEvent event) {
final Runnable job = () -> subscriber.onEvent(event); final Runnable job = () -> subscriber.onEvent(event);
final Executor executor = subscriber.executor(); final Executor executor = subscriber.executor();
@ -126,8 +126,8 @@ public class DefaultPublisher extends Thread implements EventPublisher {
return !CollectionUtils.isEmpty(subscribers); return !CollectionUtils.isEmpty(subscribers);
} }
void receiveEvent(Event event) { void receiveEvent(AbstractEvent event) {
for (Subscriber subscriber : subscribers) { for (AbstractSubscriber subscriber : subscribers) {
notifySubscriber(subscriber, event); notifySubscriber(subscriber, event);
} }
} }

@ -1,9 +1,9 @@
package cn.hippo4j.config.notify; package cn.hippo4j.config.notify;
import cn.hippo4j.config.event.AbstractEvent;
import cn.hutool.core.collection.ConcurrentHashSet; import cn.hutool.core.collection.ConcurrentHashSet;
import cn.hippo4j.config.notify.listener.Subscriber; import cn.hippo4j.config.notify.listener.AbstractSubscriber;
import cn.hippo4j.config.event.Event; import cn.hippo4j.config.event.AbstractSlowEvent;
import cn.hippo4j.config.event.SlowEvent;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -19,21 +19,21 @@ import java.util.concurrent.locks.ReentrantLock;
*/ */
public class DefaultSharePublisher extends DefaultPublisher { public class DefaultSharePublisher extends DefaultPublisher {
private final Map<Class<? extends SlowEvent>, Set<Subscriber>> subMappings = new ConcurrentHashMap(); private final Map<Class<? extends AbstractSlowEvent>, Set<AbstractSubscriber>> subMappings = new ConcurrentHashMap();
protected final ConcurrentHashSet<Subscriber> subscribers = new ConcurrentHashSet(); protected final ConcurrentHashSet<AbstractSubscriber> subscribers = new ConcurrentHashSet();
private final Lock lock = new ReentrantLock(); private final Lock lock = new ReentrantLock();
public void addSubscriber(Subscriber subscriber, Class<? extends Event> subscribeType) { public void addSubscriber(AbstractSubscriber subscriber, Class<? extends AbstractEvent> subscribeType) {
Class<? extends SlowEvent> subSlowEventType = (Class<? extends SlowEvent>) subscribeType; Class<? extends AbstractSlowEvent> subSlowEventType = (Class<? extends AbstractSlowEvent>) subscribeType;
subscribers.add(subscriber); subscribers.add(subscriber);
lock.lock(); lock.lock();
try { try {
Set<Subscriber> sets = subMappings.get(subSlowEventType); Set<AbstractSubscriber> sets = subMappings.get(subSlowEventType);
if (sets == null) { if (sets == null) {
Set<Subscriber> newSet = new ConcurrentHashSet(); Set<AbstractSubscriber> newSet = new ConcurrentHashSet();
newSet.add(subscriber); newSet.add(subscriber);
subMappings.put(subSlowEventType, newSet); subMappings.put(subSlowEventType, newSet);
return; return;

@ -1,7 +1,7 @@
package cn.hippo4j.config.notify; package cn.hippo4j.config.notify;
import cn.hippo4j.config.notify.listener.Subscriber; import cn.hippo4j.config.event.AbstractEvent;
import cn.hippo4j.config.event.Event; import cn.hippo4j.config.notify.listener.AbstractSubscriber;
/** /**
* Event publisher. * Event publisher.
@ -17,14 +17,14 @@ public interface EventPublisher {
* @param type * @param type
* @param bufferSize * @param bufferSize
*/ */
void init(Class<? extends Event> type, int bufferSize); void init(Class<? extends AbstractEvent> type, int bufferSize);
/** /**
* Add subscriber. * Add subscriber.
* *
* @param subscriber * @param subscriber
*/ */
void addSubscriber(Subscriber subscriber); void addSubscriber(AbstractSubscriber subscriber);
/** /**
* Publish. * Publish.
@ -32,7 +32,7 @@ public interface EventPublisher {
* @param event * @param event
* @return * @return
*/ */
boolean publish(Event event); boolean publish(AbstractEvent event);
/** /**
* Notify subscriber. * Notify subscriber.
@ -40,6 +40,6 @@ public interface EventPublisher {
* @param subscriber * @param subscriber
* @param event * @param event
*/ */
void notifySubscriber(Subscriber subscriber, Event event); void notifySubscriber(AbstractSubscriber subscriber, AbstractEvent event);
} }

@ -1,11 +1,11 @@
package cn.hippo4j.config.notify; package cn.hippo4j.config.notify;
import cn.hippo4j.config.notify.listener.SmartSubscriber; import cn.hippo4j.config.event.AbstractEvent;
import cn.hippo4j.config.notify.listener.Subscriber; import cn.hippo4j.config.notify.listener.AbstractSmartSubscriber;
import cn.hippo4j.config.notify.listener.AbstractSubscriber;
import cn.hippo4j.config.toolkit.ClassUtil; import cn.hippo4j.config.toolkit.ClassUtil;
import cn.hippo4j.config.toolkit.MapUtil; import cn.hippo4j.config.toolkit.MapUtil;
import cn.hippo4j.config.event.Event; import cn.hippo4j.config.event.AbstractSlowEvent;
import cn.hippo4j.config.event.SlowEvent;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import java.util.Map; import java.util.Map;
@ -33,7 +33,7 @@ public class NotifyCenter {
private static EventPublisher eventPublisher = new DefaultPublisher(); private static EventPublisher eventPublisher = new DefaultPublisher();
private static BiFunction<Class<? extends Event>, Integer, EventPublisher> publisherFactory = null; private static BiFunction<Class<? extends AbstractEvent>, Integer, EventPublisher> publisherFactory = null;
private final Map<String, EventPublisher> publisherMap = new ConcurrentHashMap(16); private final Map<String, EventPublisher> publisherMap = new ConcurrentHashMap(16);
@ -50,13 +50,13 @@ public class NotifyCenter {
}; };
INSTANCE.sharePublisher = new DefaultSharePublisher(); INSTANCE.sharePublisher = new DefaultSharePublisher();
INSTANCE.sharePublisher.init(SlowEvent.class, shareBufferSize); INSTANCE.sharePublisher.init(AbstractSlowEvent.class, shareBufferSize);
} }
public static void registerSubscriber(final Subscriber consumer) { public static void registerSubscriber(final AbstractSubscriber consumer) {
if (consumer instanceof SmartSubscriber) { if (consumer instanceof AbstractSmartSubscriber) {
for (Class<? extends Event> subscribeType : ((SmartSubscriber) consumer).subscribeTypes()) { for (Class<? extends AbstractEvent> subscribeType : ((AbstractSmartSubscriber) consumer).subscribeTypes()) {
if (ClassUtil.isAssignableFrom(SlowEvent.class, subscribeType)) { if (ClassUtil.isAssignableFrom(AbstractSlowEvent.class, subscribeType)) {
INSTANCE.sharePublisher.addSubscriber(consumer, subscribeType); INSTANCE.sharePublisher.addSubscriber(consumer, subscribeType);
} else { } else {
addSubscriber(consumer, subscribeType); addSubscriber(consumer, subscribeType);
@ -65,8 +65,8 @@ public class NotifyCenter {
return; return;
} }
final Class<? extends Event> subscribeType = consumer.subscribeType(); final Class<? extends AbstractEvent> subscribeType = consumer.subscribeType();
if (ClassUtil.isAssignableFrom(SlowEvent.class, subscribeType)) { if (ClassUtil.isAssignableFrom(AbstractSlowEvent.class, subscribeType)) {
INSTANCE.sharePublisher.addSubscriber(consumer, subscribeType); INSTANCE.sharePublisher.addSubscriber(consumer, subscribeType);
return; return;
} }
@ -74,7 +74,7 @@ public class NotifyCenter {
addSubscriber(consumer, subscribeType); addSubscriber(consumer, subscribeType);
} }
private static void addSubscriber(final Subscriber consumer, Class<? extends Event> subscribeType) { private static void addSubscriber(final AbstractSubscriber consumer, Class<? extends AbstractEvent> subscribeType) {
final String topic = ClassUtil.getCanonicalName(subscribeType); final String topic = ClassUtil.getCanonicalName(subscribeType);
synchronized (NotifyCenter.class) { synchronized (NotifyCenter.class) {
MapUtil.computeIfAbsent(INSTANCE.publisherMap, topic, publisherFactory, subscribeType, ringBufferSize); MapUtil.computeIfAbsent(INSTANCE.publisherMap, topic, publisherFactory, subscribeType, ringBufferSize);
@ -83,7 +83,7 @@ public class NotifyCenter {
publisher.addSubscriber(consumer); publisher.addSubscriber(consumer);
} }
public static boolean publishEvent(final Event event) { public static boolean publishEvent(final AbstractEvent event) {
try { try {
return publishEvent(event.getClass(), event); return publishEvent(event.getClass(), event);
} catch (Throwable ex) { } catch (Throwable ex) {
@ -92,8 +92,8 @@ public class NotifyCenter {
} }
} }
private static boolean publishEvent(final Class<? extends Event> eventType, final Event event) { private static boolean publishEvent(final Class<? extends AbstractEvent> eventType, final AbstractEvent event) {
if (ClassUtil.isAssignableFrom(SlowEvent.class, eventType)) { if (ClassUtil.isAssignableFrom(AbstractSlowEvent.class, eventType)) {
return INSTANCE.sharePublisher.publish(event); return INSTANCE.sharePublisher.publish(event);
} }
@ -107,8 +107,8 @@ public class NotifyCenter {
return false; return false;
} }
public static EventPublisher registerToPublisher(final Class<? extends Event> eventType, final int queueMaxSize) { public static EventPublisher registerToPublisher(final Class<? extends AbstractEvent> eventType, final int queueMaxSize) {
if (ClassUtil.isAssignableFrom(SlowEvent.class, eventType)) { if (ClassUtil.isAssignableFrom(AbstractSlowEvent.class, eventType)) {
return INSTANCE.sharePublisher; return INSTANCE.sharePublisher;
} }

@ -1,6 +1,6 @@
package cn.hippo4j.config.notify.listener; package cn.hippo4j.config.notify.listener;
import cn.hippo4j.config.event.Event; import cn.hippo4j.config.event.AbstractEvent;
import java.util.List; import java.util.List;
@ -10,13 +10,13 @@ import java.util.List;
* @author chen.ma * @author chen.ma
* @date 2021/6/23 19:02 * @date 2021/6/23 19:02
*/ */
public abstract class SmartSubscriber extends Subscriber { public abstract class AbstractSmartSubscriber extends AbstractSubscriber {
/** /**
* Subscribe types. * Subscribe types.
* *
* @return * @return
*/ */
public abstract List<Class<? extends Event>> subscribeTypes(); public abstract List<Class<? extends AbstractEvent>> subscribeTypes();
} }

@ -1,6 +1,6 @@
package cn.hippo4j.config.notify.listener; package cn.hippo4j.config.notify.listener;
import cn.hippo4j.config.event.Event; import cn.hippo4j.config.event.AbstractEvent;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
@ -10,7 +10,7 @@ import java.util.concurrent.Executor;
* @author chen.ma * @author chen.ma
* @date 2021/6/23 19:02 * @date 2021/6/23 19:02
*/ */
public abstract class Subscriber<T extends Event> { public abstract class AbstractSubscriber<T extends AbstractEvent> {
/** /**
* Event callback. * Event callback.
@ -24,7 +24,7 @@ public abstract class Subscriber<T extends Event> {
* *
* @return * @return
*/ */
public abstract Class<? extends Event> subscribeType(); public abstract Class<? extends AbstractEvent> subscribeType();
public Executor executor() { public Executor executor() {
return null; return null;

@ -3,10 +3,10 @@ package cn.hippo4j.config.service;
import cn.hippo4j.common.toolkit.JSONUtil; import cn.hippo4j.common.toolkit.JSONUtil;
import cn.hippo4j.common.toolkit.Md5Util; import cn.hippo4j.common.toolkit.Md5Util;
import cn.hippo4j.common.web.base.Results; import cn.hippo4j.common.web.base.Results;
import cn.hippo4j.config.event.Event; import cn.hippo4j.config.event.AbstractEvent;
import cn.hippo4j.config.event.LocalDataChangeEvent; import cn.hippo4j.config.event.LocalDataChangeEvent;
import cn.hippo4j.config.notify.NotifyCenter; import cn.hippo4j.config.notify.NotifyCenter;
import cn.hippo4j.config.notify.listener.Subscriber; import cn.hippo4j.config.notify.listener.AbstractSubscriber;
import cn.hippo4j.config.toolkit.ConfigExecutor; import cn.hippo4j.config.toolkit.ConfigExecutor;
import cn.hippo4j.config.toolkit.MapUtil; import cn.hippo4j.config.toolkit.MapUtil;
import cn.hippo4j.config.toolkit.Md5ConfigUtil; import cn.hippo4j.config.toolkit.Md5ConfigUtil;
@ -58,10 +58,10 @@ public class LongPollingService {
NotifyCenter.registerToPublisher(LocalDataChangeEvent.class, NotifyCenter.ringBufferSize); NotifyCenter.registerToPublisher(LocalDataChangeEvent.class, NotifyCenter.ringBufferSize);
NotifyCenter.registerSubscriber(new Subscriber() { NotifyCenter.registerSubscriber(new AbstractSubscriber() {
@Override @Override
public void onEvent(Event event) { public void onEvent(AbstractEvent event) {
if (isFixedPolling()) { if (isFixedPolling()) {
// Ignore. // Ignore.
} else { } else {
@ -73,7 +73,7 @@ public class LongPollingService {
} }
@Override @Override
public Class<? extends Event> subscribeType() { public Class<? extends AbstractEvent> subscribeType() {
return LocalDataChangeEvent.class; return LocalDataChangeEvent.class;
} }
}); });

@ -2,9 +2,9 @@ package cn.hippo4j.example.config;
import cn.hippo4j.example.inittest.TaskDecoratorTest; import cn.hippo4j.example.inittest.TaskDecoratorTest;
import cn.hippo4j.starter.core.DynamicThreadPool; import cn.hippo4j.starter.core.DynamicThreadPool;
import cn.hippo4j.starter.core.DynamicThreadPoolExecutor; import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;
import cn.hippo4j.starter.toolkit.thread.ThreadPoolBuilder; import cn.hippo4j.core.executor.support.ThreadPoolBuilder;
import cn.hippo4j.starter.wrapper.DynamicThreadPoolWrapper; import cn.hippo4j.core.executor.DynamicThreadPoolWrapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;

@ -1,6 +1,6 @@
package cn.hippo4j.example.handler; package cn.hippo4j.example.handler;
import cn.hippo4j.starter.spi.CustomRejectedExecutionHandler; import cn.hippo4j.core.spi.CustomRejectedExecutionHandler;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;

@ -2,8 +2,8 @@ package cn.hippo4j.example.inittest;
import cn.hippo4j.example.constant.GlobalTestConstant; import cn.hippo4j.example.constant.GlobalTestConstant;
import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.thread.ThreadUtil;
import cn.hippo4j.starter.core.GlobalThreadPoolManage; import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage;
import cn.hippo4j.starter.wrapper.DynamicThreadPoolWrapper; import cn.hippo4j.core.executor.DynamicThreadPoolWrapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;

@ -1,6 +1,6 @@
package cn.hippo4j.example.inittest; package cn.hippo4j.example.inittest;
import cn.hippo4j.starter.wrapper.DynamicThreadPoolWrapper; import cn.hippo4j.core.executor.DynamicThreadPoolWrapper;
import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.thread.ThreadUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;

@ -1,8 +1,8 @@
package cn.hippo4j.example.inittest; package cn.hippo4j.example.inittest;
import cn.hippo4j.example.constant.GlobalTestConstant; import cn.hippo4j.example.constant.GlobalTestConstant;
import cn.hippo4j.starter.core.GlobalThreadPoolManage; import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage;
import cn.hippo4j.starter.wrapper.DynamicThreadPoolWrapper; import cn.hippo4j.core.executor.DynamicThreadPoolWrapper;
import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.thread.ThreadUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC; import org.slf4j.MDC;
@ -25,8 +25,8 @@ public class TaskDecoratorTest {
/** /**
* 线 {@link TaskDecorator} * 线 {@link TaskDecorator}
* , @PostConstruct
*/ */
// @PostConstruct
public void taskDecoratorTest() { public void taskDecoratorTest() {
new Thread(() -> { new Thread(() -> {
MDC.put(PLACEHOLDER, "查看官网: https://www.hippox.cn"); MDC.put(PLACEHOLDER, "查看官网: https://www.hippox.cn");

Loading…
Cancel
Save