mirror of https://github.com/halo-dev/halo
Deprecate event queue publisher and listener manager
parent
6b46e8a897
commit
8e64b9acd6
|
@ -3,7 +3,6 @@ package run.halo.app.event;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.context.ApplicationEvent;
|
import org.springframework.context.ApplicationEvent;
|
||||||
import org.springframework.context.ApplicationListener;
|
import org.springframework.context.ApplicationListener;
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import javax.annotation.PreDestroy;
|
import javax.annotation.PreDestroy;
|
||||||
import java.util.EventListener;
|
import java.util.EventListener;
|
||||||
|
@ -20,7 +19,7 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||||
* @date 19-4-20
|
* @date 19-4-20
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Deprecated
|
||||||
public class ApplicationEventQueuePublisher {
|
public class ApplicationEventQueuePublisher {
|
||||||
|
|
||||||
private final BlockingQueue<Object> events = new LinkedBlockingQueue<>();
|
private final BlockingQueue<Object> events = new LinkedBlockingQueue<>();
|
||||||
|
|
|
@ -6,7 +6,6 @@ import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationListener;
|
import org.springframework.context.ApplicationListener;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import run.halo.app.utils.ReflectionUtils;
|
import run.halo.app.utils.ReflectionUtils;
|
||||||
|
|
||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
|
@ -21,7 +20,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
* @date 19-4-21
|
* @date 19-4-21
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Deprecated
|
||||||
public class ApplicationListenerManager {
|
public class ApplicationListenerManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package run.halo.app.event;
|
package run.halo.app.event;
|
||||||
|
|
||||||
import org.springframework.context.ApplicationListener;
|
import org.springframework.context.event.EventListener;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import run.halo.app.model.entity.Log;
|
import run.halo.app.model.entity.Log;
|
||||||
import run.halo.app.service.LogService;
|
import run.halo.app.service.LogService;
|
||||||
|
@ -12,7 +13,7 @@ import run.halo.app.service.LogService;
|
||||||
* @date 19-4-21
|
* @date 19-4-21
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class LogEventListener implements ApplicationListener<LogEvent> {
|
public class LogEventListener {
|
||||||
|
|
||||||
private final LogService logService;
|
private final LogService logService;
|
||||||
|
|
||||||
|
@ -20,7 +21,8 @@ public class LogEventListener implements ApplicationListener<LogEvent> {
|
||||||
this.logService = logService;
|
this.logService = logService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@EventListener
|
||||||
|
@Async
|
||||||
public void onApplicationEvent(LogEvent event) {
|
public void onApplicationEvent(LogEvent event) {
|
||||||
// Convert to log
|
// Convert to log
|
||||||
Log logToCreate = event.getLogParam().convertTo();
|
Log logToCreate = event.getLogParam().convertTo();
|
||||||
|
|
|
@ -2,6 +2,7 @@ package run.halo.app.service.impl;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
|
@ -13,7 +14,6 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import run.halo.app.event.ApplicationEventQueuePublisher;
|
|
||||||
import run.halo.app.event.LogEvent;
|
import run.halo.app.event.LogEvent;
|
||||||
import run.halo.app.exception.AlreadyExistsException;
|
import run.halo.app.exception.AlreadyExistsException;
|
||||||
import run.halo.app.exception.NotFoundException;
|
import run.halo.app.exception.NotFoundException;
|
||||||
|
@ -69,7 +69,7 @@ public class PostServiceImpl extends AbstractCrudService<Post, Integer> implemen
|
||||||
|
|
||||||
private final CommentService commentService;
|
private final CommentService commentService;
|
||||||
|
|
||||||
private final ApplicationEventQueuePublisher eventQueuePublisher;
|
private final ApplicationEventPublisher eventPublisher;
|
||||||
|
|
||||||
public PostServiceImpl(PostRepository postRepository,
|
public PostServiceImpl(PostRepository postRepository,
|
||||||
TagService tagService,
|
TagService tagService,
|
||||||
|
@ -77,7 +77,7 @@ public class PostServiceImpl extends AbstractCrudService<Post, Integer> implemen
|
||||||
PostTagService postTagService,
|
PostTagService postTagService,
|
||||||
PostCategoryService postCategoryService,
|
PostCategoryService postCategoryService,
|
||||||
CommentService commentService,
|
CommentService commentService,
|
||||||
ApplicationEventQueuePublisher eventQueuePublisher) {
|
ApplicationEventPublisher eventPublisher) {
|
||||||
super(postRepository);
|
super(postRepository);
|
||||||
this.postRepository = postRepository;
|
this.postRepository = postRepository;
|
||||||
this.tagService = tagService;
|
this.tagService = tagService;
|
||||||
|
@ -85,7 +85,7 @@ public class PostServiceImpl extends AbstractCrudService<Post, Integer> implemen
|
||||||
this.postTagService = postTagService;
|
this.postTagService = postTagService;
|
||||||
this.postCategoryService = postCategoryService;
|
this.postCategoryService = postCategoryService;
|
||||||
this.commentService = commentService;
|
this.commentService = commentService;
|
||||||
this.eventQueuePublisher = eventQueuePublisher;
|
this.eventPublisher = eventPublisher;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -227,7 +227,7 @@ public class PostServiceImpl extends AbstractCrudService<Post, Integer> implemen
|
||||||
|
|
||||||
// Log the creation
|
// Log the creation
|
||||||
LogEvent logEvent = new LogEvent(this, createdPost.getId().toString(), LogType.POST_PUBLISHED, createdPost.getTitle());
|
LogEvent logEvent = new LogEvent(this, createdPost.getId().toString(), LogType.POST_PUBLISHED, createdPost.getTitle());
|
||||||
eventQueuePublisher.publishEvent(logEvent);
|
eventPublisher.publishEvent(logEvent);
|
||||||
|
|
||||||
return createdPost;
|
return createdPost;
|
||||||
}
|
}
|
||||||
|
@ -238,7 +238,7 @@ public class PostServiceImpl extends AbstractCrudService<Post, Integer> implemen
|
||||||
|
|
||||||
// Log the creation
|
// Log the creation
|
||||||
LogEvent logEvent = new LogEvent(this, updatedPost.getId().toString(), LogType.POST_EDITED, updatedPost.getTitle());
|
LogEvent logEvent = new LogEvent(this, updatedPost.getId().toString(), LogType.POST_EDITED, updatedPost.getTitle());
|
||||||
eventQueuePublisher.publishEvent(logEvent);
|
eventPublisher.publishEvent(logEvent);
|
||||||
|
|
||||||
return updatedPost;
|
return updatedPost;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue