daily pastebin goal
60%
SHARE
TWEET

Untitled

a guest Dec 7th, 2017 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package FairSmokers;
  2.  
  3. import java.util.Random;
  4. import java.util.concurrent.ThreadLocalRandom;
  5.  
  6. import Smokers.GlobalState;
  7. import se.his.iit.it325g.common.AndrewsProcess;
  8.  
  9. public class Agent implements Runnable {
  10.     private int tobacco = 0;
  11.     private int paper = 0;
  12.     private int matches = 0;
  13.     private int request = 0;
  14.  
  15.    
  16.     @Override
  17.     public void run() {
  18.         while (true) {
  19.             request = GlobalState.Ach4.receive();
  20.            
  21.             if(request == 0)
  22.             {
  23.                 //Gets paper and matches, send to tobacco
  24.                 paper++;
  25.                 matches++;
  26.                 GlobalState.Sch0.send(0);
  27.             }
  28.             else if(request == 1)
  29.             {
  30.                 //Gets tobacco and matches, send to paper
  31.                 tobacco++;
  32.                 matches++;
  33.                 GlobalState.Sch1.send(1);
  34.             }
  35.             else if(request == 2)
  36.             {
  37.                 //Gets tobacco and paper, send to matches channel
  38.                 tobacco++;
  39.                 paper++;
  40.                 GlobalState.Sch2.send(2);              
  41.             }
  42.                 getState();
  43.            
  44.                 GlobalState.Ach4.receive();
  45.                
  46.                 tobacco = 0;
  47.                 paper = 0;
  48.                 matches = 0;
  49.                
  50.            
  51.         }
  52.     }
  53.    
  54.    
  55.     public void getState(){
  56.         System.out.println("A - tobacco:" + tobacco + " paper:" + paper
  57.                 + " matches:" + matches);
  58.     }
  59.    
  60.     public void doThings(){
  61.         AndrewsProcess.uninterruptibleMinimumDelay(ThreadLocalRandom
  62.                 .current().nextInt(500, 1000));
  63.     }
  64. }
RAW Paste Data
Top