Package edu.csusm.cs671.auction.agent

Examples of edu.csusm.cs671.auction.agent.AuctionAgentImpl$WorkTimerTask


   
  public static void main(String[] args) throws IOException {

    AuctioneerConfig auctioneerConfig = new AuctioneerConfig();
    auctioneerConfig.setPort(PORT);
    auctioneer = new AuctioneerImpl(auctioneerConfig);
    String cmd;
    Scanner scan = new Scanner(System.in);
    Timer timer = null;
    workTimerTask = null;
View Full Code Here


    synchronized (listeners) {
      tmp = new ArrayList<AuctionMessageListener>();
      tmp.addAll(listeners);
    }
    final ServerSocketWorker source = this;
    final AuctionMessage data = message;
   
    for (final AuctionMessageListener socketClientTextListener : tmp) {
      threadPool.execute(new Runnable() {
        public void run() {
          socketClientTextListener.onMessageReceived(new MessageEvent(source, data));
View Full Code Here

    synchronized (listeners) {
      tmp = new ArrayList<AuctionMessageListener>();
      tmp.addAll(listeners);
    }
    final SocketClient source = this;
    final AuctionMessage data = message;
   
    for (final AuctionMessageListener socketClientTextListener : tmp) {
      threadPool.execute(new Runnable() {
        public void run() {
          socketClientTextListener.onMessageReceived(new MessageEvent(source, data));
View Full Code Here

  @Override
  public void onMessageReceived(MessageEvent message) {
   
    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

   * @return
   * @throws IllegalArgumentException if work is null
   */
  private BidAuctionMessage generateBid(StartAuctionMessage auctionMessage){
   
    BidAuctionMessage bidAuctionMessage = new BidAuctionMessage();
    bidAuctionMessage.setAgentID(this.config.getId());
   
   
//    int bid = MAX_BID;
//   
//    //subtract work preference
//    Work work = auctionMessage.getWorkForAuction();
//   
//    if(work == null){
//      throw new IllegalArgumentException("Work was null!!!");
//     
//    }
//   
//    bid = subtractWorkPenaltyFromBid(bid, work);
//   
//    int size = workQueue.size();
//    bid -= size;
   
    //subtract work preference
    Work work = auctionMessage.getWorkForAuction();
   
    if(work == null){
      throw new IllegalArgumentException("Work was null!!!");
    }
   
    long bid = calulateBid(work);
   
   
//    Currency currency = new Currency(bid);
    bidAuctionMessage.setBidAmount(bid);
   
    printString("Agent ID: " + config.getId() +" AuctionID = "+ auctionMessage.getAuctionID() + " Bid = " + bid);
   
    return bidAuctionMessage;
  }
View Full Code Here

      while ((object = in.readObject()) != null) {
//        System.out.println("Read from client: "
//            + object.getClass().getCanonicalName());
       
        if (object instanceof JoinAuctionMessage) {
          JoinAuctionMessage join = (JoinAuctionMessage) object;
          this.id = join.getAgentID();
         
        }else if (object instanceof AuctionMessage) {
          fireTextEvent((AuctionMessage) object);
        }else{
          System.out.println("Message was not an AuctionMessage");
View Full Code Here

           
            clientSocket = new Socket(host, port);
            out = new ObjectOutputStream(clientSocket.getOutputStream());
            in = new ObjectInputStream(clientSocket.getInputStream());
         
            JoinAuctionMessage joinAuctionMessage = new JoinAuctionMessage();
            joinAuctionMessage.setAgentID(id);
            writeMessage(joinAuctionMessage);
           
          } catch (UnknownHostException e) {
            System.err.println("Don't know about host: localhost");
          } catch (IOException e) {
View Full Code Here

   
    AgentConfig agentConfig = AgentConfigBuilder.buildAgentConfig("agentConfig_1.properties");
    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);
   
   
    MessageEvent messageEvent = new MessageEvent(auctionAgent, auctionMessage);
    auctionAgent.onMessageReceived(messageEvent);
   
View Full Code Here

 
  @Override
  public void onMessageReceived(MessageEvent message) {
   
    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

   
    AgentConfig agentConfig = AgentConfigBuilder.buildAgentConfig("agentConfig_1.properties");
    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);
   
    MessageEvent messageEvent = new MessageEvent(auctionAgent, auctionMessage);
    auctionAgent.onMessageReceived(messageEvent);
   
   
View Full Code Here

TOP

Related Classes of edu.csusm.cs671.auction.agent.AuctionAgentImpl$WorkTimerTask

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.