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]); }
/** * 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); } }
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; }
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); } } }
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(); } }
/** * 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; }
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; }