예제 #1
0
파일: Server.java 프로젝트: anewage/git
 private void sendClientList() {
   Vector<String> clientIPList = new Vector<String>();
   for (WorkStation ws : workStations) {
     clientIPList.add(ws.getClientName());
   }
   parent.dispatchEvent(new MSG(parent, MSG.CLIENT_LIST, clientIPList));
 }
예제 #2
0
  @Override
  protected void beforeRun() {
    super.beforeRun();

    for (WorkStation m : machines) m.init();

    for (JobSource s : sources) s.init();
  }
예제 #3
0
 /**
  * Sets the workstations of this shop.
  *
  * @param machines An array containing all workstations for this shop.
  */
 public void setMachines(WorkStation[] machines) {
   this.machines = machines.clone();
   int i = 0;
   for (WorkStation w : machines) {
     w.shop = this;
     w.index = i++;
   }
 }
예제 #4
0
 /**
  * Adds a listener to all {@link WorkStation}s in the shop.
  *
  * @param listener The machine listener to add.
  * @param cloneIfPossible whether to try to clone a new instance for each machine using {@link
  *     TypeUtil#cloneIfPossible(Object)}.
  */
 public void installMachineListener(
     NotifierListener<WorkStation, WorkStationEvent> listener, boolean cloneIfPossible) {
   for (WorkStation m : machines) {
     NotifierListener<WorkStation, WorkStationEvent> ml = listener;
     if (cloneIfPossible) ml = TypeUtil.cloneIfPossible(listener);
     m.addNotifierListener(ml);
   }
 }
예제 #5
0
  /**
   * Adds a single machine to this shop.
   *
   * @see #getMachines()
   * @param machine The workstation to add.
   */
  public void addMachine(WorkStation machine) {
    ArrayList<WorkStation> list = new ArrayList<WorkStation>(Arrays.asList(machines));
    list.add(machine);

    machine.shop = this;
    machine.index = list.size() - 1;

    machines = list.toArray(new WorkStation[list.size()]);
  }
예제 #6
0
파일: Server.java 프로젝트: anewage/git
 public void sendToAll(String input, WorkStation sender) throws SocketException {
   if (sender == null) {
     for (WorkStation w : workStations) w.sendMessage(input);
   } else {
     for (WorkStation w : workStations) {
       if (!w.equals(sender)) w.sendMessage(input);
     }
   }
 }
예제 #7
0
파일: Server.java 프로젝트: anewage/git
 private boolean isRepeated(Socket socket) {
   boolean flag = false;
   for (WorkStation w : workStations) {
     if (w.getClientIP().equals(socket.getInetAddress().toString())) {
       flag = true;
       break;
     }
   }
   return flag;
 }
예제 #8
0
  @Override
  public void produceResults(Map<String, Object> res) {
    super.produceResults(res);

    res.put("numJobsFinished", jobsFinished);
    res.put("numJobsStarted", jobsStarted);
    res.put("numWIP", jobsStarted - jobsFinished);

    for (WorkStation m : machines) {
      m.produceResults(res);
    }
  }
예제 #9
0
 @GET
 @Path("/{id}/")
 public WorkStation getLaptop(@PathParam("id") String id) {
   System.out.println("----invoking getCustomer, Customer id is: " + id);
   long idNumber = Long.parseLong(id);
   for (WorkStation c : cc.getUsers()) {
     if (c.getId() == idNumber) {
       return c;
     }
   }
   return null;
 }
예제 #10
0
 /**
  * Removes a machine from this shop.
  *
  * @param machine The workstation to remove.
  */
 public void removeMachine(WorkStation machine) {
   ArrayList<WorkStation> list = new ArrayList<WorkStation>(Arrays.asList(machines));
   if (list.remove(machine)) {
     machine.shop = null;
     machine.index = -1;
     int i = 0;
     for (WorkStation w : list) {
       w.index = i++;
     }
     machines = list.toArray(new WorkStation[list.size()]);
   }
 }
예제 #11
0
파일: Server.java 프로젝트: anewage/git
 public void startGame() {
   try {
     String msg = "{ NOP " + getNumberOfPlayers() + " ";
     for (WorkStation w : workStations) {
       msg = msg + w.getClientName() + " ";
     }
     msg = msg + "}";
     sendToAll(msg, null);
   } catch (SocketException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
예제 #12
0
  /**
   * Returns a workstation with the given name, or {@code null} if no such workstation exists.
   *
   * @param name The workstation's name.
   * @return The workstation with the given name, if it exists. {@code null} otherwise.
   */
  public WorkStation getWorkstationByName(String name) {
    WorkStation res = null;

    if (getMachines() != null)
      for (WorkStation w : getMachines()) {
        if (name.equals(w.getName())) {
          res = w;
          break; // for w
        }
      }

    return res;
  }
예제 #13
0
 @DELETE
 @Path("/{id}/")
 public WorkStation deleteLaptop(@PathParam("id") String id) {
   System.out.println("----invoking deleteCustomer, Customer id is: " + id);
   long idNumber = Long.parseLong(id);
   for (WorkStation c : cc.getUsers()) {
     if (c.getId() == idNumber) {
       cc.getUsers().remove(c);
       return c;
     }
   }
   return null;
 }
예제 #14
0
  public void startJob(Job nextJob) {
    nextJob.setJobNum(jobsStarted++);

    if (getMaxJobsInSystem() > 0 && (jobsStarted - jobsFinished) >= getMaxJobsInSystem()) {
      print(SimMsgCategory.WARN, "WIP reaches %d, aborting sim.", getMaxJobsInSystem());
      end(); // abort simulation
    }

    nextJob.jobReleased();

    lastJobReleased = nextJob;
    if (numListener() > 0) fire(JOB_RELEASED);

    WorkStation mach = nextJob.getCurrentOperation().machine;
    mach.enqueueOrProcess(nextJob);
  }
예제 #15
0
  @POST
  public WorkStation addLaptop(WorkStation customer) {
    System.out.println("----invoking addCustomer, Customer name is: " + customer.getName());
    // customer.setId(++currentId);
    cc.getUsers().add(customer);
    // customers.put(customer.getId(), customer);

    return customer; // Response.ok(customer).build();
  }
예제 #16
0
파일: Server.java 프로젝트: anewage/git
 @Override
 public void run() {
   while (waitingForClients) {
     try {
       clientSocket = serverSocket.accept();
       System.out.println("accepted");
       if (!isRepeated(clientSocket)) {
         WorkStation w = new WorkStation(clientSocket, this, parent);
         workStations.add(w);
         System.out.println(clientSocket.getInetAddress() + " Joined!");
         w.setGameRunning(true);
         w.start();
         sendClientList();
       }
     } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   }
 }
예제 #17
0
  @PUT
  public WorkStation updateLaptop(WorkStation customer) {
    System.out.println(
        "----invoking updateCustomer, "
            + customer.getId()
            + "Customer name is: "
            + customer.getName());

    for (WorkStation c : cc.getUsers()) {
      if (c.getId() == customer.getId()) {
        c.setName(customer.getName());
        return c;
      }
    }
    return customer;
  }
예제 #18
0
파일: Server.java 프로젝트: anewage/git
 public void validatePlayers() {
   boolean allReady = true;
   for (WorkStation w : workStations) {
     if (w.getMapValidID().equals(-1L)) {
       w.sendMessage("{ SELECT_MAP }");
       allReady = false;
     }
   }
   if (allReady) {
     Long validID = workStations.elementAt(0).getMapValidID();
     for (WorkStation w : workStations) {
       String msg = "";
       if (w.getMapValidID().equals(validID)) {
         msg = "{ MAP_IS_VALID }";
       } else {
         msg = "{ MAP_IS_NOT_VALID }";
       }
       w.sendMessage(msg);
     }
   } else {
     workStations.elementAt(0).sendMessage("{ WAIT }");
   }
 }
예제 #19
0
  @Override
  protected void done() {
    super.done();

    for (WorkStation m : machines) m.done();
  }