17 Jul 15:37
[groovy-user] creating a new method inside invokeMethod
From: Rubee <charlestassoni@...>
Subject: [groovy-user] creating a new method inside invokeMethod
Newsgroups: gmane.comp.lang.groovy.user
Date: 2008-07-17 13:38:26 GMT
Subject: [groovy-user] creating a new method inside invokeMethod
Newsgroups: gmane.comp.lang.groovy.user
Date: 2008-07-17 13:38:26 GMT
I've seen examples where invokeMethod creates a new method so that, on the
next call, the performance hit is reduced. Here's an example from Venkat
Subramaniam's excellent "Programming Groovy." (See p. 223.)
class Manager
{
.......
def methodMissing(String name, args)
{
println "intercepting call to $name..."
def delegateTo = null
if(name.startsWith('simple')) { delegateTo = worker }
if(name.startsWith('advanced')) { delegateTo = expert }
if (delegateTo?.metaClass.respondsTo(delegateTo, name, args))
{
Manager.metaClass."${name}" = { Object[] varArgs ->
return delegateTo.invokeMethod(name, *varArgs)
}
return delegateTo.invokeMethod(name, args)
}
throw new MissingMethodException(name, Manager.class, args)
}
........
} //end class
I need to do this is an webapp, which means my analog to the Manager class
shown here lives in a multi-threaded enviroment.
My question, then, is how do I handle method-creation in a mulit-threaded
environment? I suppose that question boils down to: what do I need to
synchronize on, if anything?
I hope developers are doing this kind of thing all the time, and maybe
someone can show me a real-world example.
--
--
View this message in context: http://www.nabble.com/creating-a-new-method-inside-invokeMethod-tp18508436p18508436.html
Sent from the groovy - user mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
RSS Feed