swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: any clue?


From: Marcus G. Daniels
Subject: Re: any clue?
Date: 05 Oct 1999 09:57:45 -0700
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4

>>>>> "MN" == Murali Nandula <address@hidden> writes:

MN> /src/Swarm/swarm/src/defobj/directory.m:331 [Directory
MN> switchObjc:javaObject]

It might be a bug in Swarm related to the way you are using strings.

MN>   I had to do it like this:
MN>     public Object moveTo(Object direction) { String dirstr =
MN> (String) direction; // do something with 'dirstr' }

I think this is because you are passing true as the objcFlag to
Selector.  For a Java method, that should be false.

This works for me:

import swarm.defobj.Zone;
import swarm.activity.Schedule;
import swarm.activity.ScheduleImpl;
import swarm.activity.Activity;
import swarm.objectbase.Swarm;
import swarm.objectbase.SwarmImpl;
import swarm.Selector;
import swarm.Globals;

public class TestModelSwarm extends SwarmImpl {
  Schedule schedule;
  Schedule stopSchedule;
  
  TestModelSwarm (Zone aZone) {
    super (aZone);
  }

  public void moveTo (String direction) {
    System.out.println ("Moving " + direction + " at: " + 
                        Globals.env.getCurrentTime ());
  }

  public void stopRunning () {
    Globals.env.getCurrentSwarmActivity ().terminate ();
  }
  
  public Object buildActions () {
    schedule = new ScheduleImpl (this, 5);
    stopSchedule = new ScheduleImpl (this, true);
    
    try {
      Selector moveSel = new Selector (getClass (), "moveTo", false);
      Selector stopSel = new Selector (getClass (), "stopRunning", false);

      schedule.at$createActionTo$message (1, this, moveSel, "left");
      schedule.at$createActionTo$message (3, this, moveSel, "right");
      stopSchedule.at$createActionTo$message (20, this, stopSel);
    } catch (Exception e) {
      e.printStackTrace (System.err);
    }
    return this;
  }
  
  public Activity activateIn (Swarm swarmContext) {
    super.activateIn (swarmContext);
    
    schedule.activateIn (this);
    stopSchedule.activateIn (this);
    return getActivity ();
  }

  public static void main (String[] args) {
    Globals.env.initSwarm ("testSchedule",
                           "2.0.1", "address@hidden",
                           args);
    Swarm modelSwarm = new TestModelSwarm (Globals.env.globalZone);

    modelSwarm.buildActions ();
    modelSwarm.activateIn (null);
    modelSwarm.getActivity ().run ();
  }
}

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]