I want to use Restlet to process requests for some information, but this information takes some time to load from disk, so I want to do this step when the Restlet server is started, rather than in my Resource class, which appears to be instantiated on each request. In other words, I want to load it into memory once.
I’m looking at this tutorial: http://www.2048bits.com/2008/06/creating-simple-web-service-with.html and am assuming that each time someone requests /Users, router.attach("/users", UserResource.class); instantiates a new UserResource() object. Let’s assume I want to load the User database into memory so that the lookups in UserResource.findUser() are fast.
Update: Maybe something like this answer can help me? https://stackoverflow.com/a/7865506/318870
Update 2: I think I found a solution, so will post back soon with my findings
From the Restlet book and their public source code, they simply use the
getApplication()function from theResourceclass: