swarm-support
[Top][All Lists]
Advanced

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

Re: Creating new archiver in java Swarm


From: Marcus G. Daniels
Subject: Re: Creating new archiver in java Swarm
Date: 15 Feb 2001 18:11:11 -0800
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4

>>>>> "TW" == Tom Wainwright <address@hidden> writes:

TW> Question 1: What is the difference between CImpl and Impl classes,
TW> and which should I be using in general??

With very few exceptions, you'll won't ever use `C' interfaces and
`CImpl' classes.  It's only when there are methods that need to be
called in order to set up the ultimately-instantiated object is it
that you'd use them.  The idea is that in some circumstances, figuring
out the structural aspects of an agent involves some rules, and that
these rules conceptually belong in method that isn't relevant once
the agent is up and running.

In some sense, this is an artifact of the original Swarm design.
These `phases' were intended to be a kind of runtime mixin
inheritance, and provide capabilities like C++ templates, except at
runtime.  The idea really never took off.  One reason it didn't, I
think, is because implementation of runtime templates is quite hairy
and requires runtime native code generation to provide practical
performance benefits.  Not worth it, at least in the context of
agent-based modeling and a small project like Swarm.  Now, about the
only benefit we get from phases is that it conceptually separates
methods for the formation of an agent from methods for operation of an agent
(and only those agents that are Swarms).

Anyway, the common case is that instantiating a class can be achieved using
just constructor arguments of the `using' (a.k.a. normal) Impl class.

TW> Apparently, the setPath method doesn't exist in LispArchiverImpl

Right, that's a create-time method -- it's gone once the object
has been created.

TW> Question 2: Can someone show me how to create an archiver and
TW> write to it?  I've managed to write to the global archivers, but I
TW> want to be able to save to a separate file.

The easiest way is to use the model's archiver.  You do that like:

    Globals.env.hdf5AppArchiver.putShallow$object ("someName", someObj);

Also, for any Archiver, whether Lisp or HDF5, you can force a flush to disk
with the sync method, e.g.:

    Globals.env.hdf5AppArchiver.sync ();
  
This is separate because sometimes you may want to batch a bunch of
`puts' together without it hitting disk in little (time consuming) chunks.

Along the lines of your example, here are several working example
blocks that create _new_ Archivers (as opposed to the standard
system-wide or model-wide ones with derived filenames).

     // simple put
     {
       Archiver archiver = new HDF5ArchiverImpl (getZone (), "test.hdf");
     
       archiver.putShallow$object ("heatbugList", heatbugList);
       archiver.sync ();
     }

     // simple get and put
     {
       Archiver archiver = new HDF5ArchiverImpl (getZone (), "test.hdf");
     
       List list = (List) archiver.getObject ("heatbugList");
 
       if (list != null)
         System.out.println (list.get (0));
 
       archiver.putShallow$object ("heatbugList", heatbugList);
       archiver.sync ();
     }

     // get and put with phases -- yes, this is complex
     // this approach is also not necessary or useful in this context
     {
       // the argument to the constructor is the class (e.g. set of methods)
       // that will be active when the object is ready for use
       HDF5ArchiverC archiverC =
         new HDF5ArchiverCImpl (new HDF5ArchiverImpl ());
       
       archiverC.createBegin (getZone ());
       archiverC.setPath ("test2.hdf");
 
       // createEnd returns objects of many kinds, thus the need for a cast
       // When the archiver is used, whether it is HDF5 or Lisp isn't
       // important, so use the parent interface.
       Archiver archiver = (Archiver) archiverC.createEnd ();
 
       // likewise, getObject can return objects of different types
       List list = (List) archiver.getObject ("heatbugList");
       if (list != null)
         System.out.println (list.get (0));
      
       archiver.putShallow$object ("heatbugList", heatbugList);
       archiver.sync ();
     }
     

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