/** @see fabrik.IFactory#getFaultyCars() */ @Override public String[] getFaultyCars() { ArrayList<String> ret = new ArrayList<String>(); try { TransactionReference trans = capi.createTransaction(10000, Config.locationAutos); ContainerReference sammelstelle = capi.lookupContainer(ContainerNames.SAMMELSTELLE, Config.locationAutos, 0, trans); /* * In folgender Liste werden die defekten Autos gespeichert, die Transaktion wird * commitet und im Anschluss werden die zurueckzugebenen Autos in Textform in einem Array gespeichert */ ArrayList<Auto> autos = capi.take( sammelstelle, FifoCoordinator.newSelector(MzsConstants.Selecting.COUNT_ALL), 0, trans); for (Auto auto : autos) { ret.add(auto.toString()); } capi.commitTransaction(trans); } catch (CountNotMetException ce) { ce.printStackTrace(); } catch (MzsCoreException e) { e.printStackTrace(); } return ret.toArray(new String[ret.size()]); }
/** @see fabrik.IFactory#getDeliveredCars() */ @Override public String[] getDeliveredCars() { ArrayList<String> ret = new ArrayList<String>(); try { TransactionReference trans = capi.createTransaction(10000, Config.locationAutos); ContainerReference ausliefern = capi.lookupContainer( ContainerNames.AUSLIEFERN, Config.locationAutos, MzsConstants.RequestTimeout.ZERO, trans); /* * In folgender Liste werden die ausgelieferten Autos gespeichert, die Transaktion wird * commitet und im Anschluss werden die zurueckzugebenen Autos in Textform in einem Array gespeichert */ ArrayList<Auto> autos = capi.take( ausliefern, FifoCoordinator.newSelector(MzsConstants.Selecting.COUNT_ALL), MzsConstants.RequestTimeout.ZERO, trans); capi.commitTransaction(trans); for (Auto auto : autos) { ret.add(auto.toString()); } } catch (CountNotMetException ce) { ce.printStackTrace(); } catch (MzsCoreException e) { e.printStackTrace(); } return ret.toArray(new String[ret.size()]); }
/** @see fabrik.IFactory#getQuantity(String) */ @Override public int getQuantity(String type) { String containerName = ""; /* * Diese if Blöcke definieren, welches Einzelteil verwendet wird und uebergibt es dem * entsprechenden Container */ if (type.equals("einzelteile.Achse")) { containerName = ContainerNames.ACHSEN; } else if (type.equals("einzelteile.Bodenplatte")) { containerName = ContainerNames.PLATTEN; } else if (type.equals("einzelteile.Karosserie")) { containerName = ContainerNames.KAROSSERIE; } else if (type.equals("einzelteile.Lenkrad")) { containerName = ContainerNames.LENKRAD; } else if (type.equals("einzelteile.ReifenPaar")) { containerName = ContainerNames.REIFEN; } else if (type.equals("einzelteile.Sitz")) { containerName = ContainerNames.SITZE; } try { /* * Da man die Anzahl der Einzelteile erhalten hat, wird ueber die test-Methode von Capi * gecheckt, wieviele Einzelteile dieses Typs sich im Space befinden und zurueckgegeben */ int num = 0; TransactionReference trans = capi.createTransaction(MzsConstants.TransactionTimeout.INFINITE, Config.locationET); ContainerReference einzelteil = capi.lookupContainer( containerName, Config.locationET, MzsConstants.RequestTimeout.TRY_ONCE, trans); num = capi.test( einzelteil, FifoCoordinator.newSelector(MzsConstants.Selecting.COUNT_ALL), MzsConstants.RequestTimeout.TRY_ONCE, trans); capi.commitTransaction(trans); return num; } catch (CountNotMetException ce) { ce.printStackTrace(); } catch (MzsCoreException e) { e.printStackTrace(); System.exit(0); } return 0; }
public static void main(String[] args) { Runtime.getRuntime() .addShutdownHook( new Thread() { @Override public void run() { try { capi.take( cRef, KeyCoordinator.newSelector(id.toString()), RequestTimeout.INFINITE, null); } catch (MzsCoreException e) { System.out.println("this should never happen :S"); } } }); Logistician logistician = new Logistician(); // do some command checking int firstArg = -1; if (args.length == 1) { try { firstArg = Integer.parseInt(args[0]); } catch (NumberFormatException e) { System.err.println("Argument 1 must be an positive integer of WorkerID"); System.exit(1); } } else { System.err.println("Usage: java Logistician 'workerId'"); System.exit(1); } MzsCore core = DefaultMzsCore.newInstance(); capi = new Capi(core); try { uri = new URI("xvsm://localhost:9877"); } catch (URISyntaxException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { crefPc = App.getPcContainer(uri, capi); crefPcDefect = App.getPcDefectContainer(uri, capi); crefStorage = App.getStorageContainer(uri, capi); // create Notifications notification.createNotification(crefPc, logistician, Operation.WRITE); } catch (MzsCoreException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } // // try { // cRef = capi.lookupContainer( // containerName, // uri, // MzsConstants.RequestTimeout.INFINITE, // null); // } catch (MzsCoreException e1) { // // TODO Auto-generated catch block // e1.printStackTrace(); // } // // try { // shittyRef = capi.lookupContainer( // shittyContainerName, // uri, // MzsConstants.RequestTimeout.INFINITE, // null); // } catch (MzsCoreException e1) { // // TODO Auto-generated catch block // e1.printStackTrace(); // } // // try { // sellRef = capi.lookupContainer( // sellContainerName, // uri, // MzsConstants.RequestTimeout.INFINITE, // null); // } catch (MzsCoreException e1) { // // TODO Auto-generated catch block // e1.printStackTrace(); // } // // // check if arguments are correct // // try to insert worker id into space, exit if not unique id = firstArg; // // Entry entry = new Entry(logistician.getClass(), // KeyCoordinator.newCoordinationData(id.toString())); // // try { // capi.write(cRef, MzsConstants.RequestTimeout.TRY_ONCE, null, entry); // } catch (DuplicateKeyException dup) { // System.out.println("ERROR: A Worker with this key already exists, take another one!"); // //TODO: cleanup! // return; // } catch (MzsCoreException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } ArrayList<Computer> computerList = null; ArrayList<Computer> readComputerList = null; try { readComputerList = capi.read( crefPc, Arrays.asList(FifoCoordinator.newSelector(MzsConstants.Selecting.COUNT_MAX)), MzsConstants.RequestTimeout.INFINITE, null); } catch (MzsCoreException e3) { // TODO Auto-generated catch block e3.printStackTrace(); } for (int i = 0; i <= readComputerList.size(); i++) { try { computerList = capi.take( crefPc, LabelCoordinator.newSelector("testedComputer", 1), RequestTimeout.INFINITE, null); } catch (MzsCoreException e) { System.out.println("this should never happen :S"); } if (!computerList.isEmpty()) { Computer computer = computerList.get(0); System.out.println( "DEBUG: GOT COMPUTERLIST WITH COMPUTER CREATOR: " + computer.getMakerID() + " and Tester " + computer.getTesterID() + " AND ISDEFECT:" + computer.isDefect()); // keep track of Logistician that processed it; computer.setLogisticianID(id); if (computer.isDefect()) { TransactionReference tx = null; try { tx = capi.createTransaction(5000, uri); } catch (MzsCoreException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } /** * Entry compEntry = new Entry(computer); * * <p>try { transaction = capi.createTransaction(MzsConstants.RequestTimeout.INFINITE, * uri); capi.write(compEntry, shittyRef, RequestTimeout.INFINITE, transaction); * capi.commitTransaction(transaction); */ Entry compEntry = new Entry(computer, LabelCoordinator.newCoordinationData("shitty")); try { capi.write(compEntry, crefPcDefect, RequestTimeout.INFINITE, null); } catch (MzsCoreException e) { System.out.println("this should never happen :S"); } try { capi.commitTransaction(tx); } catch (MzsCoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("DEBUG: WROTE DEFECT TRUE TO COMPUTER NR: " + computer.getMakerID()); } else { TransactionReference tx = null; try { tx = capi.createTransaction(5000, uri); } catch (MzsCoreException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } /** * Entry compEntry = new Entry(computer); * * <p>try { transaction = capi.createTransaction(MzsConstants.RequestTimeout.INFINITE, * uri); capi.write(compEntry, sellRef, RequestTimeout.INFINITE, transaction); * capi.commitTransaction(transaction); */ Entry compEntry = new Entry(computer, LabelCoordinator.newCoordinationData("sell")); try { capi.write(compEntry, crefStorage, RequestTimeout.INFINITE, null); } catch (MzsCoreException e) { System.out.println("this should never happen :S"); } try { capi.commitTransaction(tx); } catch (MzsCoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("DEBUG: WROTE DEFECT FALSE TO COMPUTER NR: " + computer.getMakerID()); } } else { System.out.println("DEBUG: Computerlist is Empty, retrying "); } } }