REQ-3502: 去除无用逻辑
This commit is contained in:
parent
59f097249b
commit
f037117c3a
@ -17,7 +17,6 @@ import cn.axzo.msg.center.message.domain.vo.GeneralMessagePushVO;
|
||||
import cn.axzo.msg.center.message.service.card.broadcast.CardBroadcaster;
|
||||
import cn.axzo.msg.center.message.service.card.domain.CardGroup;
|
||||
import cn.axzo.msg.center.message.service.card.domain.CardSendModel;
|
||||
import cn.axzo.msg.center.message.service.card.event.CardUpdateEvent;
|
||||
import cn.axzo.msg.center.message.service.card.log.CardLogger;
|
||||
import cn.axzo.msg.center.message.service.card.log.CardLoggers;
|
||||
import cn.axzo.msg.center.message.service.replay.RequestInfo;
|
||||
@ -44,10 +43,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -76,7 +72,6 @@ public class CardManager {
|
||||
private final CardBroadcaster cardBroadcaster;
|
||||
private final CardProps cardProps;
|
||||
private final RequestReplayService requestReplayService;
|
||||
private final ApplicationContext applicationContext;
|
||||
private final ExecutorService executor = new ThreadPoolExecutor(
|
||||
5, 15,
|
||||
5L, TimeUnit.MINUTES,
|
||||
@ -325,13 +320,6 @@ public class CardManager {
|
||||
updateCardLogger.reloadAndLogCards(String.format("%s:enqueue", operation));
|
||||
CardManager.this.updateMessages(updatedCards);
|
||||
updateCardLogger.reloadAndLogCards(String.format("%s:updateMessage:success", operation));
|
||||
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
|
||||
@Override
|
||||
public void afterCommit() {
|
||||
for (Card card : cardDao.reloadCards(cards))
|
||||
applicationContext.publishEvent(new CardUpdateEvent(requestContext.getRequest(), card));
|
||||
}
|
||||
});
|
||||
return UpdateStateResult.UPDATED;
|
||||
});
|
||||
} catch (Exception e) {
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
package cn.axzo.msg.center.message.service.card.event;
|
||||
|
||||
import cn.axzo.msg.center.domain.entity.Card;
|
||||
import lombok.Getter;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* @author yanglin
|
||||
*/
|
||||
@Getter
|
||||
public class CardUpdateEvent extends ApplicationEvent {
|
||||
|
||||
private final Card reloadedCard;
|
||||
|
||||
public CardUpdateEvent(Object source, Card reloadedCard) {
|
||||
super(source);
|
||||
this.reloadedCard = reloadedCard;
|
||||
}
|
||||
|
||||
}
|
||||
@ -11,7 +11,6 @@ import cn.axzo.msg.center.domain.entity.Todo;
|
||||
import cn.axzo.msg.center.domain.entity.TodoBusiness;
|
||||
import cn.axzo.msg.center.message.service.card.CardExtInfo;
|
||||
import cn.axzo.msg.center.message.service.card.CardManager;
|
||||
import cn.axzo.msg.center.message.service.card.event.CardUpdateEvent;
|
||||
import cn.axzo.msg.center.message.service.card.exception.CardIdempotentException;
|
||||
import cn.axzo.msg.center.message.service.todo.manage.TodoLogger;
|
||||
import cn.axzo.msg.center.message.service.todo.manage.TodoManager;
|
||||
@ -28,21 +27,15 @@ import cn.axzo.msg.center.service.pending.request.CardUpdateStateRequest;
|
||||
import cn.axzo.msg.center.service.pending.request.PresetButtonPressedRequest;
|
||||
import cn.axzo.msg.center.service.pending.response.CardSendResponse;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.collect.Sets;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author yanglin
|
||||
@ -50,7 +43,7 @@ import java.util.concurrent.TimeUnit;
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class TodoSyncCardService implements ApplicationListener<CardUpdateEvent> {
|
||||
public class TodoSyncCardService {
|
||||
|
||||
private static final ThreadLocal<TodoUpdateMessage> TODO_MESSAGE = new ThreadLocal<>();
|
||||
|
||||
@ -68,19 +61,6 @@ public class TodoSyncCardService implements ApplicationListener<CardUpdateEvent>
|
||||
private final MessageTemplateV3Dao messageTemplateV3Dao;
|
||||
private final TodoManager todoManager;
|
||||
|
||||
private final long cacheSize = 1000;
|
||||
private final long cacheExpireSeconds = 10;
|
||||
private final Cache<String, Object> locks = CacheBuilder
|
||||
.newBuilder()
|
||||
.maximumSize(cacheSize)
|
||||
.expireAfterAccess(cacheExpireSeconds, TimeUnit.SECONDS)
|
||||
.build();
|
||||
private final Cache<Long, TodoCardState> todoStates = CacheBuilder
|
||||
.newBuilder()
|
||||
.maximumSize(cacheSize)
|
||||
.expireAfterAccess(cacheExpireSeconds, TimeUnit.SECONDS)
|
||||
.build();
|
||||
|
||||
void onMessage(Event event, TodoUpdateMessage message) {
|
||||
log.info("received TodoUpdateMessage: {}", message);
|
||||
try {
|
||||
@ -129,7 +109,7 @@ public class TodoSyncCardService implements ApplicationListener<CardUpdateEvent>
|
||||
|| todo.getState() == PendingMessageStateEnum.CREATED)
|
||||
sendCard(event, business, todo);
|
||||
else
|
||||
updateCardState(event, message, business, todo);
|
||||
updateCardState(event, business, todo);
|
||||
}
|
||||
|
||||
private void sendCard(Event event, TodoBusiness business, Todo todo) {
|
||||
@ -173,18 +153,7 @@ public class TodoSyncCardService implements ApplicationListener<CardUpdateEvent>
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCardState(Event event, TodoUpdateMessage message, TodoBusiness business, Todo todo) {
|
||||
//synchronized (getLock(todo)) {
|
||||
// TodoCardState lastState = todoStates.getIfPresent(todo.getId());
|
||||
// if (lastState != null && lastState.equals(TodoCardState.create(business, todo))) {
|
||||
// log.info("updateCardState: no change, todo={}", todo);
|
||||
// TodoRequestContext ctx = TodoRequestContext.create("updateCardState:ignore", message)
|
||||
// .addLogContent("todoState", lastState);
|
||||
// todoLogger.logTodoUpdated(ctx, todo);
|
||||
// return;
|
||||
// }
|
||||
//}
|
||||
|
||||
private void updateCardState(Event event, TodoBusiness business, Todo todo) {
|
||||
TodoCardUpdateStateRequest request = new TodoCardUpdateStateRequest();
|
||||
request.setTodo(todo);
|
||||
request.setTodoBusiness(business);
|
||||
@ -289,30 +258,6 @@ public class TodoSyncCardService implements ApplicationListener<CardUpdateEvent>
|
||||
return Optional.ofNullable(identityCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(CardUpdateEvent event) {
|
||||
if (!(event.getSource() instanceof TodoCardUpdateStateRequest))
|
||||
return;
|
||||
Todo todo = ((TodoCardUpdateStateRequest) event.getSource()).getTodo();
|
||||
TodoBusiness business = todoBusinessDao.getBusinesses(todo).findBusiness(todo).orElse(null);
|
||||
if (business == null) return;
|
||||
synchronized (getLock(todo)) {
|
||||
TodoCardState state = TodoCardState.create(business, todo);
|
||||
if (state.isTodoCompleted)
|
||||
todoStates.put(todo.getId(), state);
|
||||
}
|
||||
}
|
||||
|
||||
private Object getLock(Todo todo) {
|
||||
String identityCode = todo.getIdentityCode();
|
||||
try {
|
||||
return locks.get(identityCode, () -> identityCode);
|
||||
} catch (ExecutionException e) {
|
||||
log.warn("getTodoLock error, todoIdentityCode={}", identityCode, e);
|
||||
throw new RuntimeException("Should never happen!");
|
||||
}
|
||||
}
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
private static class TodoCardUpdateStateRequest extends CardUpdateStateRequest {
|
||||
@ -320,17 +265,4 @@ public class TodoSyncCardService implements ApplicationListener<CardUpdateEvent>
|
||||
private Todo todo;
|
||||
}
|
||||
|
||||
@EqualsAndHashCode
|
||||
@RequiredArgsConstructor
|
||||
private static class TodoCardState {
|
||||
private final boolean isTodoCompleted;
|
||||
private final BizFinalStateEnum bizFinalState;
|
||||
|
||||
static TodoCardState create(TodoBusiness business, Todo todo) {
|
||||
return new TodoCardState(
|
||||
todo.getState() == PendingMessageStateEnum.COMPLETED,
|
||||
business.getBizFinalState());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user