From mike at planetmcd.com Fri Mar 16 01:33:15 2012 From: mike at planetmcd.com (Michael McDermott) Date: Thu, 15 Mar 2012 21:33:15 -0400 Subject: [Aquarium-users] Problem with Aspect/pointcut code not firing Message-ID: Hello, I'm not sure if this group is still active and I sent this once, but I think before I was approved to be on the list. Sorry if this is a duplicate. If it is still active, I've been inspired by Mr. Wampler's talk about using Polyglot/AOP to rid Ruby programming of logging/exception handling clutter. I was writing a test class to deploy as a job inside of the Torquebox Jruby server: ## test.rb require 'rubygems' require 'logger' require 'aquarium' module Aquarium module Reusables module TraceMethods def self.append_features mod Aquarium::Aspects::Aspect.new :before, :type => mod, :methods => :all, :method_options => [:exclude_ancestor_methods] do |jp, object, *args| names = "#{jp.target_type.name}##{jp.method_name}" p "Entering: #{names}: args = #{args.inspect}" # jp.proceed # p "Leaving: #{names}: args = #{args.inspect}" end end end end end class TestJob # include Aquarium::DSL attr_accessor :log def initialize @log = Logger.new(STDOUT) @log.level = Logger::DEBUG @log.info("Initialized") end def run() @log.info("I ran: #{test1("test1")}: #{test2}") end def test1(val) val end def test2 "test2" end include Aquarium::Reusables::TraceMethods end When I run it in Torquebox, the aspects "fire" on the first calls to the run method and then do not. When I try it in jirb, everything seems to work just fine until I change the class a bit and then load it again. At this point when I instantiate a new instance, it seems to have lost the aspect component. I've tried several iterations with the DSL as well and all exibit the same behavior on multiple versions of Jruby. I suspect I am not understanding something and have set things up incorrectly. Any advice would be appreciated. Best, Mike From deanwampler at gmail.com Fri Mar 16 04:11:43 2012 From: deanwampler at gmail.com (Dean Wampler) Date: Thu, 15 Mar 2012 23:11:43 -0500 Subject: [Aquarium-users] Problem with Aspect/pointcut code not firing In-Reply-To: References: Message-ID: Hi Michael, I have not actively worked on Aquarium in a while, but I can offer a few suggestions. First, it has bugs on Ruby 1.9, although I believe that most of those relate to attempts to remove advice from objects. I don't know why the aspects fire just once. Could it be that that you see the aspect output whe you modify the class and not when it's methods are executed? I think I know what might happen in the second problem. Aquarium has a limitation that it only affects objects and types already loaded. It doesn't "watch" for new types or changes. I'll try your example myself tomorrow to see if I can figure out any more details. Dean Sent from my iPad On Mar 15, 2012, at 8:33 PM, Michael McDermott wrote: > Hello, > I'm not sure if this group is still active and I sent this once, but I > think before I was approved to be on the list. Sorry if this is a > duplicate. > > If it is still active, I've been inspired by Mr. Wampler's talk about using > Polyglot/AOP to rid Ruby programming of logging/exception handling clutter. > > I was writing a test class to deploy as a job inside of the Torquebox Jruby > server: > > > ## test.rb > > require 'rubygems' > > require 'logger' > > require 'aquarium' > > > > module Aquarium > > module Reusables > > module TraceMethods > > def self.append_features mod > > Aquarium::Aspects::Aspect.new :before, :type => mod, > > :methods => :all, > > :method_options => [:exclude_ancestor_methods] do |jp, object, > *args| > > names = "#{jp.target_type.name}##{jp.method_name}" > > p "Entering: #{names}: args = #{args.inspect}" > > # jp.proceed > > # p "Leaving: #{names}: args = #{args.inspect}" > > end > > end > > end > > end > > end > > > class TestJob > > # include Aquarium::DSL > > attr_accessor :log > > > def initialize > > @log = Logger.new(STDOUT) > > @log.level = Logger::DEBUG > > > @log.info("Initialized") > > end > > > def run() > > @log.info("I ran: #{test1("test1")}: #{test2}") > > end > > > def test1(val) > > val > > end > > > def test2 > > "test2" > > end > > include Aquarium::Reusables::TraceMethods > > end > > > > When I run it in Torquebox, the aspects "fire" on the first calls to the > run method and then do not. > > > When I try it in jirb, everything seems to work just fine until I change > the class a bit and then load it again. At this point when I instantiate a > new instance, it seems to have lost the aspect component. > > > I've tried several iterations with the DSL as well and all exibit the same > behavior on multiple versions of Jruby. > > > I suspect I am not understanding something and have set things up > incorrectly. Any advice would be appreciated. > > Best, > > Mike > _______________________________________________ > Aquarium-users mailing list > Aquarium-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/aquarium-users From mike at planetmcd.com Fri Mar 16 10:57:44 2012 From: mike at planetmcd.com (Michael McDermott) Date: Fri, 16 Mar 2012 06:57:44 -0400 Subject: [Aquarium-users] Problem with Aspect/pointcut code not firing In-Reply-To: References: Message-ID: Dean, Thanks for responding. I'd seen you're Strange Loop talk on Qcon and saw you had a Scala focus. I came by Aquarium through other means and then when I saw it was one of your projects, that I feared this was a dormant project and you'd moved to non-Ruby pastures. If you could look at it I'd be much obliged, but I more than understand that we all have limited time, and this is not one of your foci right now. I left Java when aspectJ was just coming into play, and I hit my first project in Ruby where the amount of required trace debugging statements makes the code painful to read, thus my researching aspects in Ruby. I thought your polyglot programmer talk on your web site was fabulous. It helped crystalize some ideas I have been pushing at the University I work at. Thanks again, Mike On Fri, Mar 16, 2012 at 12:11 AM, Dean Wampler wrote: > Hi Michael, > > I have not actively worked on Aquarium in a while, but I can offer a few > suggestions. First, it has bugs on Ruby 1.9, although I believe that most > of those relate to attempts to remove advice from objects. > > I don't know why the aspects fire just once. Could it be that that you see > the aspect output whe you modify the class and not when it's methods are > executed? > > I think I know what might happen in the second problem. Aquarium has a > limitation that it only affects objects and types already loaded. It > doesn't "watch" for new types or changes. > > I'll try your example myself tomorrow to see if I can figure out any more > details. > > Dean > > Sent from my iPad > > On Mar 15, 2012, at 8:33 PM, Michael McDermott wrote: > > > Hello, > > I'm not sure if this group is still active and I sent this once, but I > > think before I was approved to be on the list. Sorry if this is a > > duplicate. > > > > If it is still active, I've been inspired by Mr. Wampler's talk about > using > > Polyglot/AOP to rid Ruby programming of logging/exception handling > clutter. > > > > I was writing a test class to deploy as a job inside of the Torquebox > Jruby > > server: > > > > > > ## test.rb > > > > require 'rubygems' > > > > require 'logger' > > > > require 'aquarium' > > > > > > > > module Aquarium > > > > module Reusables > > > > module TraceMethods > > > > def self.append_features mod > > > > Aquarium::Aspects::Aspect.new :before, :type => mod, > > > > :methods => :all, > > > > :method_options => [:exclude_ancestor_methods] do |jp, object, > > *args| > > > > names = "#{jp.target_type.name}##{jp.method_name}" > > > > p "Entering: #{names}: args = #{args.inspect}" > > > > # jp.proceed > > > > # p "Leaving: #{names}: args = #{args.inspect}" > > > > end > > > > end > > > > end > > > > end > > > > end > > > > > > class TestJob > > > > # include Aquarium::DSL > > > > attr_accessor :log > > > > > > def initialize > > > > @log = Logger.new(STDOUT) > > > > @log.level = Logger::DEBUG > > > > > > @log.info("Initialized") > > > > end > > > > > > def run() > > > > @log.info("I ran: #{test1("test1")}: #{test2}") > > > > end > > > > > > def test1(val) > > > > val > > > > end > > > > > > def test2 > > > > "test2" > > > > end > > > > include Aquarium::Reusables::TraceMethods > > > > end > > > > > > > > When I run it in Torquebox, the aspects "fire" on the first calls to the > > run method and then do not. > > > > > > When I try it in jirb, everything seems to work just fine until I change > > the class a bit and then load it again. At this point when I > instantiate a > > new instance, it seems to have lost the aspect component. > > > > > > I've tried several iterations with the DSL as well and all exibit the > same > > behavior on multiple versions of Jruby. > > > > > > I suspect I am not understanding something and have set things up > > incorrectly. Any advice would be appreciated. > > > > Best, > > > > Mike > > _______________________________________________ > > Aquarium-users mailing list > > Aquarium-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/aquarium-users >