简单的异步框架实现
枚举事件类型
public enum EventType {
LIKE(0),
COMMENT(1),
LOGIN(2),
MAIL(3);
private int value;
EventType(int value) { this.value = value; }
public int getValue() { return value; }
}
定义事件模型
public class EventModel {
private EventType type; //事件类型
private int actorId; //执行者ID
private int entityType;
private int entityId;
private int entityOwnerId;
private Map<String, String> exts = new HashMap<String, String>(); //额外内容
public EventModel() {
}
public EventModel setExt(String key, String value) {
exts.put(key, value);
return this;
}
public EventModel(EventType type) {
this.type = type;
}
public String getExt(String key) {
return exts.get(key);
}
public EventType getType() {
return type;
}
public EventModel setType(EventType type) {
this.type = type;
return this;
}
public int getActorId() {
return actorId;
}
public EventModel setActorId(int actorId) {
this.actorId = actorId;
return this;
}
public int getEntityType() {
return entityType;
}
public EventModel setEntityType(int entityType) {
this.entityType = entityType;
return this;
}
public int getEntityId() {
return entityId;
}
public EventModel setEntityId(int entityId) {
this.entityId = entityId;
return this;
}
public int getEntityOwnerId() {
return entityOwnerId;
}
public EventModel setEntityOwnerId(int entityOwnerId) {
this.entityOwnerId = entityOwnerId;
return this;
}
public Map<String, String> getExts() {
return exts;
}
public EventModel setExts(Map<String, String> exts) {
this.exts = exts;
return this;
}
}
事件生产者
@Service
public class EventProducer {
@Autowired
JedisAdapter jedisAdapter;
public boolean fireEvent(EventModel