Package edu.csusm.cs671.auction.agent

Examples of edu.csusm.cs671.auction.agent.AuctionAgent


    if (message.getAuctionMessage() instanceof StartAuctionMessage) {
      StartAuctionMessage startAuctionMessage = (StartAuctionMessage) message.getAuctionMessage();
      BidAuctionMessage bidAuctionMessage = generateBid(startAuctionMessage);
      sendAuctionMessage(bidAuctionMessage);
    }else if (message.getAuctionMessage() instanceof WinnerAuctionMessage) {
      WinnerAuctionMessage wonAuctionMessage = (WinnerAuctionMessage) message.getAuctionMessage();
      addWonWork(wonAuctionMessage);
    }
  }
View Full Code Here


    }
  }

  @Override
  public void addTask(Work w) {
    AuctionDetail auctionDetail = new AuctionDetail(w.getWorkType(), w.getSize());
    auctionQueue.add(auctionDetail);
    startAuction();
  }
View Full Code Here

    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)
        {
View Full Code Here

    AuctionAgent auctionAgent = new AuctionAgentImpl(agentConfig);
    auctionAgent.start();
   
    StartAuctionMessage auctionMessage = new StartAuctionMessage();
   
    Work work = new Work(WorkType.TYPE_A,new Size(10000) );
   
    auctionMessage.setAuctionID(UUID.randomUUID());
    //auctionMessage.setTimeAuctionIsOpen(new Duration(10));
    auctionMessage.setWorkForAuction(work);
   
View Full Code Here

    AuctionAgent auctionAgent = new AuctionAgentImpl(agentConfig);
    auctionAgent.start();
   
    WinnerAuctionMessage auctionMessage = new WinnerAuctionMessage();
   
    Work work = new Work(WorkType.TYPE_A,new Size(10000) );
   
    auctionMessage.setAuctionID(UUID.randomUUID());
    auctionMessage.setWorkForAuction(work);
//    auction Message.setBidAmount(new Currency(100));
    auctionMessage.setAgentID(1);
View Full Code Here

        break;
      }
    }

    private void processWork(Work work, int burnRate, WorkPreferenceType preference) {
      Size size = work.getSize();
     
      if(size.getValue() <= 0){
        workQueue.poll(); //work is done pop it off the work queue
        printString("   Work is done!");
      }else{
        int newSize = size.getValue() - burnRate;
        size.setValue(newSize);
        printString("   Current work size = " + (newSize>0? newSize:0)+ "  Type = " + work.getStringWorkType() + "  Preference = " + workPreferenceTypeToString(preference));

      }
    }
View Full Code Here

    AuctionAgent auctionAgent = new AuctionAgentImpl(agentConfig);
    auctionAgent.start();
   
    StartAuctionMessage auctionMessage = new StartAuctionMessage();
   
    Work work = new Work(WorkType.TYPE_A,new Size(10000) );
   
    auctionMessage.setAuctionID(UUID.randomUUID());
    //auctionMessage.setTimeAuctionIsOpen(new Duration(10));
    auctionMessage.setWorkForAuction(work);
   
View Full Code Here

    AuctionAgent auctionAgent = new AuctionAgentImpl(agentConfig);
    auctionAgent.start();
   
    WinnerAuctionMessage auctionMessage = new WinnerAuctionMessage();
   
    Work work = new Work(WorkType.TYPE_A,new Size(10000) );
   
    auctionMessage.setAuctionID(UUID.randomUUID());
    auctionMessage.setWorkForAuction(work);
//    auction Message.setBidAmount(new Currency(100));
    auctionMessage.setAgentID(1);
View Full Code Here

//   
//    int size = workQueue.size();
//    bid -= size;
   
    //subtract work preference
    Work work = auctionMessage.getWorkForAuction();
   
    if(work == null){
      throw new IllegalArgumentException("Work was null!!!");
    }
   
View Full Code Here

  **/
  private class WorkTimerTask extends TimerTask{
 
    public void run(){
     
      Work work = workQueue.peek();
     
      if(work == null) return; //No work to process
     
      printString("Current work queue size = " + workQueue.size());
      WorkPreferenceType preference = config.getWorkPreference(work.getWorkType());
       
      switch (preference) {
      case FIRST:
        processWork(work, FIRST_PREFERENCE_BURN_RATE, preference);
        break;
View Full Code Here

TOP

Related Classes of edu.csusm.cs671.auction.agent.AuctionAgent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.