Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Registering resources when the bundle starts and deregistering when it stops
Registering resources when the bundle starts and deregistering when it stops [message #1705008] Tue, 11 August 2015 11:53 Go to next message
Antoni Mylka is currently offline Antoni MylkaFriend
Messages: 14
Registered: January 2015
Junior Member
I have a bundle that provides a widget class that depends on some static resources.

I want to register those resources when the bundle starts and unregister them when the bundle stops.

I can't register and unregister resources in the BundleActivator because ResourceManager can only be accessed in the UI thread.

I can't register and unregister resources in the ApplicationConfiguration because the application doesn't know what components are available at runtime. The bundle is part of a larger framework where UI components can appear and disappear dynamically.

It's not a workbench application, so I can't use the extension point.

I can register resources in the constructor of my widget using the idiom:

if (!RWT.getResourceManager().isRegistered(name)) {
    RWT.getResourceManager().register(name, stream);
}


but this has disadvantages:


  • Is it thread-safe? What happens if I do a cold start and 100 users establish 100 sessions at the same time. AFAIU in the worst case 50 may try to write while other 50 may read from it. How is the integrity of the rwt-resources folder guaranteed if it's shared between sessions but cannot be modified outside a session?
  • I can't deregister the resources when the bundle is stopped and uninstalled. In our use case the corresponding files in the resources folder will never be deleted. We'd like our UI components to be dynamically installable, startable, stoppable and uninstallable without trace.


I know I can write a ServiceHandler and serve the resources myself but is there a better way?
Re: Registering resources when the bundle starts and deregistering when it stops [message #1705049 is a reply to message #1705008] Tue, 11 August 2015 15:52 Go to previous message
Antoni Mylka is currently offline Antoni MylkaFriend
Messages: 14
Registered: January 2015
Junior Member
I copied all resources into the bundle and wrote a ServiceHandler. It accepts a 'path' parameter and passes that path to getClass().getResourceAsStream().

http://host:port/rap?servicehandler=handlerId&cid=6c07a581&path=path/to/style.css

Unfortunately it doesn't work because as it turns out my CSS files contain relative links to fonts and images like this:

background-image: url("../img/icons.png")

Given the normal rules of relative URL resolution, this does NOT yield:

http://host:port/rap?servicehandler=handlerId&cid=6c07a581&path=path/img/icons.png;

Instead it gives:

http://host:port/img/icons.png;

... which obviously doesn't work.

So I can't use ResourceManager and I can't write a ServiceHandler.

I can write my own mechanism for this, have a servlet that will track some resource provider services in the OSGI environment. Then resources can appear and disappear without involving the UI thread and their lifecycles can be synchronized with the bundle, not with the Application.

But ... am I missing something obvious?

[Updated on: Wed, 12 August 2015 07:32]

Report message to a moderator

Previous Topic:Session Timeout causes last-second user event
Next Topic:Rap examples doesn't work in MS Edge
Goto Forum:
  


Current Time: Fri Sep 20 16:52:25 GMT 2024

Powered by FUDForum. Page generated in 0.03856 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top