~ ~ ~ >>>>> "PJ" == Paul E Johnson writes: PJ> Suppose the outsider did have a "frob" method. Would this program PJ> call it? I tested it, and it seems the answer is "yes." The frob PJ> method of the outsider does get used, even though the selector is PJ> built from the method of the insider class. What the heck is PJ> going on? Conceptually, a Selector is a message that has no association with a class. Java reflection, however, requires such an association. Now, any time you have the need for a dispatch on an agent type (e.g. when calling actions across a set of heterogeneous agents), what Swarm does is make an Objective C method call. When such a method call turns out to be for a foreign agent (say, Java) the message is forwarded. The process of forwarding involves taking apart the Objective C message and reconstructing it in the right way for the foreign target. The reason the `outsider' can be sent `frob' is because the process of forwarding a message implies knowing to whom you are forwarding, and so Java reflection lookup requirements can still be satisfied. PJ> Is this Swarm runtime "magic" the sort of which PJ> "createActionForEachHomogeneous" circumvents? Yes, since the set passed to this method must be homogeneous, there is no point in doing dynamic method lookup over and over again. The method lookup is done once. Homogeneous ForEach Actions are faster for this reason. PJ> If the runtime can go shopping for methods, why do we have to use PJ> the selector approach at all? It's a question of context. In Java, to know whether or not a message is valid requires having a target type. PJ> 2. I am curious to know about how this method gets called: PJ> public void doesNotRecognize (Selector sel) { PJ> System.out.println ("ouch! " + sel); } PJ> } The Objective C runtime makes doesNotRecognize calls when it encounters a situation that can't be resolved by forwarding. Swarm then passes this on to the Java object involved... PJ> Maybe I can't understand because my system gives a different piece PJ> of output than yours, which seems to say "doesNotRecognize" is not PJ> called. As I indicated in the original message: MD> $ javaswarm NoSelector --version MD> NoSelector bug-swarm@swarm.org (Swarm 2001-02-23) (The glue code for passing on the doesNotRecognize message was not there in Swarm for Java in previous versions.) PJ> 3. Can you tell me how to write code to create Selectors when an PJ> argument is needed for the java method? Or two arguments? Etc. Here is an updated example: import swarm.Globals; import swarm.Selector; import swarm.objectbase.SwarmObjectImpl; class Agent extends SwarmObjectImpl { } class Insider extends Agent { public Object frob (Object with) { System.out.println ("frob with " + with); return this; } } class Outsider extends Agent { public Object frobX (Object with) { System.out.println ("frob outsider with " + with); return this; } public void doesNotRecognize (Selector sel) { System.out.println ("ouch! " + sel); } } public class NoSelector { static void main (String args[]) { Globals.env.initSwarm ("NoSelector", "bug-swarm@swarm.org", "0.0", args); Agent insider = new Insider (); Agent outsider = new Outsider (); Selector sel = null; try { sel = new Selector (insider.getClass (), "frob", false); } catch (Exception e) { e.printStackTrace (System.err); System.exit (1); } Object with = new Object (); System.out.println ("passing with argument of " + with); insider.perform$with (sel, with); outsider.perform$with (sel, with); } }