Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » How can I force refresh Java service to reload it in Sirius?(Sirius Java Service)
How can I force refresh Java service to reload it in Sirius? [message #1822523] Mon, 09 March 2020 11:06 Go to next message
Yufei Zhou is currently offline Yufei ZhouFriend
Messages: 24
Registered: March 2020
Junior Member
Hello,
I was trying to do a little trick in Sirius. I need to define some operations which is user-editable in my custom model, so I was saving a config file in my viewpoint specification project and load it to memory in the Java Service's constructor. Therefore I met a problem that when the config file changes, the Java Service class does not response to the change in time. I have to change the Service.java file and resave to make it effective. So is there anyway I can force reload the Service class (which means run the Service class's constructor method again) by a tool or some other methods? I don't want to read the config file in non-constructor methods because file I/Os are expensive and I hope to only do it once after every change.
Thanks very much for your help!
Re: How can I force refresh Java service to reload it in Sirius? [message #1822540 is a reply to message #1822523] Mon, 09 March 2020 15:16 Go to previous messageGo to next message
Maxime Porhel is currently offline Maxime PorhelFriend
Messages: 496
Registered: July 2009
Location: Nantes, France
Senior Member
Hi Yufei,

As documented in https://www.eclipse.org/sirius/doc/specifier/general/Writing_Queries.html#service_methods, please remember that Quote:
Java service methods should be stateless. There is no guarantee that two successive invocations of the same service method on two model elements (or even on the same one) will use the same instance of the service class.


You have no clue on when Sirius will call your constructor, so you should create a "configure" method that will be called by the constructor but also when your config model changes. For that you might put a listener to be notified on changes on this resource:

- Is this resource stored as an EMF model ? in this case it will be referenced from the session, and reloaded on changes by Sirius, then you would just have to provide a ResourceSyncClient for example to be notified from changes.
- If you file is a configuration file and not a model, you might add a org.eclipse.core.resources.IResourceChangeListener with ResourcesPlugin.getWorkspace().addResourceChangeListener(). If the org.eclipse.core.resources.IResourceChangeEvent comes from your resource, you will call your "configure" method

Regards


Maxime Porhel - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius

Join the Sirius community at SiriusCon. Register for free: Nov. 9th Paris
http://www.siriuscon.org/
Re: How can I force refresh Java service to reload it in Sirius? [message #1822589 is a reply to message #1822540] Tue, 10 March 2020 10:11 Go to previous message
Yufei Zhou is currently offline Yufei ZhouFriend
Messages: 24
Registered: March 2020
Junior Member
That helps a lot and thank you very much.
Previous Topic:Elements not showing in the representation
Next Topic:Exception when creating a new Representation
Goto Forum:
  


Current Time: Fri Oct 23 03:37:51 GMT 2020

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

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

Back to the top