Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » E4 Dependeny Incjection of OSGi services Lifecycle handling(Design pattern)
E4 Dependeny Incjection of OSGi services Lifecycle handling [message #1784541] Thu, 29 March 2018 07:35 Go to next message
Mike Rumpf is currently offline Mike RumpfFriend
Messages: 47
Registered: July 2009
Member
Hello guys,

E4 offers the availability to inject OSGi services to its parts.

I Could write something like

@Inject
private MyService myService


However when the part is being constructed, the application has to make sure MyService is active. Otherwise a Nullpointer will be thrown by DI. Fair enough. But how do I handle this issue in the lifecycle of the E4 application. At some point I have to wait for the service activation before opening the part (or allowing the user to do so). Is there a designated place to handle such dependencies or a recommended pattern/best practise?

Best regards,
Mike



Re: E4 Dependeny Incjection of OSGi services Lifecycle handling [message #1784634 is a reply to message #1784541] Sat, 31 March 2018 06:01 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2624
Registered: July 2012
Senior Member
I think that depends on your use case. Why is your service not active when opening the part? And have you tried to use @Service for injecting the service?
Re: E4 Dependeny Incjection of OSGi services Lifecycle handling [message #1784713 is a reply to message #1784541] Tue, 03 April 2018 07:26 Go to previous messageGo to next message
Mike Rumpf is currently offline Mike RumpfFriend
Messages: 47
Registered: July 2009
Member
My part is depending on a service which relies on a server communicaton which takes some time to become established. In a normal scr environment the component would just wait for the dependent service. My e4 application also would have to wait for the service before allowing any parts to be opened.

How would adding the @Service annotation help. It doesn't mean the part would wait for the service, or?
Re: E4 Dependeny Incjection of OSGi services Lifecycle handling [message #1784760 is a reply to message #1784713] Tue, 03 April 2018 16:29 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2624
Registered: July 2012
Senior Member
That would be a bad design with regards to UI development. It is not a good UX if the user waits for the UI without a hint what happens. And IMHO it is also not a good practice to perform long running initializations in service creation. In plain OSGi maybe fine e.g. if that server communication service is the starter or another kind of immediate component. In case the communication should be triggered lazily, I would add a method to establish the connection and make the service available directly. This way you would be able to show the UI immediately and inform the user that the connection is being established. Once done you could fire an event to update the UI indicating the connection is ready.
Re: E4 Dependeny Incjection of OSGi services Lifecycle handling [message #1784768 is a reply to message #1784760] Tue, 03 April 2018 19:33 Go to previous message
Mike Rumpf is currently offline Mike RumpfFriend
Messages: 47
Registered: July 2009
Member
Of course you are right with regard to bad design. It would be much too late to wait for the "communication service" when the part is being created. When I saw the code in question my immediate thought was: I would not do it that way... ;-)

In some ways it's a pitfall for beginners since somehow you have to take care of the lifecycle of the OSGi service. It's very easy to use the Service or Inject annotation. But you have to fully understand what it implicates.
Previous Topic:Eclipse Icon font
Next Topic:Issue with -clearPersistedState option
Goto Forum:
  


Current Time: Fri Nov 16 09:27:05 GMT 2018

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

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

Back to the top