Hi Apart from looking at existing providers such as the MongoDB, Filesystem, and BundleResource Providers in SVN as well as the Cassandra ResourceProvider mentioned by Robert, here are some generic answers: Am 07.11.2013 um 13:39 schrieb Jan Algermissen <[email protected]>:
> Hi, > > I am complteley new to Sling and tasked with creating a ResourceProvider > implementation. I have been digging thorugh the docs for a while but, > honestly, would appreciate some help :-) > > My ResourceProvider needs to contact an upstream HTTP server(s), so it needs > to use an HTTP client, preferably the Apache HTTP Client. Performance and > concurrency requirements are very high - I am not building a pet project. > This raises a number of questions for me: > > - Where do I best put the HTTP client instance and where do I configure it? > It is likely a caching client and I plan to make it multi-threaded, too (use > a connection pooling configuration for the Apache client) > I am looking for the right spot of the Sling runtime here, to wire the > client to. IIRC Sling does not come with Apache Http Components. But you can take the Http Components bundles and deploy them in Sling. This should give you access to the API. It might be a good idea, though if your ResourceProvider would configure its own specialized Http Components configuration instance. I would think that this is possible with the Http Components bundles. Just make sure to cleanup any client and configuration instances you configure when the ResourceProvider is stopped. > > - Or is there maybe a client instance in the Sling runtime that I can just > obtain and use from within my ResourceResolver? > > - Do I have to write a Factory for my Resolver? And how does a Sling > application specify it wants to work with resource from my provider? IOW, How > does the bootstrapping work? Depends. In the simplest form you don’t need a ResourceProviderFactory. You just write a ResourceProvider and register it as a service. See the FileSystem ResourceProvider as a simple example. The simple form has two disadvantages, though: It does not support different users and it has to be implemented thread-safely because the same instance is used for all ResourceResolver instances. To support users (with optional authentication) or non-thread-safe ResourceProvider instances, you have to implement a ResourceProviderFactory. In this case the factory is called for each ResourceResolver that is being created by the ResourceResolverFactory. > > - Do I also have to write a ResourceResolver and bootstrap that, too? Or does > the runtime provide its own to my ResourcePorvider? No, the existing ResourceResolverFactory will pick up your ResourceProvider and hook in into the ResourceResolvers created. > > - Will instances of my ResourceProvider be used concurrently, or is a new > instance created for every request to sling? See above: Plain ResourceProvider services will be used concurrently. ResourceProvider instances created through a ResourceProviderFactory service are unique to each ResourceResolver and thus are not used concurrently. > > - How do I obtain a reference to my (global) HTTP client inside my > ResourceProvider? It is up to your implementation on how you settup the HTTP client. > > Excuse the big bunch of newbie questions, but I feel I need hands-on > information directly as opposed digging around - especially the concurrency > and bootstrapping aspects I'd really like to not mess up :-) Hope this helps. Regards Felix > > Jan >
