diff --git a/src/main/java/com/ishland/flowsched/scheduler/TicketSet.java b/src/main/java/com/ishland/flowsched/scheduler/TicketSet.java index 36dfbbf..f4117d8 100644 --- a/src/main/java/com/ishland/flowsched/scheduler/TicketSet.java +++ b/src/main/java/com/ishland/flowsched/scheduler/TicketSet.java @@ -11,11 +11,11 @@ public class TicketSet { private final ItemStatus initialStatus; private final Set>[] status2Tickets; -// private volatile int targetStatus = 0; + private volatile int targetStatus = 0; public TicketSet(ItemStatus initialStatus, ObjectFactory objectFactory) { this.initialStatus = initialStatus; -// this.targetStatus = initialStatus.ordinal(); + this.targetStatus = initialStatus.ordinal(); ItemStatus[] allStatuses = initialStatus.getAllStatuses(); this.status2Tickets = new Set[allStatuses.length]; for (int i = 0; i < allStatuses.length; i++) { @@ -29,6 +29,8 @@ public boolean add(ItemTicket ticket) { final boolean added = this.status2Tickets[targetStatus.ordinal()].add(ticket); if (!added) return false; + this.targetStatus = this.computeTargetStatusSlow(); + // if (this.targetStatus < targetStatus.ordinal()) { // this.targetStatus = targetStatus.ordinal(); // } @@ -41,6 +43,8 @@ public boolean remove(ItemTicket ticket) { final boolean removed = this.status2Tickets[targetStatus.ordinal()].remove(ticket); if (!removed) return false; + this.targetStatus = this.computeTargetStatusSlow(); + // decreaseStatusAtomically(); return true; @@ -65,7 +69,7 @@ public boolean remove(ItemTicket ticket) { // } public ItemStatus getTargetStatus() { - return this.initialStatus.getAllStatuses()[this.computeTargetStatusSlow()]; + return this.initialStatus.getAllStatuses()[this.targetStatus]; } public Set> getTicketsForStatus(ItemStatus status) {