Class SwarmUtils
java.lang.Object
|
+--SwarmUtils
- public class SwarmUtils
- extends java.lang.Object
These two static methods create a selector. A selector is an
object of the Selector class used by Swarm to encapsulate a
"message" destined for an object, where the message is the name
of a method defined for the class to which the object belongs.
Because the method must indeed be defined for the class of the
object and because this can be determined only at run time,
there is a possibility that the creation of the selector will
throw an exception if the class and the method do not match.
Java requires that events that might throw exceptions be
enclosed in try/catch blocks. If there is an error creating
the new selector in the try block, the catch block can handle
the resulting exception. Here we have taken a pretty crude
approach to handling the exception: we simply call
System.exit(1). (Note that the "return null" which ends the
catch block is there only to tell the compiler that "return
sel" will never be reached if an exception occurs and sel is
undefined. We'll exit on an exception before ever returning
sel to the calling method.)
Note that the getSelector method overloaded. It can be
called with either a string containing the class name as its
first argument, or with an object of the desired class. In the
first case, the string is converted to a class identifier using
the forName() method, while in the second case getClass() is
used to find the class identifier for the object. The second
argument to getSelector is always a string containing the
method name. (The boolean "false" at the end of the Selector
constructor is theobjCFlag. It allows one to use
ObjectiveC-type key/value method syntax. Since we always use
Java-style method names, for us the flag is always false.)
- Author:
- Charles P. Staelin
Method Summary |
static swarm.Selector |
getSelector(java.lang.Object obj,
java.lang.String method)
|
static swarm.Selector |
getSelector(java.lang.String name,
java.lang.String method)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SwarmUtils
public SwarmUtils()
getSelector
public static swarm.Selector getSelector(java.lang.String name,
java.lang.String method)
getSelector
public static swarm.Selector getSelector(java.lang.Object obj,
java.lang.String method)