felix-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Henrik Niehaus <henrik.nieh...@gmx.de>
Subject Create component instances programatically
Date Wed, 23 Mar 2011 15:37:14 GMT
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?


Tanks in advance,
Henrik

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Mime
View raw message