Google Cloud Endpoint initialization

112 views
Skip to first unread message

Mike D

unread,
Apr 16, 2014, 9:37:29 PM4/16/14
to google-a...@googlegroups.com
I have some initialization stuff that I'd like to do before GCE can be used.  How would I do this?  I tried creating a ServletContextListener and then calling a static method on my GCE but that doesn't work.  In debugging I can see that the GCEs static variables are not set when a method is invoked.

Vinny P

unread,
Apr 23, 2014, 3:13:52 AM4/23/14
to google-a...@googlegroups.com
On Wed, Apr 16, 2014 at 8:37 PM, Mike D <mdichi...@fittrace.com> wrote:
I have some initialization stuff that I'd like to do before GCE can be used.  How would I do this?  I tried creating a ServletContextListener and then calling a static method on my GCE but that doesn't work.  In debugging I can see that the GCEs static variables are not set when a method is invoked.


Endpoints applications are slightly different than normal web applications; as you remarked in your post, static variables don't retain their values. 

If you need to do initialization, you should handle init separately (perhaps as part of a cron job) and save the results into the datastore/cloud storage/cloud SQL.
 
 
-----------------
-Vinny P
Technology & Media Advisor
Chicago, IL

App Engine Code Samples: http://www.learntogoogleit.com

Gilberto Torrezan Filho

unread,
Apr 24, 2014, 1:50:59 PM4/24/14
to google-a...@googlegroups.com
Let me see if I understood correctly: are you saying a instance of my entire VM are launched every time a request is handled by the GCE engine? All my singleton classes (DAOs, default values, some utilities) are reinstantiated each request?

I don't save sensitive state in memory (I use Memcache/Datastore for that), but some objects cloud be reused among requests, the way it works on regular GAE frontend requests.

Vinny P

unread,
Apr 24, 2014, 5:03:57 PM4/24/14
to google-a...@googlegroups.com
No. Instances don't get reloaded per request with Endpoints. That would be a terrible waste of resources.

Sorry, I probably should have clarified/explained more in my previous email, but I was in a bit of a rush when I wrote that. Endpoints doesn't support static methods ( see this article, scroll down to the API Methods header ) unless they're marked as private. When OP tried to run his static method, it may not have run or failed off.

In addition, I cheated a little bit on the answer and noted that the OP cross-posted his question to SO, where he said that he needed data tables precomputed during init. That's something that really needs to be moved to a regular cron or similar. 

@OP/Mike: Can you post a simple test case?

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-appengine.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages