while(!auctionQueue.isEmpty())
{
if(isRunning)
{
StartAuctionMessage msg = new StartAuctionMessage();
AuctionDetail auctionDetail = auctionQueue.poll();
if(auctionDetail == null){
continue;
}
msg.setWorkForAuction(auctionDetail.getWorkDetail());
msg.setAuctionID(auctionDetail.getID());
bidderList.clear();
listenning = true;
server.writeToAll(msg);
int delay = 1000;
try {
Thread.sleep(delay);
} catch (InterruptedException e1) {
}
//decide who win
BidAuctionMessage highestBidder;
highestBidder = getHighestBidder();
if(highestBidder == null)
{
listenning = false;
continue;
}
// while((highestBidder = getHighestBidder())==null)
// {
// server.writeToAll(msg);
// }
try{
System.out.println("Winner:Agent_"+highestBidder.getAgentID() + " AuctionID = " + msg.getAuctionID());
System.out.println(" Work size: "+ msg.getWorkForAuction().getSize().getValue() + " Work type: " + msg.getWorkForAuction().getWorkType());
WinnerAuctionMessage winnerAuctionMessage = new WinnerAuctionMessage();
winnerAuctionMessage.setAgentID(highestBidder.getAgentID());
winnerAuctionMessage.setBidAmount(highestBidder.getBidAmount());
winnerAuctionMessage.setWorkForAuction(msg.getWorkForAuction());
server.writeToAgent(winnerAuctionMessage, highestBidder.getAgentID());
//update history
auctionDetail.setWinner("agent_"+highestBidder.getAgentID());
auctionDetail.setWinningPrice(highestBidder.getBidAmount());
auctionHistory.add(auctionDetail);
}
catch(Exception e)
{