Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » At what Point to insert a singleton class into the model?
At what Point to insert a singleton class into the model? [message #987874] Wed, 28 November 2012 08:25 Go to next message
Alex Kipling is currently offline Alex Kipling
Messages: 250
Registered: July 2012
Senior Member
I have a Singleton class, which should do some work, every time when a new Object is inserted into the Context.

If it would be in the model - I could do something like that inside the Singleton:

@Inject
onChange(MyClass monitor){
 //do the work here
}


What would be the best way to attach the Singleton to model, in order to monitor MyClass changes inside the context?
Re: At what Point to insert a singleton class into the model? [message #987877 is a reply to message #987874] Wed, 28 November 2012 08:34 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph Keimel
Messages: 347
Registered: December 2010
Location: Germany
Senior Member
Ideas that come to mind:
1) Add it to the Model as an AddOn
2) Create and add the instance to the application context manualy on @PostContextCreate in your life cycle handler.

You should probably use @Optional too, since there will probably not be a MyClass in the context on creation of your singleton.
Re: At what Point to insert a singleton class into the model? [message #987878 is a reply to message #987874] Wed, 28 November 2012 08:37 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk Fauth
Messages: 1263
Registered: July 2012
Senior Member
As far as I have understood, I would suggest to create your Singleton not as a Singleton, but as a POJO. Then annotate your class with @Creatable and @Singleton, and let the container do the "magic".

If you need to create your Singleton yourself with some initialization parameters or whatever, I guess a lifecycle hook method annotated with @PostContextCreate would be the best place to add it to the context.
Re: At what Point to insert a singleton class into the model? [message #987883 is a reply to message #987878] Wed, 28 November 2012 09:12 Go to previous message
Alex Kipling is currently offline Alex Kipling
Messages: 250
Registered: July 2012
Senior Member
Thnx Dirk, Christoph!
The @Creatable approach is what i need.

An other way could be using context.runAndTrack(new RunAndTrack()) to track object changes in context.
Previous Topic:How to create a handler by id?
Next Topic:XWT ValidationRule question
Goto Forum:
  


Current Time: Sat Aug 30 22:37:06 EDT 2014

Powered by FUDForum. Page generated in 0.13101 seconds