swarm-support
[Top][All Lists]
Advanced

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

Re: Randomize Concurrent Events


From: Marcus G. Daniels
Subject: Re: Randomize Concurrent Events
Date: 01 May 2001 14:35:50 -0600
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.7

>>>>> "MN" == Minh Nguyen <address@hidden> writes:

MN> Do I have to use a ConcurrentSchedule or something to make this happen?

Thanks for pointing this problem out.  It actually was necessary to
set up a custom concurrentGroupType to get this behavior. 

Today's snapshot and builds will avoid that inconvenience.

  ftp://ftp.swarm.org/pub/swarm/src/testing/swarm-2001-05-01.tar.gz

  ftp://ftp.swarm.org/pub/swarm/binaries/w32/latest/javaswarm.dll.gz
                                                    libkaffeswarm.dll.gz
                                                    swarm.jar.gz
                                                    swarm.dll.gz

Here's an example (just for the benefit of others).  If you run it several
times with --varyseed, you should see "bap" and "bonk" printed in different
orders..

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

import swarm.Globals;

public class TestRandomize extends SwarmImpl {
    Schedule schedule;

    TestRandomize (Zone aZone) {
        super (aZone);
    }
    
    public void bonk () {
        System.out.println ("bonk @ " + Globals.env.getCurrentTime ());
    }

    public void bap () {
        System.out.println ("bap @ " + Globals.env.getCurrentTime ());
    }

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

        schedule = new ScheduleImpl (getZone (), false);
        schedule.setDefaultOrder (Globals.env.Randomized);

        try {
            Selector sel1 = new Selector (getClass (), "bonk", false);
            Selector sel2 = new Selector (getClass (), "bap", false);

            schedule.at$createActionTo$message (0, this, sel1);
            schedule.at$createActionTo$message (0, this, sel2);
        } catch (Exception e) {
            e.printStackTrace (System.err);
            System.exit (1);
        }

        return this;
    }

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

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

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

        TestRandomize testRandomize =
            new TestRandomize (Globals.env.globalZone);

        testRandomize.buildObjects ();
        testRandomize.buildActions ();
        testRandomize.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]