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)); }
@Override protected void beforeRun() { super.beforeRun(); for (WorkStation m : machines) m.init(); for (JobSource s : sources) s.init(); }
/** * 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++; } }
/** * 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); } }
/** * 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()]); }
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); } } }
private boolean isRepeated(Socket socket) { boolean flag = false; for (WorkStation w : workStations) { if (w.getClientIP().equals(socket.getInetAddress().toString())) { flag = true; break; } } return flag; }
@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); } }
@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; }
/** * 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()]); } }
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(); } }
/** * 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; }
@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; }
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); }
@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(); }
@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(); } } }
@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; }
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 }"); } }
@Override protected void done() { super.done(); for (WorkStation m : machines) m.done(); }