1 package at.ac.tuwien.sbc.valesriegler.xvsm;
3 import java.io.Serializable;
6 import org.mozartspaces.notifications.Notification;
7 import org.mozartspaces.notifications.NotificationListener;
8 import org.mozartspaces.notifications.Operation;
9 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory;
12 import at.ac.tuwien.sbc.valesriegler.types.PizzaOrder;
14 public class CookXVSM extends AbstractXVSMConnector {
15 private static final Logger log = LoggerFactory.getLogger(CookXVSM.class);
19 public CookXVSM(int id) {
25 useDeliverPizzasContainer();
26 usePreparePizzasContainer();
29 public void listenForPizzas() {
30 NotificationListener pizzasListener = new NotificationListener() {
32 public void entryOperationFinished(final Notification notification, final Operation operation, final List<? extends Serializable> entries) {
34 log.info("New Pizzas to prepare!");
36 List<PizzaOrder> pizzas = castEntries(entries);
37 for (PizzaOrder pizzaOrder : pizzas) {
38 log.info(pizzaOrder.toString());
41 // List<GroupData> groups = castEntries(entries);
42 // Collections.shuffle(groups);
44 // for (GroupData group : groups) {
46 // TransactionReference tx = capi.createTransaction(1500, URI.create(Util.SERVER_ADDR));
49 // // Acquire a lock for the group in the AssignTableContainer
50 // String groupNotFound = String.format("Group with id %d was already assigned a table by another waiter!", group.getId());
52 // GroupData lockedGroup = takeEntityByTemplateFromContainer(new GroupData(group.getId()), assignTableContainer, tx, 1000, groupNotFound);
53 // // Acquire a lock for one free table in the TablesContainer
54 // Table lockedFreeTable = takeEntityByTemplateFromContainer(new Table(null), freeTablesContainer, tx, RequestTimeout.DEFAULT, String.format("No free table for group with id %d could be found", group.getId()));
56 // assignGroupToTable(lockedGroup, lockedFreeTable, tx);
58 // } catch (IllegalArgumentException e) {
59 // log.info("IllegalArgumentException");
60 // e.printStackTrace();
61 // } catch (EntityNotFoundByTemplate e) {
62 // log.info(e.getMessage());
63 // } catch (Exception e) {
64 // log.error("AN INNER EXCEPTION");
65 // e.printStackTrace();
67 // } catch (TransactionException e) {
68 // log.info("An unimportant TransactionException has occurred");
69 // } catch (Exception e) {
70 // log.error("OUTER EXCEPTION");
77 notificationMgr.createNotification(preparePizzasContainer, pizzasListener, Operation.WRITE);
78 log.info("Created pizzasContainer notification for a cook");
79 } catch (Exception e) {
80 handleSpaceErrorAndTerminate(e);