Esempio n. 1
1
 public void messageReceived(int to, MessageJ m) {
   try {
     if (m.getType() == AgillaTSResMsg.AM_TYPE) {
       log("Got a results message: " + m);
       // results = (AgillaTSResMsgJ)m;
       synchronized (response) {
         response.add(m);
         // if (timer != null) timer.kill();
         response.notifyAll();
       }
     } else if (m.getType() == AgillaTSReqMsg.AM_TYPE) {
       AgillaTSReqMsgJ reqMsg = (AgillaTSReqMsgJ) m;
       log("Got a request message: " + m);
       processRequest(reqMsg);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Esempio n. 2
0
 private MessageJ waitForResponse() {
   synchronized (response) {
     while (response.size() == 0) {
       try {
         response.wait();
       } catch (Exception e) {
         e.printStackTrace();
       }
     }
   }
   if (response.size() > 0) {
     return (MessageJ) response.remove(0);
   } else {
     log("BUG: Recursive call to waitForResponse()...");
     return waitForResponse();
   }
 }
Esempio n. 3
0
 /**
  * Returns a tuple matching the specified template. If no match is found, block until one is
  * found. If more than one match is found, choose and return one randomly. The tuple is kept in
  * the tuple space.
  */
 public Tuple rd(Tuple template) {
   log("RD: Performing an rd() operation.");
   Tuple result = rdp(template);
   if (result != null) return result;
   else {
     while (true) {
       synchronized (blocked) {
         try {
           log("RD: Blocking while doing an rd().");
           blocked.wait();
         } catch (Exception e) {
           e.printStackTrace();
         }
         result = rdp(template);
         if (result != null) return result;
       }
     }
   }
 }
Esempio n. 4
0
 /**
  * Returns a tuple matching the specified template. If no match is found, block until one is
  * found. If more than one match is found, choose and return one randomly. The tuple is removed
  * from the tuple space.
  */
 public Tuple in(Tuple template) {
   log("IN: Performing an in() operation.");
   Tuple result = inp(template);
   if (result != null) {
     return result;
   } else {
     while (true) {
       synchronized (blocked) {
         try {
           log("IN: BLOCKED while doing an in().");
           blocked.wait();
           log("IN: UNBLOCKED while doing an in().");
         } catch (Exception e) {
           e.printStackTrace();
         }
         log("IN: Trying to find a match.");
         result = inp(template);
         if (result != null) return result;
       }
     }
   }
 }