[aosd-discuss] dynamic AOP and dynamic languages
SainTiss
saintiss at arklinux.org
Thu May 11 09:27:53 EST 2006
Hi all,
recently I was looking at some java implementations like PROSE, which
seem to allow dynamic enabling/disabling of aspects. However, Java just
doesn't seem to be the suitable language for this kind of thing. It
lacks flexibility.
Basically you either need to modify the VM or use the debugger interface
or use other tricks...
That is why I assumed there would be alternative implementations in
other languages which had to be much simpler. Only I couldn't really
find any...
So I made an attempt to create a prototype of a dynamic weaving
framework in Io (www.iolanguage.org). Let me give an example of the
ubiquitous logging case:
===============================================
== Here is the Logger Aspect, with two pointcuts, each
== having one advice
===============================================
LoggerAspect := Aspect clone do (
setName("loggerAspect")
Logger := Object clone do (
log := method(arg,
writeln("LOG: ", arg)
)
)
)
LoggerAspect addPointcut (
Pointcut clone do (
addJoinpoint (
message(A findBlocksByName("m"))
)
addAdvice(
message(attachMessage (lastMessage, Object message (EVAL(Logger)
log("LOGGING EXIT")))) evaluateTemplate(LoggerAspect) )
)
)
LoggerAspect addPointcut (
Pointcut clone do (
addJoinpoint (
message(Lobby findSlotsByName("A") appendSeq(Lobby
findSlotsByName("B")) map(o, o findBlocksByName("mB")) flattenS) )
addAdvice (
message(insertMessage (message, Object message (EVAL(Logger)
log("LOGGING BEGIN")))) evaluateTemplate(LoggerAspect) )
)
)
========================================================
== Here are a few objects to which logging will be applied
========================================================
A := Object clone do (
mA := method (
writeln("MA BODY")
)
mB := method (
writeln("MB BODY")
)
)
B := Object clone do (
mBB := method (
writeln("MBB Body")
writeln("MBB Body cont")
)
)
======================================================================
== Here is the main program, which enables, disables, and reenables
== logging
=======================================================================
"-- no logging --" println
A mA
writeln
A mB
writeln
B mBB
writeln
writeln
LoggerAspect apply
"-- logging applied --" println
A mA
writeln
...
LoggerAspect disable
"-- logging disabled --" println
A mA
writeln
...
LoggerAspect enable
"-- logging enabled --" println
A mA
writeln
...
========================================
== And here is the output:
=====================================
-- no logging --
MA BODY
MB BODY
MBB Body
MBB Body cont
-- logging applied --
MA BODY
LOG: LOGGING EXIT
LOG: LOGGING BEGIN
MB BODY
LOG: LOGGING EXIT
LOG: LOGGING BEGIN
MBB Body
MBB Body cont
-- logging disabled --
MA BODY
MB BODY
MBB Body
MBB Body cont
-- logging enabled --
MA BODY
LOG: LOGGING EXIT
LOG: LOGGING BEGIN
MB BODY
LOG: LOGGING EXIT
LOG: LOGGING BEGIN
MBB Body
MBB Body cont
=======================================
I hope the idea is sufficiently clear from this. Basically every piece
of code in Io is a message, so I can handle the weaving behind the
scenes through manipulating these messages. The query language for
pointcuts is also Io itself. I agree that in the above examples the
queries may look somewhat artificial and complex, but it should not be
too difficult to have a query library which would hide that complexity.
I would like to get
some feedback on whether this (dynamic weaving in a dynamic language) is
considered useful in the AOP community. I get a feeling that maybe it
isn't because then maybe there would have been dynamic language
implementations before?
If anything is unclear, I'll be happy to provide some additional
explanation...
Anyway, any feedback is welcome :)
Thanks,
Hans Schippers
--
A liberal is a person whose interests aren't at stake at the moment
-- Willis Player
Hans Schippers
Research Assistant of the Research Foundation - Flanders (FWO -
Vlaanderen) http://www.win.ua.ac.be/~hschipp/
Formal Techniques in Software Engineering (FoTS)
University of Antwerp
Middelheimlaan 1
2020 Antwerpen - Belgium
Phone: +32 3 265 38 71
Fax: +32 3 265 37 77
More information about the discuss
mailing list