From dean at aspectprogramming.com Mon Feb 25 22:34:24 2008 From: dean at aspectprogramming.com (Dean Wampler) Date: Mon, 25 Feb 2008 21:34:24 -0600 Subject: [Aquarium-users] V0.4.0 Released Message-ID: <2F92DC82-A552-4289-9240-01A46E7390C9@aspectprogramming.com> Greeting, I just released V0.4.0, which adds support for JRuby. Not only do the regular "pure Ruby" Aquarium specs run reliably under JRuby (V1.1RC2), but you can now advise Java types with Aquarium! There are some *important* limitations, though. Cartographers of old would mark dangerous or unknown sections of their maps with "hic sunt dracones" (here be dragons), a reference to the practice of adorning ornate maps with serpents around the edges. This is true of Aqurium + Java types in JRuby, too, at least currently. See the details here: http://aquarium.rubyforge.org/jruby.html Yours, dean Dean Wampler, Ph.D. dean at objectmentor.com http://www.objectmentor.com See also: http://www.aspectprogramming.com AOP advocacy site http://aquarium.rubyforge.org AOP for Ruby http://www.contract4j.org Design by Contract for Java5 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/aquarium-users/attachments/20080225/8467b20b/attachment.html From mvyver at gmail.com Thu Feb 28 00:08:52 2008 From: mvyver at gmail.com (Mark Van De Vyver) Date: Thu, 28 Feb 2008 16:08:52 +1100 Subject: [Aquarium-users] Aquarium: around classes and descendants Message-ID: <389c43e40802272108q79ab84b6h731cbe38723a4edb@mail.gmail.com> Hi, Can anyone shed light on what I'm doing wrong in the attached minimal example. What I see is: "Initializing MyModule::OtherModule::MyDescendant ancestor" "Initializing MyModule::OtherModule::MyDescendant" W, [2008-02-28T16:02:04.641217 #11518] WARN -- : Warning: No join points were matched. The options specified were [:around, {:classes_and_descendents=>MyModule::OtherModule::Abstract, :in_objects=>MyModule::OtherModule, :default_objects=>MyModule::MyClass, :calls_to=>:initialize}]. What I expected to se was somthing like: Entering.... "Initializing MyModule::OtherModule::MyDescendant ancestor" Leaving... We really should see this: .... Entering.... "Initializing MyModule::OtherModule::MyDescendant" Leaving... We really should see this:.... A follow-up question would be: Is it possible to invoke only around the descendants and not the Ancestor/Abstract's initialize? Appreciate any tips. -------------- next part -------------- A non-text attachment was scrubbed... Name: scratch.rb Type: application/x-ruby Size: 1127 bytes Desc: not available Url : http://rubyforge.org/pipermail/aquarium-users/attachments/20080228/fe05f13a/attachment-0001.bin From mvyver at gmail.com Thu Feb 28 01:28:56 2008 From: mvyver at gmail.com (Mark Van De Vyver) Date: Thu, 28 Feb 2008 17:28:56 +1100 Subject: [Aquarium-users] Aquarium: around classes and descendants In-Reply-To: <389c43e40802272108q79ab84b6h731cbe38723a4edb@mail.gmail.com> References: <389c43e40802272108q79ab84b6h731cbe38723a4edb@mail.gmail.com> Message-ID: <389c43e40802272228k23c317e5g22ed7c7afe85d91@mail.gmail.com> Hi, I've made some progress to get to where I wanted... see the attached. Essentially I wanted to be able to pass an instance of the 'observed' class to instance methods of the 'observing' class. The attached shows how I did this. One note is that if we replace self.new with self.initialize in the 'after' stanza then an exception is raised. Is this a bug? All that remains is to see if I can place the aspect around descendants of a class and not the parent class itself.... is this possible? Thanks Mark On Thu, Feb 28, 2008 at 4:08 PM, Mark Van De Vyver wrote: > Hi, > Can anyone shed light on what I'm doing wrong in the attached minimal example. > > What I see is: > > "Initializing MyModule::OtherModule::MyDescendant ancestor" > "Initializing MyModule::OtherModule::MyDescendant" > W, [2008-02-28T16:02:04.641217 #11518] WARN -- : Warning: No join > points were matched. The options specified were [:around, > {:classes_and_descendents=>MyModule::OtherModule::Abstract, > :in_objects=>MyModule::OtherModule, > :default_objects=>MyModule::MyClass, :calls_to=>:initialize}]. > > What I expected to se was somthing like: > > Entering.... > "Initializing MyModule::OtherModule::MyDescendant ancestor" > Leaving... > We really should see this: .... > Entering.... > "Initializing MyModule::OtherModule::MyDescendant" > Leaving... > We really should see this:.... > > > A follow-up question would be: > Is it possible to invoke only around the descendants and not the > Ancestor/Abstract's initialize? > > Appreciate any tips. > -------------- next part -------------- A non-text attachment was scrubbed... Name: scratch.rb Type: application/x-ruby Size: 1380 bytes Desc: not available Url : http://rubyforge.org/pipermail/aquarium-users/attachments/20080228/9bdd5412/attachment.bin From mvyver at gmail.com Thu Feb 28 01:45:26 2008 From: mvyver at gmail.com (Mark Van De Vyver) Date: Thu, 28 Feb 2008 17:45:26 +1100 Subject: [Aquarium-users] Aquarium: around classes and descendants In-Reply-To: <389c43e40802272228k23c317e5g22ed7c7afe85d91@mail.gmail.com> References: <389c43e40802272108q79ab84b6h731cbe38723a4edb@mail.gmail.com> <389c43e40802272228k23c317e5g22ed7c7afe85d91@mail.gmail.com> Message-ID: <389c43e40802272245g696de7a6le861dff7b733f04e@mail.gmail.com> On Thu, Feb 28, 2008 at 5:28 PM, Mark Van De Vyver wrote: > Hi, > I've made some progress to get to where I wanted... see the attached. Spoke too soon.... to get the behavior I'd like it is neccessary to insert a 'non-standard' self at the end of the observed class' initialize method. Is this intended behavior? Another revised version is attached that illustrates a use-case that might not be too unusual: - initialize an instance of the 'observing' class before initializing the 'observed' class. - pass the observed instance to the observer instance. - invoke some observer instance methods. HTH? Mark > Essentially I wanted to be able to pass an instance of the 'observed' > class to instance methods of the 'observing' class. > The attached shows how I did this. > > One note is that if we replace self.new with self.initialize in the > 'after' stanza then an exception is raised. > Is this a bug? > > All that remains is to see if I can place the aspect around > descendants of a class and not the parent class itself.... is this > possible? > > Thanks > Mark > > > > > > > On Thu, Feb 28, 2008 at 4:08 PM, Mark Van De Vyver wrote: > > Hi, > > Can anyone shed light on what I'm doing wrong in the attached minimal example. > > > > What I see is: > > > > "Initializing MyModule::OtherModule::MyDescendant ancestor" > > "Initializing MyModule::OtherModule::MyDescendant" > > W, [2008-02-28T16:02:04.641217 #11518] WARN -- : Warning: No join > > points were matched. The options specified were [:around, > > {:classes_and_descendents=>MyModule::OtherModule::Abstract, > > :in_objects=>MyModule::OtherModule, > > :default_objects=>MyModule::MyClass, :calls_to=>:initialize}]. > > > > What I expected to se was somthing like: > > > > Entering.... > > "Initializing MyModule::OtherModule::MyDescendant ancestor" > > Leaving... > > We really should see this: .... > > Entering.... > > "Initializing MyModule::OtherModule::MyDescendant" > > Leaving... > > We really should see this:.... > > > > > > A follow-up question would be: > > Is it possible to invoke only around the descendants and not the > > Ancestor/Abstract's initialize? > > > > Appreciate any tips. > > > -------------- next part -------------- A non-text attachment was scrubbed... Name: scratch.rb Type: application/x-ruby Size: 1441 bytes Desc: not available Url : http://rubyforge.org/pipermail/aquarium-users/attachments/20080228/5524df13/attachment.bin From dean at aspectprogramming.com Thu Feb 28 10:44:16 2008 From: dean at aspectprogramming.com (Dean Wampler) Date: Thu, 28 Feb 2008 09:44:16 -0600 Subject: [Aquarium-users] Aquarium: around classes and descendants In-Reply-To: <389c43e40802272245g696de7a6le861dff7b733f04e@mail.gmail.com> References: <389c43e40802272108q79ab84b6h731cbe38723a4edb@mail.gmail.com> <389c43e40802272228k23c317e5g22ed7c7afe85d91@mail.gmail.com> <389c43e40802272245g696de7a6le861dff7b733f04e@mail.gmail.com> Message-ID: <8969AF02-AC3A-4F0A-A45E-598A24433F8C@aspectprogramming.com> Hi, Mark, I found a bug looking at this example :( and two cases where Aquarium should provide warnings. I've attached my version and I'll post the appropriate bug and feature requests to trac. If you use :exclude_classes => ::MyModule::OtherModule::Abstract, it will bypass this parent module and only advise the descendents, as you desire. Your initialize needed to return "self"; otherwise it would return the result of the print statement, which is nil. The better way to handle this case is to ignore the return value of initialize, as returned by "proceed", and instead simply assign "object" (one of the advice block's parameters) to your @observed_instance. It is standard Ruby behavior for "new" to ignore the return value of initialize, so this is a more "robust" approach. One thing to be careful about is the return value of around advice. Normally, you would capture the value returned by "proceed" and return that at the end of the advice. So, you could add "mc.observed_instance" or "object" at the end of the advice. However, for reasons I just mentioned, this isn't necessary when advising initialize methods. Here's the most curious thing about your example; the ":in_objects" you passed masked a bug, but didn't actually match any join points as you intended. First, I need to add a warning that you should only use this flag with instances of a class and never with a type. Yes, types are Objects, but using this flag this way could lead to confusing behavior with the metamodel. I need to add a warning against doing this. In your case, this flag actually matched no join points, because there is no initialize method on types themselves, just instances of them. I need to add a warning when any explicitly-specified types or objects don't actually match any join points. (You do get warned if nothing at all matches.) Note that I added print statements to show the "specification" (computed from the inputs) and what join points got matched. However, this flag did work around a bug! There is a provision in Aquarium that if you embed an aspect in a type, as here, it will use as a "default object" instances of that type. This is so you don't have to explicitly name the type when writing advise like this: class Foo ... # The following 2 after statements are equivalent: # after :calls_to => :initialize, :in_type => Foo do; ...; end after :calls_to => :initialize do; ...; end ... end Unfortunately, it appears that aquarium is still trying to advise this "hidden" default object (you can see it actually in the specification). I noticed the bug when I added the print join points statement AFTER commenting out your ":in_objects", which I thought was doing nothing. In fact, that option suppressed the default object feature. When I removed your flag, Aquarium advised this object, even though other TYPES where specified, and that actually leads to an infinite recursion when the advice runs! One workaround is to add MyClass to the list of excluded types, as shown (until I fix this bug). Another workaround is to move the aspect creation outside of MyClass. Sorry for the long-winded reply, but you've showed me ways to make Aquarium better! dean On Feb 28, 2008, at 12:45 AM, Mark Van De Vyver wrote: > On Thu, Feb 28, 2008 at 5:28 PM, Mark Van De Vyver > wrote: >> Hi, >> I've made some progress to get to where I wanted... see the attached. > > Spoke too soon.... to get the behavior I'd like it is neccessary to > insert a 'non-standard' self at the end of the observed class' > initialize method. > Is this intended behavior? > > Another revised version is attached that illustrates a use-case that > might not be too unusual: > - initialize an instance of the 'observing' class before initializing > the 'observed' class. > - pass the observed instance to the observer instance. > - invoke some observer instance methods. > > HTH? > Mark > > >> Essentially I wanted to be able to pass an instance of the 'observed' >> class to instance methods of the 'observing' class. >> The attached shows how I did this. >> >> One note is that if we replace self.new with self.initialize in the >> 'after' stanza then an exception is raised. >> Is this a bug? >> >> All that remains is to see if I can place the aspect around >> descendants of a class and not the parent class itself.... is this >> possible? >> >> Thanks >> Mark >> >> >> >> >> >> >> On Thu, Feb 28, 2008 at 4:08 PM, Mark Van De Vyver >> wrote: >>> Hi, >>> Can anyone shed light on what I'm doing wrong in the attached >>> minimal example. >>> >>> What I see is: >>> >>> "Initializing MyModule::OtherModule::MyDescendant ancestor" >>> "Initializing MyModule::OtherModule::MyDescendant" >>> W, [2008-02-28T16:02:04.641217 #11518] WARN -- : Warning: No join >>> points were matched. The options specified were [:around, >>> {:classes_and_descendents=>MyModule::OtherModule::Abstract, >>> :in_objects=>MyModule::OtherModule, >>> :default_objects=>MyModule::MyClass, :calls_to=>:initialize}]. >>> >>> What I expected to se was somthing like: >>> >>> Entering.... >>> "Initializing MyModule::OtherModule::MyDescendant ancestor" >>> Leaving... >>> We really should see this: .... >>> Entering.... >>> "Initializing MyModule::OtherModule::MyDescendant" >>> Leaving... >>> We really should see this:.... >>> >>> >>> A follow-up question would be: >>> Is it possible to invoke only around the descendants and not the >>> Ancestor/Abstract's initialize? >>> >>> Appreciate any tips. >>> >> > _______________________________________________ > Aquarium-users mailing list > Aquarium-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/aquarium-users Dean Wampler, Ph.D. dean at objectmentor.com http://www.objectmentor.com See also: http://www.aspectprogramming.com AOP advocacy site http://aquarium.rubyforge.org AOP for Ruby http://www.contract4j.org Design by Contract for Java5 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/aquarium-users/attachments/20080228/ca988202/attachment-0002.html -------------- next part -------------- A non-text attachment was scrubbed... Name: scratch.rb Type: text/x-ruby-script Size: 2914 bytes Desc: not available Url : http://rubyforge.org/pipermail/aquarium-users/attachments/20080228/ca988202/attachment-0001.bin -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/aquarium-users/attachments/20080228/ca988202/attachment-0003.html