[appengine-java] Re: Prerelease SDK 1.5.5 available for download!

2011-10-03 Thread Jay Young
Holy crap!

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine-java/-/sGNjx_rosygJ.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Building Session affinity manually

2011-06-26 Thread Jay Young
There's nothing you can do to affect which request goes to which instance.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine-java/-/XKpUIjxHBW8J.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: 1.5.1 SDK Prerelease

2011-06-19 Thread Jay Young
Just downloaded the new "appengine-java-sdk-1.5.1_prerelease.zip" and ran 
the dev_appserver, only to receive the following exception.  The Jetty 
server starts up as expected, but will only serve 503s.

WARNING: Failed startup of context 
com.google.apphosting.utils.jetty.DevAppEngineWebAppContext@4463a1ae{/,/devel/rblog/WAR}
java.lang.NullPointerException
at 
com.google.appengine.tools.appstats.Recorder.checkNotNull(Recorder.java:365)
at com.google.appengine.tools.appstats.Recorder.(Recorder.java:207)
at com.google.appengine.tools.appstats.Recorder.(Recorder.java:197)
at 
com.google.appengine.tools.appstats.AppstatsFilter.init(AppstatsFilter.java:183)
at org.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:97)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at 
org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:662)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
at 
org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:224)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at 
com.google.appengine.tools.development.JettyContainerService.startContainer(JettyContainerService.java:186)
at 
com.google.appengine.tools.development.AbstractContainerService.startup(AbstractContainerService.java:162)
at 
com.google.appengine.tools.development.DevAppServerImpl.start(DevAppServerImpl.java:164)
at 
com.google.appengine.tools.development.DevAppServerMain$StartAction.apply(DevAppServerMain.java:164)
at 
com.google.appengine.tools.util.Parser$ParseResult.applyArgs(Parser.java:48)
at 
com.google.appengine.tools.development.DevAppServerMain.(DevAppServerMain.java:113)
at 
com.google.appengine.tools.development.DevAppServerMain.main(DevAppServerMain.java:89)

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine-java/-/6ifJrc2tLl8J.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



Re: [appengine-java] Re: Is the native API really so much faster than JDO and slim3?

2011-06-09 Thread Jay Young
When frameworks compete, everyone wins!

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine-java/-/3zCQizDuxPIJ.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Entity.getKey() reliable for gets?

2011-06-05 Thread Jay Young
In the Javadoc for Entity.getKey(), it says:

If the entity has not yet been saved (e.g. via DatastoreService.put), this 
Key will not be fully specified and cannot be used for certain operations 
(like DatastoreService.get). Once the Entity has been saved, its Key will be 
updated to be fully specified.

Does this only refer to the fact that the entity might not yet have an ID or 
keyname?  In other words, if I construct the entity with an ID or keyname, 
can I rely on entity.getKey() to return something I can use in a 
db.get(key), or is there some other part that is not fully specified until a 
put?  Considering that you can get a full key from a KeyFactory with only a 
kind and keyname/ID, I'm assuming this would work, but I'd like to make 
sure.

Thanks. 

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine-java/-/blZubkEyMy0tOXNK.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: New GWT/App Engine site

2011-05-31 Thread Jay Young
Cool idea, but I think you might want to look into GWT's code splitting.  It 
took me 35 seconds to download your 2.11MB file.  That's going to turn off a 
LOT of users.  I understand that that file gets cached, but that's not going 
to be the case on their first trip to your site.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Combine getIdentifiable with get?

2011-04-28 Thread Jay Young
According to the JavaDoc, the IdentifiableValue interface includes a 
getValue() method which returns the value as an Object:

http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/memcache/MemcacheService.IdentifiableValue.html

IdentifiableValue idVal = memcache.getIdentifiable(key); // Get the value as 
an IdentifiableValue
Object myMemcacheObj = idVal.getValue(); // Pull the Object out of that; 
does not touch memcache again.

maybeTouchTheObj(myMemcacheObj);

memcache.putIfUntouched(key, idVal, myMemcacheObj); // Put the object back.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Best Practice for Java Datastore API

2011-04-21 Thread Jay Young
For me, it's still been beneficial to use a model-like class just like you 
would for JDO and JPA and make all of your data store calls within these 
classes, and make sure the methods that perform writes enforce the 
invariants.  I'm doing this in Javascript, even, and I've never had an issue 
with type mismatches.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: 1.4.3 Javadocs? Looking for the FileServiceFactory docs:

2011-04-03 Thread Jay Young
On Sunday, April 3, 2011 12:59:23 PM UTC-4, Mitch Rudominer wrote:
>
> I will look into posting it somewhere temporarily.


files-javadoc.appspot.com?  :-) 

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Tips/Pitfalls for total newbies?

2011-04-01 Thread Jay Young
Watch all of the App Engine videos from 2008, specifically the following 
(yes, they pre-date Java support on App Engine, but most of the principles 
apply):
https://sites.google.com/site/io/building-scalable-web-applications-with-google-app-engine
https://sites.google.com/site/io/under-the-covers-of-the-google-app-engine-datastore
https://sites.google.com/site/io/working-with-google-app-engine-models

Then watch the 2009 
ones: http://www.google.com/events/io/2009/sessions.html#appengine
Particulary 
http://www.google.com/events/io/2009/sessions/BuildingScalableComplexApps.html 
and http://www.google.com/events/io/2009/sessions/SofterSideofSchemas.html

Then watch the 2010 
ones: http://www.google.com/events/io/2010/sessions.html#App%20Engine
Specifically:
http://www.google.com/events/io/2010/sessions/appstatsrpc-appengine.html
http://www.google.com/events/io/2010/sessions/high-throughput-data-pipelines-appengine.html

The information in  these videos is invaluable.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



Re: [appengine-java] Re: GAE on Mac OS X not working on local Jetty

2011-03-30 Thread Jay Young
I just upgraded to the 1.4.3 SDK and re-installed the Mac OS X Java Update 
4.  Everything seems to be working as before.  Thanks for the fix!

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



Re: [appengine-java] Task Enqueue in a Transaction

2011-03-22 Thread Jay Young
According to the docs, gets, puts, deletes, and ancestor queries are all 
strongly consistent:
http://code.google.com/appengine/docs/java/datastore/hr/

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: New Mac Java Update, Now Dev Server Stops After ACK Running

2011-03-16 Thread Jay Young
https://groups.google.com/forum/#!topic/google-appengine-java/WiImnzVb9Fo

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Development AppEngine server quits with no warnings.

2011-03-15 Thread Jay Young
http://code.google.com/p/googleappengine/issues/detail?id=4712

Check 
comment #39 for a work-around.

On Tuesday, March 15, 2011 2:09:44 PM UTC-4, Cyrille Vincey wrote:
>
> +1... 2 days lost. Arghhh.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: suggestions on template engine for GAE-java

2011-03-15 Thread Jay Young
http://code.google.com/closure/templates/

Google doesn't push their Closure Tools very hard, but I've had a lot of 
success with their templating engine.  Take a look at the docs.  It's not 
Django/PHP/JSP style templating, so it does take a bit of re-learning.  That 
said, there are a lot of benefits to their approach.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: App Engine plugin (Java) for Eclipse terminates unexpectedly

2011-03-15 Thread Jay Young
There is an issue with the JVM in Apple's release.  See the thread and issue 
linked below.  I recommend the solution posted in Comment #39 on the issue 
tracker.

Thread:  
https://groups.google.com/forum/#!topic/google-appengine-java/WiImnzVb9Fo
Issue:  http://code.google.com/p/googleappengine/issues/detail?id=4712

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Why does google set quotas on their API calls?

2011-03-14 Thread Jay Young
Because when you do image transformations, you are sending an API to another 
piece of Google's infrastructure, which I would assume is highly optimized 
for doing such things.  If you do it in your own code, you'll probably pay 
more in CPU cost than you would for the API call.  If it's just a matter of 
bumping into the number of times you are allowed to make those API calls, 
let them know.  They've been known to relax some quotas for users with real 
needs.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Weird performance problem last 3 days or so

2011-03-10 Thread Jay Young
Might the difference between your foo and bar deployments be the size of the 
data set you have for each app?  If the fresh install is consistently fine 
and the old one is consistently slow, maybe you've hit a threshold where 
some inefficiency in your queries or data handling has started to actually 
matter.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Development AppEngine server quits with no warnings.

2011-03-09 Thread Jay Young
Created an issue for this: 
 http://code.google.com/p/googleappengine/issues/detail?id=4712

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Creating/Compiling new Java class at run time

2011-03-08 Thread Jay Young
I dunno about this.  The different JVM language runtimes (JRuby, Rhino, 
Groovy, etc) all generate and run bytecode on the fly.  I don't know if you 
can cache that generated byte code and re-execute it later, though that 
seems like it'd be a shortcoming of the interpreter, not the App Engine 
environment.


On Wednesday, March 9, 2011 12:17:57 AM UTC-5, Didier Durand wrote:
>
> Hi, 
>
> Even if you solve the File I/O issue, I would guess that you may then 
> face security issue: Google has probably protected its instances 
> against execution of code not coming direcly from the war file... 
>
> Anyway, very interesting question: pls, let us konw how you progress. 
>
> regards 
>
> didier 
>
> On Mar 9, 5:43 am, Larry Cable  wrote: 
> > On Mar 8, 8:35 pm, Larry Cable  wrote: 
> > 
> > 
> > 
> > > On Mar 7, 12:13 am, Rick Smith  wrote: 
> > 
> > > > Hi all 
> > 
> > > > Can I create and compile a java class at run time on goolge 
> > > > appengine. 
> > > > Use case: I have given a UI to my application user that they can 
> > > > define their own business logic.Now what is going to be main 
> challenge 
> > > > is that I need to make new deployment each time when some one need to 
>
> > > > modify its business logic. As an alternate I want to store source 
> code 
> > > > in data base and compile it when required. 
> > 
> > > > Regards 
> > 
> > > > Rick 
> > 
> > > As others have pointed out the file I/O issue precludes using a 
> > > compiler  
> > 
> > > The best I can suggest is using BCEL to construct classes at 
> > > runtime... But I have never tried this with GAE so I do not know if 
> > > BCEL is whitelist safe. 
> > 
> > Just as a followup you need to take a look at the BCEL API to see if 
> > you can create in-memory class files ... Otherwise you will trip up 
> > over the File I/O issue again.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Can we use Java Development Server in production mode

2011-03-01 Thread Jay Young
Rick, now that I think of it, the Java dev_appserver is based on Jetty, 
which is multi-threaded.  I was thinking of the python server (at least I'm 
pretty sure I'd heard that).  Toby was absolutely right.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Can we use Java Development Server in production mode

2011-03-01 Thread Jay Young
Googlers have said many times that you should not use the dev server for 
production.  Among other things, It is single-threaded, so you don't get 
concurrent request handling, and it is not hardened for security.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: openId with user service redirection clarification

2011-02-26 Thread Jay Young
If the login page is in the pop-up, then the pop-up window is being 
re-directed, not the main window.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: How to produce a synchronized timestamp?

2011-02-06 Thread Jay Young
Brett Slatkin:

"...clocks aren't in sync.  It doesn't work like that.  Even with NTP it 
doesn't work like that.  I saw a server the other day it was 40 minutes 
off."

http://www.google.com/events/io/2010/sessions/high-throughput-data-pipelines-appengine.html

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Synchronized reads/writes on a memcache variable

2010-12-15 Thread Jay Young
On Dec 15, 10:50 am, Simon  wrote:
> although I'd argue that
> you should be changing your design anyway since synchronizing across a
> distributed architecture for a lot of threads is just unadvisable.

No doubt.  I was simply commenting on the method in question.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Synchronized reads/writes on a memcache variable

2010-12-15 Thread Jay Young
I considered the increment decrement approach, but it creates a race
condition with the counter.  Having many different threads/tasks
trying to grab the lock at the same time  could increment the number
above one, even when no one has the lock because there is still a
period of time between the increment() and decrement().  Remember,
these are RPC calls going over the network.  If any part of that
interaction is slow, there will be even longer periods between the +1
and -1.  I think this method errs on the side of accidentally locking
when there isn't a lock.  The only negatives I see would apply to any
lock that's implemented in a cache.


On Dec 15, 8:23 am, Simon  wrote:
> Hi,
>
> I think the following should work with the following caveats:
> - there's a small danger that if the server blows up before it
> releases the lock, that no threads would be able to update your cache,
> but since it's only a cache of data. This is easily mitigated by
> introducing a task which periodically resets the lock.
> - I still believe that there's the possibility that separate instances
> will get a non-updated object, even if you use the locking, since I'm
> assuming it takes x-amount of time for the changes in MemCache to
> propagate throughout the instances.  I may be wrong in this assumption
> however.
>
> Anyway, your code would go something like:
>
> boolean lockAcquired = false;
>
> try {
>     lockAcquired = acquireLock();
>     doStuff();} finally {
>
>     if (lockAcquired) {
>         releaseLock();
>     }
>
> }
>
> With the locking code being:
>
>     public static boolean acquireLock() {
>
>         boolean lockAcquired = true;
>         try {
>             while (increment() != 1) {
>                 decrement();
>                 Thread.sleep(500);
>             }
>         } catch (Throwable t) {
>             // Log error
>             lockAcquired = false;
>         }
>
>         return lockAcquired;
>     }
>
>     public static void releaseLock() {
>         decrement();
>     }
>
>     private static void decrement() {
>         MemcacheServiceFactory.getMemcacheService().increment("LOCK",
> -1, 0L);
>     }
>
>     private static Long increment() {
>         return
> MemcacheServiceFactory.getMemcacheService().increment("LOCK", 1, 0L);
>     }
>
> On Dec 14, 9:56 pm, Jay Young  wrote:
>
>
>
>
>
>
>
> > Grr.  Just noticed another issue.  The cache item that you get the
> > index is not the same item as the lock, so really you need two
> > different cache items, one to make sure you have a unique value for
> > the lock, and the lock itself.  The code above is correct, you just
> > need different keys for the first two cache reads.
>
> > If you can generate a guaranteed-unique name (maybe the thread ID +
> > time?), you can drop the first cache item and use that as the lock
> > value.  This would also prevent the issue with the code above if the
> > lockIndex item is ever evicted and re-read at the same time (thus
> > returning 0 for both), or if it overflows the long.
>
> > (I honestly don't know if this is iron-clad, but intuitively it seems
> > like it would work with only very minor edge cases.)
>
> > On Dec 14, 4:08 pm, Andrei Cosmin Fifiiþã 
> > wrote:
>
> > > H, super...
> > > I was thinking of smth like (val mod 2) == 0/1 (true/false), but the lock
> > > reading wasn't safe.
> > > Thanks!
>
> > > On 14 December 2010 20:57, Jay Young  wrote:
>
> > > > Except return lockIndex should just be return true.
>
> > > > --
> > > > You received this message because you are subscribed to the Google 
> > > > Groups
> > > > "Google App Engine for Java" group.
> > > > To post to this group, send email to
> > > > google-appengine-j...@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > google-appengine-java+unsubscr...@googlegroups.com > > >  unsubscr...@googlegroups.com>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/google-appengine-java?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Synchronized reads/writes on a memcache variable

2010-12-15 Thread Jay Young
On Dec 15, 8:23 am, Simon  wrote:
> since I'm
> assuming it takes x-amount of time for the changes in MemCache to
> propagate throughout the instances.  I may be wrong in this assumption
> however.

I don't think cache data is propagated to the various app instances.
It resides in its own central (distributed) system and all handlers/
tasks/cron/whatever make RPC calls into the cache.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Synchronized reads/writes on a memcache variable

2010-12-14 Thread Jay Young
Grr.  Just noticed another issue.  The cache item that you get the
index is not the same item as the lock, so really you need two
different cache items, one to make sure you have a unique value for
the lock, and the lock itself.  The code above is correct, you just
need different keys for the first two cache reads.

If you can generate a guaranteed-unique name (maybe the thread ID +
time?), you can drop the first cache item and use that as the lock
value.  This would also prevent the issue with the code above if the
lockIndex item is ever evicted and re-read at the same time (thus
returning 0 for both), or if it overflows the long.

(I honestly don't know if this is iron-clad, but intuitively it seems
like it would work with only very minor edge cases.)

On Dec 14, 4:08 pm, Andrei Cosmin Fifiiţă 
wrote:
> H, super...
> I was thinking of smth like (val mod 2) == 0/1 (true/false), but the lock
> reading wasn't safe.
> Thanks!
>
> On 14 December 2010 20:57, Jay Young  wrote:
>
>
>
>
>
>
>
> > Except return lockIndex should just be return true.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Google App Engine for Java" group.
> > To post to this group, send email to
> > google-appengine-j...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-appengine-java+unsubscr...@googlegroups.com > unsubscr...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/google-appengine-java?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Synchronized reads/writes on a memcache variable

2010-12-14 Thread Jay Young
Except return lockIndex should just be return true.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: Synchronized reads/writes on a memcache variable

2010-12-14 Thread Jay Young
Would this work?  Just call getLock() in a while(! getLock()) {} loop
until you get it.

boolean getLock() {
 String lockIndex = "LockIndex" +
MemcacheService.increment("descriptiveLockName", 1, 0);
 MemcacheService.put("DescriptiveLockName",
lockIndex,
null,
MemcacheService.SetPolicy.ADD_ONLY_IF_NOT_PRESENT);
  if(memcacheService.get("DescriptiveLockName") == lockIndex) {
// Yay, got the lock.
return lockIndex;
  }
  else {
return false;
  }
}

void releaseLock() {
  MemcacheService.delete("DescriptiveLockName");
}



On Dec 14, 5:07 am, Andrei Cosmin Fifiiţă 
wrote:
> I was thinking about that (increment/decrement)...
> But, first, if the tasks read the value of the variable that needs to be
> incremented, isn't there a posibility that all tasks will read the same
> value at the same time and then increment it in the same time ?
>
> On 14 December 2010 11:59, Simon  wrote:
>
>
>
>
>
>
>
> > The synchronized block won't work at all, since it's not guaranteed
> > that you only have a single instance of your application running at
> > any point in time.  As soon as you have multiple instances then you
> > will be synchronizing in different JVMs and hence you'll get multiple
> > threads accessing the cache, and hence the same problem will occur.
>
> > You could probably use the Memcache increment/decrement functionality
> > to hook together a rough cross-instance synchronization, since they
> > increment and decrement atomically.
>
> > On Dec 14, 5:22 am, Michael Weinberg  wrote:
> > > You can use the standard Java synchronization to synchronize the task
> > > threads, e.g.
>
> > > synchronized (YourMemcachedDataClass.class) {
> > >   YourMemcachedDataClass cachedData =
> > > (YourMemcachedDataClass)cache.get(CACHE_KEY);
>
> > >   if (cachedData == null)
> > >      cachedData = new YourMemcachedDataClass ();
>
> > >   cachedData.add(...);
> > >   cachedData.set(...);
>
> > >   cache.put(CACHE_KEY, cachedData);
>
> > > }
>
> > > this way only 1 thread at a time will get into the synchronized block.
>
> > > Hope it helps..
>
> > > Michael Weinberg
>
> > > On Dec 13, 11:41 am, Ice13ill  wrote:
>
> > > > Maybe there's something that i don't know very well about the memcache
> > > > service and this problem is simpler then i thing it is... If so,
> > > > please advice :)
>
> > > > On Dec 13, 6:38 pm, Ice13ill  wrote:
>
> > > > > I need advice for implementing concurrent access to a memcache
> > > > > variable, when used by multiple running tasks.
> > > > > The problem is this: I have a number of tasks reading from datastore
> > > > > and doing some processing.
> > > > > When the processing is complete, i add a String to a List stored in
> > > > > memcache. So i need to get the List from memcache, add a new element,
> > > > > and put it back. The pb is that if 2 tasks write on that variable, i
> > > > > get an exception (I understand that the memcache service gives me a
> > > > > "clone" of the object, not the object itself, or am I wrong ?)
> > > > > So how can i avoid more than one tasks writing in the same object ?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Google App Engine for Java" group.
> > To post to this group, send email to
> > google-appengine-j...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-appengine-java+unsubscr...@googlegroups.com > unsubscr...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/google-appengine-java?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.