Hi,
On 23.03.11 16:37, "Henrik Niehaus" <[email protected]> wrote: >Hi felix users, > >I'm thinking about using iPojo to create component instances >programatically. I have a class OsdSession, which represents a user >session and has dependencies to several services. The OsdSession itself >runs as a thread and handles user interaction until the user explicitly >ends the session. >My idea was to use iPojo to create new instances of the OsdSession, >because then I don't have to create all the service lookup / handling, >but let iPojo inject all dependencies. > >I played around with ipojo and I'm now able to create a new instance >like so (simplified): > >@Component >public class OsdSession implements Runnable {...} > >@Component >public class Activator { > >@Requires(filter = "(factory.name=de.berlios.vch.osdserver.OsdSession)") >private Factory sessionFactory; > >private OsdSession createSession() throws UnacceptableConfiguration, >MissingHandlerException, ConfigurationException { > InstanceManager instance = (InstanceManager) >sessionFactory.createComponentInstance(null); > instance.start(); > OsdSession session = (OsdSession) instance.createPojoObject(); >} > >} > >But with this code I have to check, if the instance is valid and call >the validate and invalidate method and do all the stuff, which ipojo >normally does for me. > >My goal was to get the same behaviour as if I had defined the instance >in the metadata.xml. But instead of having only one instance, I want to >create them, when they are needed. > >Another point is, that the instances should be disposed if the user >session ends, so that everything gets cleaned up and I don't leak memory. > >What do you think about my approach? Is there a way to do this? Maybe >there are other approaches to solve this kind of problems? You should let iPOJO creates the pojo object for you, and not call createPojoObject. If you want to force the object creation, use @Component(immediate=true). To retrieve the created object, just use InstanceManager.getPojoObject() Regards, Clement > > >Tanks in advance, >Henrik > >--------------------------------------------------------------------- >To unsubscribe, e-mail: [email protected] >For additional commands, e-mail: [email protected] > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

