Exemplo n.º 1
0
 public Tuple[] rdgp(Tuple template) {
   Vector matchingTuples = new Vector();
   for (int i = 0; i < ts.size(); i++) {
     Tuple tuple = (Tuple) ts.get(i);
     if (template.matches(tuple)) matchingTuples.add(tuple);
   }
   if (matchingTuples.size() == 0) return null;
   return (Tuple[]) matchingTuples.toArray(new Tuple[0]);
 }
Exemplo n.º 2
0
 /**
  * Registers a reaction on this tuple space.
  *
  * @param rxn The reaction to register
  * @param listener The reaction callback function
  */
 public void registerReaction(Reaction rxn, ReactionListener listener) {
   reactions.add(new RegisteredReaction(rxn, listener));
   for (int i = 0; i < ts.size(); i++) {
     Tuple t = (Tuple) ts.get(i);
     if (rxn.getTemplate().matches(t)) listener.reactionFired(t);
   }
 }
Exemplo n.º 3
0
 public Tuple rdp(Tuple template) {
   for (int i = 0; i < ts.size(); i++) {
     Tuple tuple = (Tuple) ts.get(i);
     if (template.matches(tuple)) return tuple;
   }
   return null;
 }
Exemplo n.º 4
0
 private void checkRxns(Tuple t) {
   for (int i = 0; i < reactions.size(); i++) {
     RegisteredReaction rr = (RegisteredReaction) reactions.get(i);
     if (rr.getReaction().getTemplate().matches(t)) {
       rr.getListener().reactionFired(t);
     }
   }
 }
Exemplo n.º 5
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();
   }
 }
Exemplo n.º 6
0
 /**
  * Deregisters a reaction.
  *
  * @param r The reaction to register.
  * @return true if successful, false otherwise.
  */
 public boolean deregisterReaction(Reaction r) {
   for (int i = 0; i < reactions.size(); i++) {
     RegisteredReaction rxn = (RegisteredReaction) reactions.get(i);
     if (rxn.rxn.equals(r)) {
       reactions.remove(i);
       return true;
     }
   }
   return false;
 }
Exemplo n.º 7
0
 public Tuple inp(Tuple template) {
   for (int i = 0; i < ts.size(); i++) {
     Tuple tuple = (Tuple) ts.get(i);
     log("INP: Comparing:\n" + template + "\nwith:\n" + tuple);
     if (template.matches(tuple)) {
       log("INP: Match!");
       ts.remove(i);
       return tuple;
     }
   }
   return null;
 }