|
Re: registering handlers [message #1032024 is a reply to message #1031924] |
Tue, 02 April 2013 13:36 |
|
Phill,
The key used to register the service handler must be unique across the entire application, but each handler is associated with a particular user session (Display). You can use an integer counter, UUID, or some other mechanism to ensure the id is unique. You should also unregister the handler when it is no longer needed. For instance, if your download corresponds the contents of some table, then it probably makes sense to unregister it when the table is disposed. To make it available for an entire user session, you could put the registration your EntryPoint.createUI() method. I believe RAP will cleanup the registration automatically when the user session is disposed.
Hope that helps,
Cole
|
|
|
|
Re: registering handlers [message #1037965 is a reply to message #1032024] |
Wed, 10 April 2013 08:28 |
|
Hi Cole,
your statement about the scope of ServiceHandlers is not correct, let me
clarify. ServiceHandlers are like simple servlets, they are registered
with the (application-scoped) ServiceManager and have application scope
itself, not session scope.
> ... each handler is associated with a particular user session (Display)
No, code in a ServiceHandler has access to the user's Display, but the
ServiceHandler does not have session scope.
> I believe RAP will cleanup the
> registration automatically when the user session is disposed.
Since they have application scope, that's not the case. If you don't
unregister a service handler, it will remain in place as long as the
application keeps running.
Therefore I would not recommend to create new service handlers for every
user session. I would rather create one service handler in the
application configuration and use it for all sessions.
If you have an idea how we can make this more clear in the documentation
or API, your input is very appreciated.
Best regards,
Ralf
--
Ralf Sternberg
Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/
Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
|
|
|
|
Re: registering handlers [message #1038782 is a reply to message #1038118] |
Thu, 11 April 2013 10:05 |
|
Hi Phill,
I don't have the one ideal solution for you, but some suggestions:
1) You can create a separate ServiceHandler for every single UISession,
but you have to make sure to unregister the handlers correctly. For me
it just doesn't feel right to create so many service handlers in the
application scope and there is the risk to create a memory leak.
2) The custom component could provide an initialize() method that is
called from the application configuration. In this initialize method,
the component could register resources, service handlers, etc. However,
this involves a dependency from the application to the custom widget.
Most of the times you'll prefer loose coupling instead. Moreover, when
the component needs a reference to the application, you end up with a
circular dependency.
2) If the application does not know about the custom component, the
component can only be initialized when it is first accessed, i.e.
lazily. You can do so by storing the service handler in the
ApplicationContext using setAttribute() and create it only if doesn't
exist yet. You'll have to make sure that this code is thread safe. RAP
does not yet provide support for ApplicationSingletons, which would
probably be helpful for those cases.
3) Depending on your environment, you could also consider to register a
servlet with the HttpService or the servlet API. In a servlet you can't
access the UISession, but you can access the HttpSession, where all
user-related information should be kept. So if you store whatever the
servlet needs in the HttpSession (UISession.getHttpSession()), a servlet
could be an alternative.
HTH, Ralf
--
Ralf Sternberg
Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/
Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
|
|
|
Powered by
FUDForum. Page generated in 0.05253 seconds