swarm-support
[Top][All Lists]
Advanced

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

Re: Serialisation (saving) in Java


From: Marcus G. Daniels
Subject: Re: Serialisation (saving) in Java
Date: 15 Sep 2000 17:40:07 -0700
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4

>>>>> "MB" == Marie-Edith Bissey <address@hidden> writes:

MB> I declared the variable startBudget as public, and installed the
MB> fixes, but nothing changed much in the program... Do you have some
MB> examples of the use of putShallow$Object in javaSwarm? 

Here is an example that saves a single object to a .scm and .hdf file.
The first time you run it you should see "null" twice, because it is
trying to load the yet-to-be-created object from these two sources.

The second time you run it, it will have written the objects to the
.scm and .hdf files, and so you should see address@hidden  

The item.scm file should look like this:

(list
  (cons 'item
     (make-instance 'Item #:a #t #:b 1 #:c 2.000000F0 #:d 3.000000D0)))

The HDF5 file should be loadable like so:

$ R
> library(hdf5)
> hdf5load("item.hdf")

It will be stored as the "item" variable":

> item
        a b c d
item TRUE 1 2 3

Here's the code:

import swarm.Globals;
import swarm.defobj.HDF5ArchiverImpl;
import swarm.defobj.LispArchiverImpl;
import swarm.defobj.Archiver;
import swarm.defobj.Zone;

class Item {
  public boolean a;
  public int b;
  public float c;
  public double d;
  
  Item () { }

  Item (boolean a, int b, float c, double d) {
    this.a = a;
    this.b = b;
    this.c = c;
    this.d = d;
  }
}

public class ArchivedItem {
  Item item;

  public ArchivedItem () {
    super ();

    item = new Item (true, 1, 2.0f, 3.0);
  }
  
  void test (Archiver archiver) {
    System.out.println (archiver.getObject ("item"));
    archiver.putShallow$object ("item", item);
    archiver.sync ();
  }

  static void main (String args[]) {
    Globals.env.initSwarm ("ArchivedItem", "0.0",
                           "address@hidden", args);
    Zone aZone = Globals.env.globalZone;

    ArchivedItem item = new ArchivedItem ();
    item.test (new HDF5ArchiverImpl (aZone, "item.hdf"));
    item.test (new LispArchiverImpl (aZone, "item.scm"));
  }
}

                  ==================================
   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]