Added some magic on the road toward more elegant support for dynamic languages

like Groovy and JRuby. Created a DynamicEventDispatcher that automatically maps
attribute, element and set events to methods. Say you have a field:

  public DSet occupantInfo;

you can create a method in any class:

  public void occupantInfoAdded (BodyObject source, OccupantInfo entry);

and then bind that class as a listener using the dynamic event dispatcher:

  _myobj.addListener(new DynamicEventDispatcher(object));

I also created a nicer replacement for the MessageHandler system which is
clunky but still way simpler than using a full InvocationService. Basically we
dispatch MessageEvent as if it were a method call. 

For example, in AtlantiManager I define:

    public void placeTile (BodyObject placer, AtlantiTile tile)

which receives a request by a player to place a tile on their turn. Then in
AtlantiController, I simply call:

   _atlobj.manager.invoke("placeTile", tile);

Of course, in JRuby and Groovy, that's going to look like:

   _atlobj.manager.placeTile(tile);

which is all part of the fun.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4344 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2006-08-24 17:35:32 +00:00
parent 0291990de9
commit b4d66588c1
4 changed files with 364 additions and 218 deletions
+9 -13
View File
@@ -21,26 +21,22 @@
package com.threerings.crowd;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* A placeholder class that contains a reference to the log object used by
* the Crowd services.
* Contains a reference to the log object used by the Crowd services.
*/
public class Log
{
public static com.samskivert.util.Log log =
new com.samskivert.util.Log("crowd");
/** Convenience function. */
public static boolean debug ()
{
return (com.samskivert.util.Log.getLevel() ==
com.samskivert.util.Log.DEBUG);
}
/** We dispatch our log messages through this logger. */
public static Logger log =
Logger.getLogger("com.threerings.narya.crowd");
/** Convenience function. */
public static void debug (String message)
{
log.debug(message);
log.fine(message);
}
/** Convenience function. */
@@ -58,6 +54,6 @@ public class Log
/** Convenience function. */
public static void logStackTrace (Throwable t)
{
log.logStackTrace(com.samskivert.util.Log.WARNING, t);
log.log(Level.WARNING, t.getMessage(), t);
}
}