Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Service reference life cycle(Best practice for obtaining service references)
Service reference life cycle [message #1226998] Fri, 03 January 2014 08:56 Go to next message
Patrick Mackinlay is currently offline Patrick MackinlayFriend
Messages: 10
Registered: December 2013
Junior Member
Based on the standard Scout SDK pattern, my application currently has a server service for each client form. In most cases, these forms communicate with my persistence service, which handles the internal details of interacting with the data store (the data store is not SQL based, so I'm not able to use the standard SQL support). This means that each of these form handling services need a reference to the persistence service in order to do anything with it, and of course the same is true of any other services which need to interact with each other.

My question goes to the correct way to obtain the needed service reference, with respect to the service life cycle on the server. Essentially, I can see two basic options:


  1. Grab a reference to the dependency the first time it's needed, and hold on to it indefinitely, or
  2. Obtain a reference to the dependency within each service operation that requires it, and allow it to be released when the operation is completed


Which of these two options is more correct or preferred? Is there any practical impact one way or the other on a Scout application (e.g. impact on the ability to load/unload bundles at runtime, performance, or garbage collection, etc.)?
Re: Service reference life cycle [message #1227170 is a reply to message #1226998] Fri, 03 January 2014 18:51 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
Thanks for asking this question!

I could imagine something like this:

  @Override
  public MyFormData load(MyFormData formData) {
    Person person = SERVICES.getService(PersistenceService.class).loadPerson(formData.getPersonId());
    
    //map Person in MyFormData...
    
    return formData;
  }


I never store a service reference in a class private variable (like m_persistenceService).

As far as I know:
- The service Lookup doesn't cost you the second time (the first call might cost, for example when you use lazy loading)
- Your service needs to be stateless --> so it is a bad practice to store something in a variable.

It would be great to have confirmation.

Re: Service reference life cycle [message #1228918 is a reply to message #1227170] Wed, 08 January 2014 10:48 Go to previous message
Ken Lee is currently offline Ken LeeFriend
Messages: 97
Registered: March 2012
Member
I agree with Jérémie's answer.

Jeremie Bresson wrote on Fri, 03 January 2014 13:51

- Your service needs to be stateless --> so it is a bad practice to store something in a variable.


This is exactly the reason why you shouldn't store the service as a member on your form class.

[quote ]
- The service Lookup doesn't cost you the second time (the first call might cost, for example when you use lazy loading)
[/quote]

Calling SERVICES.getService(MyService.class) will look up the given MyService in the service registry. As Jérémie said the service lookup won't have any significant performance impact. Loading the class during the first call will happen in either approach (storing as a member or calling the service via service registry). So this shouldn't be an argument to store the service in a member variable.


Previous Topic:Scout RAP target - loading RCP View not working
Next Topic:Adding TAB boxes programmatically dynamically via a button
Goto Forum:
  


Current Time: Tue Mar 19 02:16:39 GMT 2024

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

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

Back to the top