Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6898495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:18:12+00:00 2026-05-27T07:18:12+00:00

I want to use Restlet to process requests for some information, but this information

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:18:12+00:00Added an answer on May 27, 2026 at 7:18 am

    From the Restlet book and their public source code, they simply use the getApplication() function from the Resource class:

    public class Application extends org.restlet.Application {
    
        public static void main(String... args) throws Exception {
            // Create a component with an HTTP server connector
            final Component comp = new Component();
            comp.getServers().add(Protocol.HTTP, 3000);
    
            // Attach the application to the default host and start it
            comp.getDefaultHost().attach("/v1", new Application());
            comp.start();
        }
    
        private final ObjectContainer container;
    
        /**
         * Constructor.
         */
        public Application() {
            /** Open and keep the db4o object container. */
            EmbeddedConfiguration config = Db4oEmbedded.newConfiguration();
            config.common().updateDepth(2);
            this.container = Db4oEmbedded.openFile(config, System
                    .getProperty("user.home")
                    + File.separator + "restbook.dbo");
        }
    
        @Override
        public Restlet createInboundRoot() {
            final Router router = new Router(getContext());
    
            // Add a route for user resources
            router.attach("/users/{username}", UserResource.class);
    
            // Add a route for user's bookmarks resources
            router.attach("/users/{username}/bookmarks", BookmarksResource.class);
    
            // Add a route for bookmark resources
            final TemplateRoute uriRoute = router.attach(
                    "/users/{username}/bookmarks/{URI}", BookmarkResource.class);
            uriRoute.getTemplate().getVariables().put("URI",
                    new Variable(Variable.TYPE_URI_ALL));
    
            return router;
        }
    
        /**
         * Returns the database container.
         * 
         * @return the database container.
         */
        public ObjectContainer getContainer() {
            return this.container;
        }
    }
    
    
    /** resource class (UserResource.java) has these functions
    /**
     * Returns the parent application.
     * 
     * @return the parent application.
     */
    @Override
    public Application getApplication() {
        return (Application) super.getApplication();
    }
    
    /**
     * Returns the database container.
     * 
     * @return the database container.
     */
    public ObjectContainer getContainer() {
        return getApplication().getContainer();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want use some data from a website with web service. i have a
I want use ORDER BY RAND() query mysql. But I have some question want
I want use $.ajax to read some infomation from xml file,here is my js
I want use from multiple upload image in codeigniter but problem is here that
I want use php simple xml parse some tree like this. how to plus
So I want use multiple div tags that use webkit borders but for some
I want use JQuery mobile for the front-end of my mobile application, but I
i want to use title on text. is this possible to make title on
I have class in server side and I want use method of this class
I want to make use of RESTlet RESTful web-services. The architechture will make use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.