swarm-support
[Top][All Lists]
Advanced

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

Re: [Swarm-Support] Java swarm help with Log File


From: Marcus G. Daniels
Subject: Re: [Swarm-Support] Java swarm help with Log File
Date: Tue, 08 Nov 2005 09:52:13 -0700
User-agent: Thunderbird 1.0+ (Windows/20050803)

durga bhavani wrote:
Could you please clear the idea of adding methods to the list and
also the objects that are in the leaderlist should have the method which I have to call I am very new to Java swarm could you please provide an example for the same
Here is an example that illustrates the difference between a List target (ForEach send) and a simple target.


import swarm.SwarmEnvironmentImpl;
import swarm.Globals;
import swarm.defobj.Zone;
import swarm.activity.ActionGroupImpl;
import swarm.activity.ActionGroup;
import swarm.activity.Activity;
import swarm.objectbase.SwarmImpl;
import swarm.objectbase.Swarm;
import swarm.Selector;

import java.util.LinkedList;
import java.util.List;

public class TestList extends SwarmImpl {
    List leaderList;
    ActionGroup modelActions;

    class MyMathsClass{
        public int addEmUp(){
            int i,j;
            int value=0;
            for(i=0;i<10;i++){
                for(j=0;j<10;j++){
                    value=i+j;
                }
            }
            System.out.println ("addEmUp result:" + value);
            return value;
        }
    }
    
    public Object buildObjects () {
        super.buildObjects ();

        leaderList = new LinkedList ();
        leaderList.add (new MyMathsClass ());
        return this;
    }
    
    public Object buildActions () {
        super.buildActions ();
        Selector sel = null;

        try {
            sel = new Selector (MyMathsClass.class, "addEmUp", false);
        } catch (Exception e) {
            System.exit (1);
        }
        modelActions = new ActionGroupImpl (this);
        modelActions.createActionForEach$message (leaderList, sel);
        modelActions.createActionTo$message (leaderList.get(0), sel);
        return this;
    }
    
    public Activity activateIn (Swarm swarmContext) {
        super.activateIn (swarmContext);

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

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

    public static void main (String args[]) {
        Globals.env.initSwarm ("TestList", "0.0", "address@hidden", args);
        
        Swarm swarm = new TestList (Globals.env.globalZone);
        swarm.buildObjects ();
        swarm.buildActions ();
        swarm.activateIn (null).run();
    }
}

reply via email to

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