@Override public String toString() { Map<String, Object> m = new ListOrderedMap<String, Object>(); m.put("Scale Factor", this.scale_factor); m.put("Loader Start", this.loaderStartTime); m.put("Loader Stop", this.loaderStopTime); m.put( "Last CloseAuctions", (this.lastCloseAuctionsTime.getTime() > 0 ? this.lastCloseAuctionsTime : null)); m.put("Client Start", this.clientStartTime); m.put("Current Virtual Time", this.currentTime); m.put("Pending ItemCommentResponses", this.pending_commentResponses.size()); // Item Queues Histogram<ItemStatus> itemCounts = new Histogram<ItemStatus>(true); for (ItemStatus status : ItemStatus.values()) { int cnt = 0; switch (status) { case OPEN: cnt = this.items_available.size(); break; case ENDING_SOON: cnt = this.items_endingSoon.size(); break; case WAITING_FOR_PURCHASE: cnt = this.items_waitingForPurchase.size(); break; case CLOSED: cnt = this.items_completed.size(); break; default: assert (false) : "Unexpected " + status; } // SWITCH itemCounts.put(status, cnt); } m.put("Item Queues", itemCounts); return (StringUtil.formatMaps(m)); }
private ItemStatus addItemToProperQueue(ItemInfo itemInfo, Timestamp baseTime) { // Always check whether we even want it for this client // The loader's profile and the cache profile will always have a negative client_id, // which means that we always want to keep it if (this.client_id != -1) { if (this.userIdGenerator == null) this.initializeUserIdGenerator(this.client_id); if (this.userIdGenerator.checkClient(itemInfo.getSellerId()) == false) { return (null); } } long remaining = itemInfo.endDate.getTime() - baseTime.getTime(); ItemStatus new_status = (itemInfo.status != null ? itemInfo.status : ItemStatus.OPEN); // Already ended if (remaining <= AuctionMarkConstants.ITEM_ALREADY_ENDED) { if (itemInfo.numBids > 0 && itemInfo.status != ItemStatus.CLOSED) { new_status = ItemStatus.WAITING_FOR_PURCHASE; } else { new_status = ItemStatus.CLOSED; } } // About to end soon else if (remaining < AuctionMarkConstants.ITEM_ENDING_SOON) { new_status = ItemStatus.ENDING_SOON; } if (new_status != itemInfo.status) { if (itemInfo.status != null) assert (new_status.ordinal() > itemInfo.status.ordinal()) : "Trying to improperly move " + itemInfo + " from " + itemInfo.status + " to " + new_status; switch (new_status) { case OPEN: this.addItem(this.items_available, itemInfo); break; case ENDING_SOON: this.items_available.remove(itemInfo); this.addItem(this.items_endingSoon, itemInfo); break; case WAITING_FOR_PURCHASE: (itemInfo.status == ItemStatus.OPEN ? this.items_available : this.items_endingSoon) .remove(itemInfo); this.addItem(this.items_waitingForPurchase, itemInfo); break; case CLOSED: if (itemInfo.status == ItemStatus.OPEN) this.items_available.remove(itemInfo); else if (itemInfo.status == ItemStatus.ENDING_SOON) this.items_endingSoon.remove(itemInfo); else this.items_waitingForPurchase.remove(itemInfo); this.addItem(this.items_completed, itemInfo); break; default: } // SWITCH itemInfo.status = new_status; } if (LOG.isTraceEnabled()) LOG.trace( String.format( "%s - #%d [%s]", new_status, itemInfo.itemId.encode(), itemInfo.getEndDate())); return (new_status); }