swarm-support
[Top][All Lists]
Advanced

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

Re: memory in java


From: Marcus G. Daniels
Subject: Re: memory in java
Date: 27 Dec 1999 19:13:29 -0800
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4

>>>>> "JR" == Juan A Rodriguez <address@hidden> writes:

JR> All this Long objects are when calling at$createActionTo$message
JR> for the schedule. It's one of the parameters of the method called
JR> by the selector. 

Below is an example of how to use the `foreign action' FCall feature found
in the current sources.  It avoids wrapping scalars in Objects, and
thus avoids the problem you're having.

Note that unlike C, that `long' in Java is fixed at 64 bits.
That's why use of the addLongLong:.  I fixed some things related to long
in today's snapshot, so if you're using longs, be sure to grab it.

  ftp://ftp.santafe.edu/pub/swarm/testing/swarm-1999-12-27.tar.gz

import swarm.objectbase.SwarmImpl;
import swarm.defobj.Zone;
import swarm.activity.Schedule;
import swarm.activity.ScheduleImpl;
import swarm.objectbase.Swarm;
import swarm.activity.Activity;
import swarm.defobj.FCallImpl;
import swarm.defobj.FCall;
import swarm.defobj.FArgumentsImpl;
import swarm.defobj.FArgumentsCImpl;
import swarm.defobj.FArguments;
import swarm.defobj.FArgumentsC;
import swarm.Selector;
import swarm.Globals;

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

  public void stepSwarm (long val) {
    System.out.println ("step @ " + Globals.env.getCurrentTime () + 
                        " val: " + val);
  }

  public void stopSwarm () {
    getActivity ().terminate ();
  }
  
  FCall createCall () {
    try {
      FArgumentsC creating = new FArgumentsCImpl (new FArgumentsImpl ());
      Selector sel = new Selector (getClass (), "stepSwarm", false);
      
      creating.createBegin (getZone ());
      creating.setJavaFlag (true);
      creating.setSelector (sel);
      creating.addLongLong (100);
      return new FCallImpl (getZone (), this, sel,
                            (FArguments) creating.createEnd ());
    } catch (Exception e) {
      e.printStackTrace (System.err);
    }
    return null;
  }

  FCall createStopCall () {
    try {
      Selector sel = new Selector (getClass (), "stopSwarm", false);
      return new FCallImpl (getZone (), this, sel,
                            new FArgumentsImpl (getZone (), sel, true));
    } catch (Exception e) {
      e.printStackTrace (System.err);
    }
    return null;
  }

  public Object buildActions () {
    super.buildActions ();
    
    schedule = new ScheduleImpl (this, 1);
    stopSchedule = new ScheduleImpl (this, true);
    schedule.at$createFAction (0, createCall ());
    stopSchedule.at$createFAction (10, createStopCall ());
    return this;
  }

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

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

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

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