Skip to content
This repository has been archived by the owner on Jul 27, 2018. It is now read-only.

Commit

Permalink
JAV-336 simplified events
Browse files Browse the repository at this point in the history
  • Loading branch information
seanyinx committed Sep 5, 2017
1 parent 4ef6d72 commit c41550b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,19 @@

public class CouponGrabbedEvent<T> extends SecKillEvent {

protected CouponEntity<T> coupon;
private final CouponEntity<T> coupon;

public CouponGrabbedEvent() {
super();
this.type = CouponGrabbedEvent.class.getSimpleName();
}

public CouponGrabbedEvent(Format format, String content) {
this();
coupon = format.deserialize(content, CouponEntity.class);
this.promotionId = coupon.getPromotionId();
public CouponGrabbedEvent(CouponEntity<T> coupon) {
super(coupon.getPromotionId(), CouponGrabbedEvent.class.getSimpleName());
this.coupon = coupon;
}

public CouponGrabbedEvent(PromotionEntity promotion, T customerId) {
this();
this.promotionId = promotion.getPromotionId();
this.coupon = new CouponEntity<>(promotion.getPromotionId(), System.currentTimeMillis(), promotion.getDiscount(),
customerId);
this(new CouponEntity<>(
promotion.getPromotionId(),
System.currentTimeMillis(),
promotion.getDiscount(),
customerId));
}

public CouponEntity<T> getCoupon() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,10 @@

public class PromotionFinishEvent extends SecKillEvent {

protected PromotionEntity promotion;

public PromotionFinishEvent() {
super();
this.type = PromotionFinishEvent.class.getSimpleName();
}

public PromotionFinishEvent(Format format, String content) {
this();
promotion = format.deserialize(content, PromotionEntity.class);
this.promotionId = promotion.getPromotionId();
}
private final PromotionEntity promotion;

public PromotionFinishEvent(PromotionEntity promotion) {
this();
this.promotionId = promotion.getPromotionId();
super(promotion.getPromotionId(), PromotionFinishEvent.class.getSimpleName());
this.promotion = promotion;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,17 @@

public class PromotionStartEvent extends SecKillEvent {

protected PromotionEntity promotion;

public PromotionEntity getPromotion() {
return promotion;
}

public PromotionStartEvent() {
super();
this.type = PromotionStartEvent.class.getSimpleName();
}

public PromotionStartEvent(Format format, String content){
this();
promotion = format.deserialize(content, PromotionEntity.class);
this.promotionId = promotion.getPromotionId();
}
private final PromotionEntity promotion;

public PromotionStartEvent(PromotionEntity promotion) {
this();
this.promotionId = promotion.getPromotionId();
super(promotion.getPromotionId(), PromotionStartEvent.class.getSimpleName());
this.promotion = promotion;
}

public PromotionEntity getPromotion() {
return promotion;
}

@Override
public String getContent(Format format) {
return format.serialize(promotion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@

public abstract class SecKillEvent {

protected String promotionId;
protected String type;
private final String promotionId;
private final String type;

public SecKillEvent(String promotionId, String type) {
this.promotionId = promotionId;
this.type = type;
}

public String getPromotionId() {
return promotionId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

import io.servicecomb.poc.demo.seckill.Format;
import io.servicecomb.poc.demo.seckill.dto.EventMessageDto;
import io.servicecomb.poc.demo.seckill.entities.CouponEntity;
import io.servicecomb.poc.demo.seckill.entities.EventEntity;
import io.servicecomb.poc.demo.seckill.entities.PromotionEntity;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
Expand Down Expand Up @@ -63,14 +65,14 @@ private SecKillEvent generateEvent(String type, String content) {
}

private SecKillEvent couponGrabbedEvent(String content) {
return new CouponGrabbedEvent(format, content);
return new CouponGrabbedEvent<>(format.deserialize(content, CouponEntity.class));
}

private SecKillEvent promotionStartEvent(String content) {
return new PromotionStartEvent(format, content);
return new PromotionStartEvent(format.deserialize(content, PromotionEntity.class));
}

private SecKillEvent promotionFinishEvent(String content) {
return new PromotionFinishEvent(format, content);
return new PromotionFinishEvent(format.deserialize(content, PromotionEntity.class));
}
}

0 comments on commit c41550b

Please sign in to comment.