swarm-support
[Top][All Lists]
Advanced

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

Re: freedom using Activity


From: Marcus G. Daniels
Subject: Re: freedom using Activity
Date: 15 May 2000 15:03:43 -0700
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4

>>>>> "DA" == David Aliaga <address@hidden> writes:

DA> That means that I do Execute_trials until the agent "die", then
DA> change something and run again the trial.  I have no idea how to
DA> implement these 2 levels in swarm, especially because in the
DA> examples the agents seem to live "forever" I can make some code to
DA> accomplish what I want but I feel its forced and not natural, for
DA> example:

Here's a fairly clean approach.  The idea is to hold on to a handle
to an activated schedule, and then kill that activity off when the time
comes.  This actually didn't work right in 2.1.1 (and has never
really been done, as far as I know), so you'll need to grab new
DLLs, gunzip them, and put them in $SWARMHOME/bin.  Also gunzip swarm.jar.gz
and put it in $SWARMHOME/share/swarm.

  ftp://ftp.swarm.org/pub/swarm/binaries/w32/2.1.1-fixes

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

public class StopOnStatusChange extends SwarmImpl {
  Schedule repeatingSchedule1;
  Schedule repeatingSchedule2;
  Schedule stopSchedule;
  Activity activity1;

  StopOnStatusChange (Zone aZone) {
    super (aZone); 
  }

  public Object buildActions () {
    repeatingSchedule1 = new ScheduleImpl (getZone (), 1);
    repeatingSchedule2 = new ScheduleImpl (getZone (), 1);
    stopSchedule = new ScheduleImpl (getZone (), true);

    try {
      repeatingSchedule1.at$createActionTo$message
        (0, this,
         new Selector (getClass (), "check1", false));
      repeatingSchedule2.at$createActionTo$message
        (0, this,
         new Selector (getClass (), "step2", false));
      stopSchedule.at$createActionTo$message
        (10, this,
         new Selector (getClass (), "stopall", false));
    } catch (Exception e) {
      e.printStackTrace (System.err);
      System.exit (1);
    }
    return this;
  }

  public void check1 () {
    int t = getActivity ().getCurrentTime ();

    System.out.println ("check1 @ " + t);
    if (t == 5)
      activity1.terminate ();
  }

  public void step2 () {
    System.out.println ("step @ " + getActivity ().getCurrentTime ());
  }

  public void stopall () {
    getActivity ().terminate ();
  }
  
  public Activity activateIn (Swarm swarmContext) {
    super.activateIn (swarmContext);
    
    repeatingSchedule2.activateIn (this);
    activity1 = repeatingSchedule1.activateIn (this);
    stopSchedule.activateIn (this);
    return getActivity ();
  }

  static public void main (String args[]) {
    Globals.env.initSwarm ("StopOnStatusChange", "0.0",
                           "address@hidden", args);
    
    StopOnStatusChange obj = 
      new StopOnStatusChange (Globals.env.globalZone);

    obj.buildObjects ();
    obj.buildActions ();
    obj.activateIn (null).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]