Unable to resolve static method call from groovlet into packaged class

355 views
Skip to first unread message

Jeff

unread,
Apr 23, 2010, 11:17:57 AM4/23/10
to Gaelyk
Ok, so I've modified the import so that it is no longer static:

import com.gaelyktestapp.service.PageTemplateService.*

And I've modfied the code to use a fully qualified static reference:

logWarning("ajaxDbOperations:getRepliesCounts userId =
$PageTemplateService.getUser(request).userId")

It throws the following:

Apr 23, 2010 3:01:36 PM
com.google.appengine.tools.development.ApiProxyLocalImpl log
INFO: [1272034896614000] javax.servlet.ServletContext log:
GroovyServlet Error: script: '/ajaxDbOperations.groovy': Script
processing failed.No such property: PageTemplateService for class:
ajaxDbOperationsorg.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:
49)
GroovyServlet Error: script: '/ajaxDbOperations.groovy': Script
processing failed.No such property: PageTemplateService for class:
ajaxDbOperationsorg.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:
49)
groovy.lang.MissingPropertyException: No such property:
PageTemplateService for class: ajaxDbOperations
at
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:
49)
at
org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:
49)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:
241)
at ajaxDbOperations.run(ajaxDbOperations.groovy:253)
at groovy.util.GroovyScriptEngine.run(GroovyScriptEngine.java:464)
at groovy.servlet.GroovyServlet$1.call(GroovyServlet.java:120)
at org.codehaus.groovy.runtime.GroovyCategorySupport
$ThreadCategoryInfo.use(GroovyCategorySupport.java:93)
at org.codehaus.groovy.runtime.GroovyCategorySupport
$ThreadCategoryInfo.access$200(GroovyCategorySupport.java:61)
at
org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:
201)
at groovy.servlet.GroovyServlet.service(GroovyServlet.java:129)
at groovyx.gaelyk.GaelykServlet.super$5$service(GaelykServlet.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:
100)
at
org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:
88)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1058)
at
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:
127)
at groovyx.gaelyk.GaelykServlet
$_service_closure1.doCall(GaelykServlet.groovy:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:
100)
at
org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:
88)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at
org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:
272)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
at
org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:
66)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:
151)
at groovyx.gaelyk.GaelykServlet
$_service_closure1.doCall(GaelykServlet.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:
100)
at
org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:
88)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at
org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:
272)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
at groovy.lang.Closure.call(Closure.java:276)
at groovy.lang.Closure.call(Closure.java:271)
at org.codehaus.groovy.runtime.GroovyCategorySupport
$ThreadCategoryInfo.use(GroovyCategorySupport.java:93)
at org.codehaus.groovy.runtime.GroovyCategorySupport
$ThreadCategoryInfo.access$200(GroovyCategorySupport.java:61)
at
org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:
201)
at
org.codehaus.groovy.runtime.DefaultGroovyMethods.use(DefaultGroovyMethods.java:
315)
at org.codehaus.groovy.runtime.dgm$640.invoke(Unknown Source)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite
$PogoMetaMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:
307)
at
org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:
51)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:
155)
at groovyx.gaelyk.GaelykServlet.service(GaelykServlet.groovy:44)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:
511)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1166)
at
com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:
51)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:
43)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:
122)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:
388)
at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:
216)
at
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:
182)
at
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:
765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:
418)
at
com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:
70)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
at com.google.appengine.tools.development.JettyContainerService
$ApiProxyHandler.handle(JettyContainerService.java:349)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:
542)
at org.mortbay.jetty.HttpConnection
$RequestHandler.headerComplete(HttpConnection.java:923)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:
409)
at org.mortbay.thread.QueuedThreadPool
$PoolThread.run(QueuedThreadPool.java:582)

This is odd, isn't it?

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes Gaelyk.
Pour envoyer un message à ce groupe, adressez un e-mail à gae...@googlegroups.com.
Pour vous désabonner de ce groupe, envoyez un e-mail à l'adresse gaelyk+un...@googlegroups.com.
Pour plus d'options, consultez la page de ce groupe : http://groups.google.com/group/gaelyk?hl=fr

Guillaume Laforge

unread,
Apr 23, 2010, 11:35:25 AM4/23/10
to gae...@googlegroups.com
But now your import is wrong.
It's not:

import com.gaelyktestapp.service.PageTemplateService.*

But:

import com.gaelyktestapp.service.PageTemplateService

Try again with that.
I want to be sure the class is properly resolved, at least.
--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one

Jeff Schwartz

unread,
Apr 23, 2010, 11:49:06 AM4/23/10
to gae...@googlegroups.com
Import corrected and is now:

import com.gaelyktestapp.service.PageTemplateService

Which now throws the following:

INFO: [1272037578764000] javax.servlet.ServletContext log: GroovyServlet Error:  script: '/ajaxDbOperations.groovy':  Script processing failed.No such property: getUser for class: com.gaelyktestapp.service.PageTemplateServicegroovy.lang.MetaClassImpl.invokeStaticMissingProperty(MetaClassImpl.java:876)
GroovyServlet Error:  script: '/ajaxDbOperations.groovy':  Script processing failed.No such property: getUser for class: com.gaelyktestapp.service.PageTemplateServicegroovy.lang.MetaClassImpl.invokeStaticMissingProperty(MetaClassImpl.java:876)
groovy.lang.MissingPropertyException: No such property: getUser for class: com.gaelyktestapp.service.PageTemplateService
    at groovy.lang.MetaClassImpl.invokeStaticMissingProperty(MetaClassImpl.java:876)
    at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1610)
    at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1586)
    at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:3295)
    at org.codehaus.groovy.runtime.callsite.ClassMetaClassGetPropertySite.getProperty(ClassMetaClassGetPropertySite.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:237)

    at ajaxDbOperations.run(ajaxDbOperations.groovy:253)
    at groovy.util.GroovyScriptEngine.run(GroovyScriptEngine.java:464)
    at groovy.servlet.GroovyServlet$1.call(GroovyServlet.java:120)
    at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:93)
    at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.access$200(GroovyCategorySupport.java:61)

    at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:201)
    at groovy.servlet.GroovyServlet.service(GroovyServlet.java:129)
    at groovyx.gaelyk.GaelykServlet.super$5$service(GaelykServlet.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:100)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1058)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:127)
    at groovyx.gaelyk.GaelykServlet$_service_closure1.doCall(GaelykServlet.groovy:45)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:100)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:151)
    at groovyx.gaelyk.GaelykServlet$_service_closure1.doCall(GaelykServlet.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:100)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
    at groovy.lang.Closure.call(Closure.java:276)
    at groovy.lang.Closure.call(Closure.java:271)
    at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:93)
    at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.access$200(GroovyCategorySupport.java:61)

    at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:201)
    at org.codehaus.groovy.runtime.DefaultGroovyMethods.use(DefaultGroovyMethods.java:315)
    at org.codehaus.groovy.runtime.dgm$640.invoke(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoMetaMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:307)

    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:155)
    at groovyx.gaelyk.GaelykServlet.service(GaelykServlet.groovy:44)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:51)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)

    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:70)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:349)

    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)

    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)


--
--
Jeff

Guillaume Laforge

unread,
Apr 23, 2010, 2:41:14 PM4/23/10
to gae...@googlegroups.com
And how do you call getUser?
Show me the code :-)

Jeff Schwartz

unread,
Apr 23, 2010, 3:07:59 PM4/23/10
to gae...@googlegroups.com
It now works with the explicit static call and the use of non static import.

In the previous stack trace I gave it was my fault (I think) because the expression I was using was:


logWarning("ajaxDbOperations:getRepliesCounts userId = $PageTemplateService.getUser(request).userId")

and it should have been (I think):

logWarning("ajaxDbOperations:getRepliesCounts userId = ${PageTemplateService.getUser(request).userId}")

Notice that I had left off the { and } but should that have made a difference?

Based on this it appears that groovy doesn't support static imports and the shortened static call when using them. Am I wrong?

Jeff

Jeff Schwartz

unread,
Apr 23, 2010, 3:27:52 PM4/23/10
to gae...@googlegroups.com
Based on what I read at http://groovy.codehaus.org/Static+Import+Usage it apparently does so am I doing something wrong or is this just some weird gaelyk/groovy kind of thing going on here?

Jeff

Guillaume Laforge

unread,
Apr 23, 2010, 3:36:48 PM4/23/10
to gae...@googlegroups.com
You indeed had to use curly braces, actually, as per your previous post.
In a GString, you can do $a.b.c and it will be recognized as such, but
for more complex expressions, such as when there are method calls, you
have to wrap everything with curly braces.
It's more to do with how GStrings work, than with static imports which
work just fine in Groovy.
So if you want to avoid the hassle of remember the rule of
with/without curly braces, just use curlies all the time.

Jeff Schwartz

unread,
Apr 23, 2010, 4:14:56 PM4/23/10
to gae...@googlegroups.com
But the code breaks when multiple users are hitting it which is why I posted this originally in the other thread :(

I only used loging as an example - a poor one, which I mangled in my correspondence and my apologies for that. The code in question is this:

String userId = getUser(request).userId

as well as

logWarning("ajaxDbOperations:userId = ${getUser(request).userId}")

These calls work as expected when one user is on the system but breaks when 2 are on. This is using static importing:

INFO: [1272052436544000] javax.servlet.ServletContext log: GroovyServlet Error:  script: '/ajaxDbOperations.groovy':  Script processing failed.Cannot get property 'userId' on null objectorg.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:56)
GroovyServlet Error:  script: '/ajaxDbOperations.groovy':  Script processing failed.Cannot get property 'userId' on null objectorg.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:56)
java.lang.NullPointerException: Cannot get property 'userId' on null object
    at org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:56)
    at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:156)
    at org.codehaus.groovy.runtime.callsite.NullCallSite.getProperty(NullCallSite.java:29)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:237)
    at ajaxDbOperations.run(ajaxDbOperations.groovy:252)
Apr 23, 2010 7:53:56 PM com.google.appengine.tools.development.ApiProxyLocalImpl log
INFO: [1272052436563000] javax.servlet.ServletContext log: GroovyServlet Error:  script: '/ajaxDbOperations.groovy':  Script processing failed.Cannot get property 'userId' on null objectorg.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:56)
GroovyServlet Error:  script: '/ajaxDbOperations.groovy':  Script processing failed.Cannot get property 'userId' on null objectorg.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:56)
java.lang.NullPointerException: Cannot get property 'userId' on null object
    at org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:56)
    at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:156)
    at org.codehaus.groovy.runtime.callsite.NullCallSite.getProperty(NullCallSite.java:29)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:237)
    at ajaxDbOperations.run(ajaxDbOperations.groovy:196)

Jeff

unread,
Apr 26, 2010, 10:41:07 AM4/26/10
to Gaelyk
I spent the weekend reworking almost all the code. I am testing now
and it looks like the errors I was getting and the erratic behavior
was not due to anything directly related to gaelyk but I think I
should share this with you so that you don't fall into the same traps
that I did :)

Gaelyk has a wrapper for memcache which allows you to do the
following:

if('somekey' in memcache){
cache = memcache['somekey']
}else{
cache = gogetit()
memcache['somkey'] = cache
}
// use cache...

The above pattern is dangerous and should be avoided. The cache can
become invalid between the check for it being in memcache and your
assignment to cache or whatever var you will store its reference in.
Instead, a safer pattern is the following:

cache = memcache['somekey']
if(cache == null){
cache = gogetit()
memcache['somekey'] = cache
}
// use cache

The above pattern is the only sure way of avoiding this type of "I got
it/ I don't have it" type of issue. This is why things seemed to be
disappearing from my cache after what I thought was a valid assignment
of its reference.

My sincerest apologies to the group and to Guillaume for inferring
that I thought the problem was due to some fault in Gaelyk. Obviously
it wasn't. It was due to my use of an improper coding pattern. I
should have known better...

:(

Jeff
> ...
>
> read more »

Guillaume Laforge

unread,
Apr 26, 2010, 10:44:07 AM4/26/10
to gae...@googlegroups.com
Hmm, very interesting finding!

At least, I'm glad it's not Gaelyk's fault, and it's great to share
your experience!
Thank you!

Guillaume
--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one

Jeff Schwartz

unread,
Apr 26, 2010, 10:51:40 AM4/26/10
to gae...@googlegroups.com
My appologies again, Guillaume. I am sure that there is a place for the use of the 'in' pattern with memcache but I would avoid it at all costs lol. Without the ability to lock down the cache (which is a terrible idea anyway) the possibility exists that you will at some point bump heads with a null reference.

Jeff
--
--
Jeff

Guillaume Laforge

unread,
Apr 26, 2010, 11:03:02 AM4/26/10
to gae...@googlegroups.com
Yeah, it seems like a good idea, but that could cause some more
trouble than it's worth.

That said, using the contains() method directly (in is just a shortcut
to contains()), you'd get into the same trouble anyway.

But I'm wondering whether we could find something nicer, that would
"wrap" the pattern you're using, but with a nicer / groovier feel to
it...

Jeff Schwartz

unread,
Apr 26, 2010, 11:14:40 AM4/26/10
to gae...@googlegroups.com
If we could then that would be, well, very Groovy! And it would save the next unfortunate soul to fall into the same trap that I did.

Jeff

Guillaume Laforge

unread,
Apr 26, 2010, 11:42:23 AM4/26/10
to gae...@googlegroups.com
Instead of:

cache = memcache['somekey']
if(cache == null){
cache = gogetit()
memcache['somekey'] = cache
}
// use cache

Perhaps something like:

memcache.withKey('somekey', default: { gogetit() }) { value ->
// use cache
}

But I'm not necessarily sure it's that much easier to read.

A more complex implementation could also help us achieve something like:

memcache.withKey('somekey').defaultValue { gogetit() }.do {
// use cache
}

Or something like that.
Not sure if it really improves things?

Jeff Schwartz

unread,
Apr 26, 2010, 12:06:36 PM4/26/10
to gae...@googlegroups.com
I think the 2nd pattern would be more flexible but that's just my preference.
Reply all
Reply to author
Forward
0 new messages