swarm-support
[Top][All Lists]
Advanced

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

Re: How to Replace actions in schedules ?


From: Marcus G. Daniels
Subject: Re: How to Replace actions in schedules ?
Date: 11 Jun 2001 23:06:15 -0600
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.7

>>>>> "NB" == Narjes BELLAMINE-BEN SAOUD <address@hidden> writes:

NB> My problem, is how to replace one actions by a different one...

Swarm can now do this in the literal way you suggest.  You'll need
today's snapshot or Windows DLLs & jar file from

To install:

$ cd /tmp

$ mv /Swarm-2.1.1/share/swarm/swarm.jar /Swarm-2.1.1/share/swarm/swarm.jar.bak
$ wget ftp://ftp.swarm.org/pub/swarm/binaries/w32/latest/swarm.jar.gz
$ gunzip swarm.jar.gz
$ mv swarm.jar /Swarm-2.1.1/share/swarm

 (for Sun JDK)
$ mv /Swarm-2.1.1/bin/javaswarm.dll /Swarm-2.1.1/bin/javaswarm.dll.bak
$ wget ftp://ftp.swarm.org/pub/swarm/binaries/w32/latest/javaswarm.dll.gz
$ gunzip javaswarm.dll.gz 
$ mv javaswarm.dll /Swarm-2.1.1/bin

(for Kaffe)
$ mv /Swarm-2.1.1/bin/libkaffeswarm.dll /Swarm-2.1.1/bin/libkaffeswarm.dll.bak
$ wget ftp://ftp.swarm.org/pub/swarm/binaries/w32/latest/libkaffeswarm.dll.gz
$ gunzip libkaffeswarm.dll.gz
$ mv libkaffeswarm.dll /Swarm-2.1.1/bin

Here's an example:

import swarm.objectbase.SwarmImpl;
import swarm.activity.Schedule;
import swarm.activity.ScheduleImpl;
import swarm.objectbase.Swarm;
import swarm.activity.Activity;
import swarm.activity.ActionSelectorS;
import java.util.LinkedList;
import java.util.List;
import swarm.defobj.Zone;
import swarm.Selector;
import swarm.Globals;

class Agent { 
  int sn;
  
  Agent (int sn) {
    this.sn = sn;
  }

  public void msg1 () {
    System.out.println (this + " " + sn + " msg1");
  }
        
  public void msg2 () {
    System.out.println (this + " " + sn + " msg2");
  }
 
}

public class UpdateSelector extends SwarmImpl {
  Schedule schedule;
  Schedule changeSchedule;
  Schedule stopSchedule;
  ActionSelectorS actionForEach;
  List agentList; 
  Selector sel2;
  
  UpdateSelector (Zone aZone) {
    super (aZone);
  }

  public Object buildObjects () {
    super.buildObjects ();

    agentList = new LinkedList ();
    for (int i = 0; i < 2; i++)
      agentList.add (new Agent (i));
    return this;
  }

  public Object buildActions () {
    super.buildActions ();
    
    schedule = new ScheduleImpl (getZone (), 1);
    changeSchedule = new ScheduleImpl (getZone (), true);
    stopSchedule = new ScheduleImpl (getZone (), true);

    try {
      Selector sel = new Selector (Agent.class, "msg1", false);
      
      actionForEach =
        schedule.at$createActionForEachHomogeneous$message (0, agentList, sel);
            
      sel = new Selector (getClass (), "change", false);
      changeSchedule.at$createActionTo$message (2, this, sel);

      sel = new Selector (getClass (), "stop", false);
      stopSchedule.at$createActionTo$message (4, this, sel);

      sel2 = new Selector (Agent.class, "msg2", false);
    } catch (Exception e) {
      e.printStackTrace (System.err);
      System.exit (1);
    }
    return this;
  }
    
  public void change () {
    System.out.println ("change");
    try {
      actionForEach.setMessageSelector (sel2);
    } catch (Exception e) {
      e.printStackTrace (System.err);
      System.exit (1);
    }
  }

  public void stop () {
    getActivity ().terminate ();
  }

  public Activity activateIn (Swarm swarmContext) {
    super.activateIn (swarmContext);

    schedule.activateIn (this);
    changeSchedule.activateIn (this);
    stopSchedule.activateIn (this);
    return getActivity ();
  }

  static void main (String args[]) {
    Globals.env.initSwarm ("UpdateSelector",
                           "0.0",
                           "address@hidden",
                           args);

    UpdateSelector obj = new UpdateSelector (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]