[maglev-discussion] Persisting Ruby Modules?

13 views
Skip to first unread message

Conrad Taylor

unread,
Nov 8, 2011, 1:38:53 PM11/8/11
to maglev-d...@googlegroups.com
Hey ALL, what the proper way to persist a ruby module?  I was thinking that something like the following would do the job but appears that I'm missing something:

module SomeModule
 
  module ClassMethods
 
    ...
 
  end
 
  def self.included( klass )

    klass.extend ClassMethods

    Maglev::PERSISTENT_ROOT[ klass ] = Hash.new
 
    klass.maglev_persistable  # stage the class for persistence
 
    self.maglev_persistable  # stage the module for persistence
 
  end
 
end
Maglev.commit_transaction

-Conrad


Tim Felgentreff

unread,
Nov 8, 2011, 1:42:55 PM11/8/11
to maglev-d...@googlegroups.com
You might want to make the ClassMethods module persistable, too, also,
you can do that once, you don't have to do it everytime another class
includes them. Other than that, I don't see anything immediately
wrong, what's the error you are getting?

> --
> You received this message because you are subscribed to the Google Groups
> "MagLev Discussion" group.
> To post to this group, send email to maglev-d...@googlegroups.com.
> To unsubscribe from this group, send email to
> maglev-discuss...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/maglev-discussion?hl=en.
>

Peter McLain

unread,
Nov 8, 2011, 1:47:01 PM11/8/11
to maglev-d...@googlegroups.com
Classes and Modules need to be defined in persistent mode. Try wrapping your code in Maglev.persistent do ... end, or run maglev on the module definition file with the --commit option.

--
Peter McLain
pmc...@vmware.com


Jesse Cooke

unread,
Nov 8, 2011, 2:08:49 PM11/8/11
to maglev-d...@googlegroups.com
A while back I talked with Monty & Peter about this #maglev_persistable method & IIRC they didn't think it was the best idea to actually use it.
As Peter said, wrapping your code in a persistent_do block is preferred.

Conrad Taylor

unread,
Nov 8, 2011, 2:20:47 PM11/8/11
to maglev-d...@googlegroups.com
On Tue, Nov 8, 2011 at 11:08 AM, Jesse Cooke <je...@jc00ke.com> wrote:
On Tue, Nov 8, 2011 at 10:38 AM, Conrad Taylor <conr...@gmail.com> wrote:
Hey ALL, what the proper way to persist a ruby module?  I was thinking that something like the following would do the job but appears that I'm missing something:

module SomeModule
 
  module ClassMethods
 
    ...
 
  end
 
  def self.included( klass )

    klass.extend ClassMethods

    Maglev::PERSISTENT_ROOT[ klass ] = Hash.new
 
    klass.maglev_persistable  # stage the class for persistence
 
    self.maglev_persistable  # stage the module for persistence
A while back I talked with Monty & Peter about this #maglev_persistable method & IIRC they didn't think it was the best idea to actually use it.
As Peter said, wrapping your code in a persistent_do block is preferred.

Jesse, I really like the maglev_persistable because it doesn't require me to wrap all my ruby code.  Now, I guess the better method would be to follow Peter's recommendation to use the -Mcomment option:

$ maglev-ruby -Mcommit some_file.rb

Now, I guess that I'll go and update my blog post.

-Conrad

Conrad Taylor

unread,
Nov 8, 2011, 2:30:06 PM11/8/11
to maglev-d...@googlegroups.com
On Tue, Nov 8, 2011 at 10:47 AM, Peter McLain <pmc...@vmware.com> wrote:
Classes and Modules need to be defined in persistent mode.  Try wrapping your code in Maglev.persistent do ... end, or run maglev on the module definition file with the --commit option.


Peter, thanks for the information because the -Mcommit option worked great.  Also, the option provides a visual cue as to what action I'm really performing at the command line.  BTW, Maglev.persistent do ... end worked as well but I prefer the -Mcommit option because it allows my to easily test classes across Ruby implementations.

Thanks again,

-Conrad

Conrad Taylor

unread,
Nov 8, 2011, 2:40:15 PM11/8/11
to maglev-d...@googlegroups.com
On Tue, Nov 8, 2011 at 10:42 AM, Tim Felgentreff <timfelg...@gmail.com> wrote:
You might want to make the ClassMethods module persistable, too, also,
you can do that once, you don't have to do it everytime another class
includes them. Other than that, I don't see anything immediately
wrong, what's the error you are getting?


Tim, after running `maglev-ruby some_module.rb` from the command line, I was getting a NoMethodError.  Thus, you're correct in that ClassMethods was not being properly marked for persistent because I was marking the including class and the outer most module.  Now,
the option, -Mcommit, allows me to remove all the klass.maglev_persistable and self.maglev_persistable ruby statements as well as the Maglev.commit_transaction.  Now, I need to update a blog post with these corrections and additions.

Thanks for the info,

-Conrad

Peter McLain

unread,
Nov 8, 2011, 2:49:06 PM11/8/11
to maglev-d...@googlegroups.com
Hi Conrad,

I guess there is a bit of confusion (to which, I contributed).

In your example, which module did not get persisted? My comment assumed that it was SomeModule that wasn't persisted. But your code also tries to persist any class the mixes in SomeModule, so I'm not sure which Module/Class is not getting persisted.

For the code below to work, you'll certainly first need to ensure SomeModule is persisted, and that is NOT being done by the code below. (more comments below).

> On Tue, Nov 8, 2011 at 11:08 AM, Jesse Cooke <je...@jc00ke.com> wrote:
> On Tue, Nov 8, 2011 at 10:38 AM, Conrad Taylor <conr...@gmail.com> wrote:
> Hey ALL, what the proper way to persist a ruby module? I was thinking that something like the following would do the job but appears that I'm missing something:
>
> module SomeModule
>
> module ClassMethods
>
> ...
>
> end
>
> def self.included( klass )
>
> klass.extend ClassMethods
>
> Maglev::PERSISTENT_ROOT[ klass ] = Hash.new
>
> klass.maglev_persistable # stage the class for persistence
>
> self.maglev_persistable # stage the module for persistence

> A while back I talked with Monty & Peter about this #maglev_persistable method & IIRC they didn't think it was the best idea to actually use it.
> As Peter said, wrapping your code in a persistent_do block is preferred.
>
> Jesse, I really like the maglev_persistable because it doesn't require me to wrap all my ruby code. Now, I guess the better method would be to follow Peter's recommendation to use the -Mcomment option:

This deceptively simple example is actually getting a bit complex. My comment about --commit would apply to making SomeModule persistent. That's ok. But SomeModule is doing a lot of tricky things, and I'm not sure there all in the correct order (yet)! I haven't had time to really think this one through or run any code, but here are a couple of concerns I have:

1. You are doing "klass.extend ClassMethods" *before* you make klass persistent.
2. The klass.extend probably needs to in the persistent block
3. There is no check to see if klass is *already* persistent
4. There is no guarantee that all of klass's ancestors are persistent.
5. Looks like the self.maglev_persistable will mark SomeModule persistable *each* time it gets mixed in

Something like the following totally un-parsed, un-run, un-tested code might work better:

def self.included(klass)
Maglev.persistent do
klass.maglev_persistable
klass.extend ClassMethods
# etc.
end
# at this point, the persistence is staged, but not committed.
end

Stepping back a bit, I'm wondering whether the whole endeavour is too clever by half. Smalltalk is easy: *everything* is persistent. In MagLev, for better or worse, we decided that you'd have to explicitly manage persistent classes (the idea being not all code *should* be persistent). Persistence is a powerful hammer, but the MagLev team, with advice from the Smalltalk GreyBeards, thought it would be wise for only carefully selected classes to be persistent in MagLev (basically, your domain model...the things that would have been candidates for ActiveRecord: see https://github.com/MagLev/maglev/blob/master/docs/persistence-api.rdoc). Doing a bunch of Metaprogramming with persistence is wielding two very powerful swords... I'm not trying to say you shouldn't try what your doing, just that we hand't envisioned such potentially un-restrained application of persistence to classes. But its good to see people playing with MagLev, and perhaps we can work out the kinks here and we'll find it's a great combination!

--
Peter McLain
pmc...@vmware.com


Charles Monteiro

unread,
Nov 8, 2011, 3:07:41 PM11/8/11
to maglev-d...@googlegroups.com
So , newbie question again, persisting classes / modules is done for the purposes of making said behavior available i.e. server based (MagLev based) ?

tia

-Charles

--
You received this message because you are subscribed to the Google Groups "MagLev Discussion" group.
To post to this group, send email to maglev-d...@googlegroups.com.
To unsubscribe from this group, send email to maglev-discuss...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/maglev-discussion?hl=en.




--
Charles A. Monteiro
www.monteirosfusion.com
sent from the road

Jesse Cooke

unread,
Nov 8, 2011, 3:17:18 PM11/8/11
to maglev-d...@googlegroups.com
Yeah. One way to think of persisting is multiple VMs can access the same code without explicitly loading it.
Once code is persisted, it is available to any connected VM without that VM actually loading that code.
Kinda like data in a normal database, once it's in the Gemstone repository it's available to any instance that connects in the future.

--------------------------------------------
Jesse Cooke :: N-tier Engineer
jc00ke.com / @jc00ke

Peter McLain

unread,
Nov 8, 2011, 3:26:27 PM11/8/11
to maglev-d...@googlegroups.com

On Nov 8, 2011, at 12:17 PM, Jesse Cooke wrote:

> Yeah. One way to think of persisting is multiple VMs can access the same code without explicitly loading it.

> On Tue, Nov 8, 2011 at 12:07 PM, Charles Monteiro <cha...@nycsmalltalk.org> wrote:


> So , newbie question again, persisting classes / modules is done for the purposes of making said behavior available i.e. server based (MagLev based) ?

There are at least two big reasons to persist code:

1. As Jesse said, a reason to persist classes is to get code loaded and shared across VMs.

2. Another reason is to get your *data* saved (your domain model). E.g., instead of persisting rows in a Customer table in MySQL, you can create a persistent Customer class (a plain-old ruby class), and you persist Customer objects. Along with those objects, will be the class and the behavior. It's just all OO modeling and no ORM mapping pain. You'll want to collect your customers into some collection, and probably index them for faster search (MagLev supports indexing, just like an RDBMS would). See https://github.com/MagLev/maglev/blob/master/examples/persistence/indexing/Indexing-README.rdoc

--
Peter McLain
pmc...@vmware.com


Charles Monteiro

unread,
Nov 8, 2011, 3:45:11 PM11/8/11
to maglev-d...@googlegroups.com
well, then kind of the way Gemstone / S works .

What I'm hoping is that my experiences with Gemstone / S will help me get past the learning curb of MagLev i.e. how much of the design , how things work in general is based on Gemstone/ S ? i.e. do we think of application partitioning things in the same way,. also are there concepts such as forwarders, replicationSpecs, stubbing etc

How about the admin of MagLev ? Is that like Gemstone/ S ?

Where are the docs ?

Honestly, I'm starting to get a bit excited. Granted I rather still do most things in Smalltalk and with Gemstone / S , but to have access to something that works the same way-ish, has the same scaling properties etc with a language that is not half bad, gives me hope. Although I still think that overall Seaside is a better web framework than Rails , then again MagLev is not limited in its use to a specific presentation framework. But I ramble ...

Adrian Madrid

unread,
Nov 8, 2011, 4:06:58 PM11/8/11
to maglev-d...@googlegroups.com
How does it work? Let's say I persist a new copy of a class Person. Do all running VMs start using the new code automagically or do I need to restart those VMs?


Adrian Madrid
aema...@gmail.com




--
Peter McLain
pmc...@vmware.com




Jesse Cooke

unread,
Nov 8, 2011, 4:09:37 PM11/8/11
to maglev-d...@googlegroups.com
On Tue, Nov 8, 2011 at 1:06 PM, Adrian Madrid <aema...@gmail.com> wrote:
How does it work? Let's say I persist a new copy of a class Person. Do all running VMs start using the new code automagically or do I need to restart those VMs?
When those VMs run a Maglev.abort_transaction, then yes, they'll see the changes. If you haven't already, check out & run the hat trick example

aemadrid

unread,
Nov 8, 2011, 4:21:24 PM11/8/11
to maglev-d...@googlegroups.com
That makes sense. I can plan then when/where I want to get new releases of my (running) code.

Peter McLain

unread,
Nov 8, 2011, 4:27:30 PM11/8/11
to maglev-d...@googlegroups.com

On Nov 8, 2011, at 12:45 PM, Charles Monteiro wrote:

> What I'm hoping is that my experiences with Gemstone / S will help me get past the learning curb of MagLev i.e. how much of the design , how things work in general is based on Gemstone/ S ? i.e. do we think of application partitioning things in the same way,. also are there concepts such as forwarders, replicationSpecs, stubbing etc

The underlying processes (stone, vm etc.) and architecture (shared page cache) are the same. Some of the details you mention (e.g., forwarders and in general the way Smalltalk deals with migration) are Smalltalk specific. See the api persistence doc in $MAGLEV_HOME/docs for more details on the differences between ruby and smalltalk here. You also have access to all of the Smalltalk objects too! See https://github.com/MagLev/maglev/blob/master/docs/ruby_and_smalltalk.rdoc

> How about the admin of MagLev ? Is that like Gemstone/ S ?

In fact, we recommend reading the GemStone/S docs for details on admin of the stone, vm etc. (http://maglev.github.com/docs/further_reading.html).

> Where are the docs ?

$MAGLEV_HOME/docs and we are starting to fill out the documentation section of http://maglev.github.com/ The examples directory has good stuff as well.

--
Peter McLain
pmc...@vmware.com


Charles A. Monteiro

unread,
Nov 8, 2011, 4:29:04 PM11/8/11
to MagLev Discussion
but how is schema migration handled ? i.e. you may have persisted
object instances under a prior object schema (set of instVars )

Jesse Cooke

unread,
Nov 8, 2011, 4:31:44 PM11/8/11
to maglev-d...@googlegroups.com
On Tue, Nov 8, 2011 at 1:29 PM, Charles A. Monteiro <charles....@gmail.com> wrote:
but how is schema migration handled ? i.e. you may have persisted
object instances under a prior object schema (set of instVars )
True! Peter had written up some ideas on migrations, which can be found in the examples/persistence/migrations dir. 

On Nov 8, 4:21 pm, aemadrid <aemad...@gmail.com> wrote:
> That makes sense. I can plan then when/where I want to get new releases of
> my (running) code.

--
You received this message because you are subscribed to the Google Groups "MagLev Discussion" group.

Conrad Taylor

unread,
Nov 8, 2011, 4:48:49 PM11/8/11
to maglev-d...@googlegroups.com, maglev-d...@googlegroups.com

Sent from my iPhone

On Nov 8, 2011, at 11:49 AM, Peter McLain <pmc...@vmware.com> wrote:

> Hi Conrad,
>
> I guess there is a bit of confusion (to which, I contributed).
>
> In your example, which module did not get persisted? My comment assumed that it was SomeModule that wasn't persisted. But your code also tries to persist any class the mixes in SomeModule, so I'm not sure which Module/Class is not getting persisted.

Peter, the SomeModule is not being persisted.

>
> For the code below to work, you'll certainly first need to ensure SomeModule is persisted, and that is NOT being done by the code below. (more comments below).
>
>> On Tue, Nov 8, 2011 at 11:08 AM, Jesse Cooke <je...@jc00ke.com> wrote:
>> On Tue, Nov 8, 2011 at 10:38 AM, Conrad Taylor <conr...@gmail.com> wrote:
>> Hey ALL, what the proper way to persist a ruby module? I was thinking that something like the following would do the job but appears that I'm missing something:
>>
>> module SomeModule
>>
>> module ClassMethods
>>
>> ...
>>
>> end
>>
>> def self.included( klass )
>>
>> klass.extend ClassMethods
>>
>> Maglev::PERSISTENT_ROOT[ klass ] = Hash.new
>>
>> klass.maglev_persistable # stage the class for persistence
>>
>> self.maglev_persistable # stage the module for persistence
>
>> A while back I talked with Monty & Peter about this #maglev_persistable method & IIRC they didn't think it was the best idea to actually use it.
>> As Peter said, wrapping your code in a persistent_do block is preferred.
>>
>> Jesse, I really like the maglev_persistable because it doesn't require me to wrap all my ruby code. Now, I guess the better method would be to follow Peter's recommendation to use the -Mcomment option:
>
> This deceptively simple example is actually getting a bit complex. My comment about --commit would apply to making SomeModule persistent. That's ok. But SomeModule is doing a lot of tricky things, and I'm not sure there all in the correct order (yet)! I haven't had time to really think this one through or run any code, but here are a couple of concerns I have:
>
> 1. You are doing "klass.extend ClassMethods" *before* you make klass persistent.

I was thinking that

> 2. The klass.extend probably needs to in the persistent block
> 3. There is no check to see if klass is *already* persistent

There are two possible cases here I believe:

1) I want to update a persistent class
or module.

2) I want to mixin a module into
another class or module.

Given the above to cases, what's the best way to do this?

> 4. There is no guarantee that all of klass's ancestors are persistent.

How does one make this guarantee?

> 5. Looks like the self.maglev_persistable will mark SomeModule persistable *each* time it gets mixed in
>
> Something like the following totally un-parsed, un-run, un-tested code might work better:
>
> def self.included(klass)
> Maglev.persistent do
> klass.maglev_persistable
> klass.extend ClassMethods
> # etc.
> end
> # at this point, the persistence is staged, but not committed.
> end
>
> Stepping back a bit, I'm wondering whether the whole endeavour is too clever by half. Smalltalk is easy: *everything* is persistent. In MagLev, for better or worse, we decided that you'd have to explicitly manage persistent classes (the idea being not all code *should* be persistent). Persistence is a powerful hammer, but the MagLev team, with advice from the Smalltalk GreyBeards, thought it would be wise for only carefully selected classes to be persistent in MagLev (basically, your domain model...the things that would have been candidates for ActiveRecord: see https://github.com/MagLev/maglev/blob/master/docs/persistence-api.rdoc).

Yes, I agree with you a 100%. I would like to persist data access objects or objects that are used for my data access layer.

> Doing a bunch of Metaprogramming with persistence is wielding two very powerful swords... I'm not trying to say you shouldn't try what your doing, just that we hand't envisioned such potentially un-restrained application of persistence to classes. But its good to see people playing with MagLev, and perhaps we can work out the kinks here and we'll find it's a great combination!

I'm playing with the ability to easily mixin Maglev by isolating it from the class that it is being mixed into. Just playing around.

-Conrad

>
> --
> Peter McLain
> pmc...@vmware.com

Charles Monteiro

unread,
Nov 8, 2011, 5:01:30 PM11/8/11
to maglev-d...@googlegroups.com
but in Smalltalk , not everything had to be persisted , I could have had VW only classes for example. and btw , Smalltalk Graybeards :) , cute .

On Tue, Nov 8, 2011 at 4:48 PM, Conrad Taylor <conr...@gmail.com> wrote:


Sent from my iPhone

On Nov 8, 2011, at 11:49 AM, Peter McLain <pmc...@vmware.com> wrote:

> Hi Conrad,
>
> áI guess there is a bit of confusion (to which, I contributed).
>
> áIn your example, which module did not get persisted? áMy comment assumed that it was SomeModule that wasn't persisted. áBut your code also tries to persist any class the mixes in SomeModule, so I'm not sure which Module/Class is not getting persisted.

Peter, the SomeModule is not being persisted.

>
> áFor the code below to work, you'll certainly first need to ensure SomeModule is persisted, and that is NOT being done by the code below. á(more comments below).

>
>> On Tue, Nov 8, 2011 at 11:08 AM, Jesse Cooke <je...@jc00ke.com> wrote:
>> On Tue, Nov 8, 2011 at 10:38 AM, Conrad Taylor <conr...@gmail.com> wrote:
>> Hey ALL, what the proper way to persist a ruby module? áI was thinking that something like the following would do the job but appears that I'm missing something:
>>
>> module SomeModule
>>
>> ámodule ClassMethods
>>
>> á á...
>>
>> áend
>>
>> ádef self.included( klass )
>>
>> á áklass.extend ClassMethods
>>
>> á áMaglev::PERSISTENT_ROOT[ klass ] = Hash.new
>>
>> á áklass.maglev_persistable á# stage the class for persistence
>>
>> á áself.maglev_persistable á# stage the module for persistence

>
>> A while back I talked with Monty & Peter about this #maglev_persistable method & IIRC they didn't think it was the best idea to actually use it.
>> As Peter said, wrapping your code in a persistent_do block is preferred.
>>
>> Jesse, I really like the maglev_persistable because it doesn't require me to wrap all my ruby code. áNow, I guess the better method would be to follow Peter's recommendation to use the -Mcomment option:
>
> áThis deceptively simple example is actually getting a bit complex. áMy comment about --commit would apply to making SomeModule persistent. áThat's ok. áBut SomeModule is doing a lot of tricky things, and I'm not sure there all in the correct order (yet)! áI haven't had time to really think this one through or run any code, but here are a couple of concerns I have:
>
> á1. You are doing "klass.extend ClassMethods" *before* you make klass persistent.

I was thinking that

> á2. The klass.extend probably needs to in the persistent block
> á3. There is no check to see if klass is *already* persistent

There are two possible cases here I believe:

1) I want to update a persistent class
á á or module.


2) I want to mixin a module into
á á another class or module.


Given the above to cases, what's the best way to do this?

> á4. There is no guarantee that all of klass's ancestors are persistent.

How does one make this guarantee?

> á5. Looks like the self.maglev_persistable will mark SomeModule persistable *each* time it gets mixed in

>
> Something like the following totally un-parsed, un-run, un-tested code might work better:
>
> á ádef self.included(klass)
> á á áMaglev.persistent do
> á á á áklass.maglev_persistable
> á á á áklass.extend ClassMethods
> á á á á# etc.
> á á áend
> á á á# at this point, the persistence is staged, but not committed.
> á áend
>
> Stepping back a bit, I'm wondering whether the whole endeavour is too clever by half. áSmalltalk is easy: *everything* is persistent. áIn MagLev, for better or worse, we decided that you'd have to explicitly manage persistent classes (the idea being not all code *should* be persistent). áPersistence is a powerful hammer, but the MagLev team, with advice from the Smalltalk GreyBeards, thought it would be wise for only carefully selected classes to be persistent in MagLev (basically, your domain model...the things that would have been candidates for ActiveRecord: see https://github.com/MagLev/maglev/blob/master/docs/persistence-api.rdoc).

Yes, I agree with you a 100%. áI would like to persist data access objects or objects that are used for my data access layer.

> Doing a bunch of Metaprogramming with persistence is wielding two very powerful swords... I'm not trying to say you shouldn't try what your doing, just that we hand't envisioned such potentially un-restrained application of persistence to classes. áBut its good to see people playing with MagLev, and perhaps we can work out the kinks here and we'll find it's a great combination!

I'm playing with the ability to easily mixin Maglev by isolating it from the class that it is being mixed into. áJust playing around.


-Conrad

>
> --
> Peter McLain
> pmc...@vmware.com
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups "MagLev Discussion" group.
> To post to this group, send email to maglev-d...@googlegroups.com.
> To unsubscribe from this group, send email to maglev-discuss...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/maglev-discussion?hl=en.
>

--
You received this message because you are subscribed to the Google Groups "MagLev Discussion" group.
To post to this group, send email to maglev-d...@googlegroups.com.
To unsubscribe from this group, send email to maglev-discuss...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/maglev-discussion?hl=en.

Michael Latta

unread,
Nov 8, 2011, 5:43:27 PM11/8/11
to maglev-d...@googlegroups.com
In maglev you can run entirely with VM resident classes if you choose.  If you persist data the classes need to be persistent.  Not all your classes need to be.  In a Rails app only the Model equivalent classes need be persistent.  the controller and view classes would stay VM resident in most cases.  There may be a reason to persist them to speed up VM startup or such but that would be an optimization for performance.  Since there are no instances that live past a request there would be no other point.  On the other hand you could attach view/controller objects to the session and move from a stateless to a statefull application which would be an interesting use case.  Of course the part of Rails that creates new controller instances would need to be patched to look for one on the session, but being Rails where monkey patching is possible, and given that Rails 3 is much better structured where it may not even go that far, there are many options to play with if you choose.

Michael

Jesse Cooke

unread,
Nov 8, 2011, 5:49:27 PM11/8/11
to maglev-d...@googlegroups.com
On Tue, Nov 8, 2011 at 2:43 PM, Michael Latta <mla...@technomage.com> wrote:
In maglev you can run entirely with VM resident classes if you choose.  If you persist data the classes need to be persistent.  Not all your classes need to be.  In a Rails app only the Model equivalent classes need be persistent.  the controller and view classes would stay VM resident in most cases.  There may be a reason to persist them to speed up VM startup or such but that would be an optimization for performance.  Since there are no instances that live past a request there would be no other point.  On the other hand you could attach view/controller objects to the session and move from a stateless to a statefull application which would be an interesting use case.  Of course the part of Rails that creates new controller instances would need to be patched to look for one on the session, but being Rails where monkey patching is possible, and given that Rails 3 is much better structured where it may not even go that far, there are many options to play with if you choose.

There may be other classes that need to get persisted. This is something we looked into before. Take, for instance, if you have a User class that mixes in Devise. If you want to persist users you'd have to persist Devise, which depends on bcypt, etc. You can quickly end up persisting more than you want. It will be very interesting to find these cases as more people use MagLev. 

Michael Latta

unread,
Nov 8, 2011, 5:56:51 PM11/8/11
to maglev-d...@googlegroups.com
I agree that some frameworks like Devise make undue assumptions about the environment and as a result place more logic in the model classes than they should.  It will be interesting to see how much people fix those problems or just avoid those frameworks for use with Maglev.  In the case of devise it is trying to manage persistence requirements and mix in the API for accessing those along with some logic.  it should not be hard to separate out the concerns and only persist classes/modules that really belong there and use a proxy object to connect Devise and Maglev.  The great thing about duck typing is that even though Devise thinks it is talking to the persistent User object you can always insert a facade object to isolate the persistence from the API.

Michael
Reply all
Reply to author
Forward
0 new messages