Thank you Mr. Clement and Mr. Guillaume for your help during the previous days.
I once read that iPOJO was made to simplify the development of OSGI applications. But looking at all these things I need to set in order to create an iPOJO instance, I find that iPOJO is actually complicating my life. Probably the reason why I find iPOJO complicated is because I am new to iPOJO, and I am missing its concept. But based on my experience, I highly recommend more documentation for iPOJO syntax. It is really cumbersome to go the APIs and to try to get the syntax for a specific task. I am not saying there is no documentation. Actually, I liked how the website is organized with different tutorials, but these tutorials are more concept-oriented rather than showing how you can achieve something by a java code. During the last month, I have been experimenting with different component models including OSGI Declarative Services, iPOJO, Fractal, Frascati , and SCA. The simplest and richest one I found so far is The Declarative Service. Meanwhile, I will go with that one to achieve my needs. Perhaps, I will come back in the future, and learn more about iPOJO. Thanks again, and good luck with whatever you are doing. I am sure it is a great and valuable work. Zaid -----Original Message----- From: Clement Escoffier [mailto:[email protected]] Sent: Sunday, January 26, 2014 10:26 PM To: Apache Felix - Users Mailing List Subject: Re: iPOJO Components instantiated but no visible output On 26 janv. 2014, at 18:29, Zaid Jamal Saeed Al Mahmoud <[email protected]> wrote: > You are right. It is a java application, not a component. > > I did this: > > ServiceReference factoryServiceReference= > m_felix.getBundleContext().getServiceReference(HelloService.class.getName()); > Factory factory > =(Factory)m_felix.getBundleContext().getService(factoryServiceReference); > ComponentInstance x= > factory.createComponentInstance(null); > x.start(); > > But I got: java.lang.NullPointerException: Specified service reference cannot > be null. There are several issues: 1) Why do you retrieve a service reference exposing HelloService while you want Factory 2) Unfortunately with your settings (retrieving services form outside the OSGi framework) it won't be that easy. This should work: ServiceReference[] references = m_felix.getBundleContext().getServiceReferences(Factory.class.getName(), "(factory.name=...)"); if (references == null) { System.out.println("No references"); } else { Object factory = m_felix.getBundleContext().getService(references[0]); } Unfortunately, all access to the retrieved service will be done using reflection. To avoid this, you can try to configure the Felix launcher to export the iPOJO packages from the system bundle (by setting org.osgi.framework.system.packages.extra). You should have a look to the 'Using Services Provided By Bundles' from http://felix.apache.org/site/apache-felix-framework-launching-and-embedding.html Regards, Clement > > > > -----Original Message----- > From: Clement Escoffier [mailto:[email protected]] > Sent: Sunday, January 26, 2014 5:24 PM > To: Apache Felix - Users Mailing List > Subject: Re: iPOJO Components instantiated but no visible output > > > On 26 janv. 2014, at 10:54, Zaid Jamal Saeed Al Mahmoud > <[email protected]> wrote: > >> Thank you Mr. Guillaume. >> >> Where you mentioned, " Get the iPOJO Factory service (associated with the >> type/component you want to instantiate) and call Factory.createInstance(...)" >> >> I would love to achieve that. But I am seeking since a week for the syntax >> code to achieve that. Here's what I did: >> >> In my Java Application: >> >> @Requires(filter="(factory.name=my-factory)") >> private Factory factory; > > The @Requires only works in iPOJO component. According to your setup, this > code is not an iPOJO component (Am I wrong ?). You have to do the service > lookup using the bundle context to retrieve the Factory service. > > > Regards, > > Clement > > > >> >> THEN, >> >> ComponentInstance instance = >> factory.createComponentInstance(null); >> instance.start(); >> >> This keeps raising a Null Pointer Exception that factory is NULL. But my >> bundle has a component with the name factory and that bundle is up and >> running, and I can see that my-factory is alive as well by the command: >> >> g! ipojo:factories >> Factory my-factory (VALID) >> >> >> Can you just help me with the right syntax of getting a factory service, so >> I can instantiate my component. Thanks. >> >> >> >> >> -----Original Message----- >> From: Guillaume Sauthier (OW2/GMail) [mailto:[email protected]] >> Sent: Sunday, January 26, 2014 12:29 PM >> To: [email protected] >> Subject: Re: iPOJO Components instantiated but no visible output >> >> No, DefaultInstanceDeclaration CANNOT be used at the moment from outside of >> iPOJO bundle. >> This is a dead-end. >> >> A common use case is to define type (component) and instance statically: >> using the metadata.xml iPOJO description file. >> >> A more dynamic use case is to only create instance dynamically >> (type/components are still statically described). >> In that case, there are plenty solutions available: >> * Get the iPOJO Factory service (associated with the type/component >> you want to instantiate) and call Factory.createInstance(...) >> * Using ConfigAdmin: you create Configuration objects and push them >> the the CA service. iPOJO will obtain that configuration and create >> the instance for you >> >> You talked a bit about the all dynamic use case. I must tell that it's mode >> complexe and probably less adapted to all cases. >> Imagine that you have a class designed for another component model: scr, dm, >> blueprint, ... >> You don't want to change the code of these classes: the so-called iPOJO API >> is for you. >> You'll be able to tell iPOJO to modify/manipulate the class bytecode and >> make it a full-blown iPOJO component. >> And then, that API facilitate you the instance creation (but it's the >> Factory methods that are used behind the hood). >> >> Is this clearer ? >> So in your case, I would suggest you to start with metadata.xml (or >> annotations) to describes types of components. >> And then create instances through config admin. >> I would also suggest you to take a look at file install that have a nice >> file format to declares configuration dynamically. >> >> --G >> >> >> 2014/1/26 Zaid Jamal Saeed Al Mahmoud <[email protected]> >> >>> Thank you Mr. Clement for your response. >>> >>> Actually, I prefer to create the component types dynamically. >>> Therefore, annotations is not my first preference when it comes to >>> creating the component type. As I mentioned earlier, I am targeting >>> ipojo APIs. The more things are dynamic, the happier I will be. >>> >>> I've been reading in the link you sent me to configure the framework. >>> It is not clear in that page which properties are used to solve my >>> class loader issue. I've tried the following properties: >>> >>> org.osgi.framework.system.packages.extra >>> >>> org.osgi.framework.bundle.parent: >>> >>> I suspected the later one since its description says, "Specifies >>> which class loader is used for boot delegation", and you mentioned >>> that I am using the wrong class loader. >>> >>> I tried to configure the framework with different values for those >>> properties but none of them helped solving my issues. My instance is >>> still not available. >>> >>> I'd appreciate it if you can possibly be more specific regarding >>> which property/properties I need to set when configuring Felix, so >>> it helps me solving the problem. >>> >>> Thanks again for your help. >>> >>> >>> >>> Zaid >>> -----Original Message----- >>> From: Clement Escoffier [mailto:[email protected]] >>> Sent: Saturday, January 25, 2014 6:32 PM >>> To: Apache Felix - Users Mailing List >>> Subject: Re: iPOJO Components instantiated but no visible output >>> >>> Hi, >>> >>> >>> The example you just gave use the iPOJO API. This API is intended to >>> create component types (i.e. factories) dynamically which does not >>> seem to be what you want. This way works but is really cumbersome as >>> you can't use the annotations. >>> >>> What I proposed you was to use either the config admin or the >>> factory service or instance declarations. It looks like iPOJO can't >>> see your instance declaration because they are exposed using the >>> wrong class loader (from code outside the OSGi framework). I >>> realized the issue when reading all your mails again. To get it to >>> work this way, check how to configure the framework to avoid class >>> loader mismatch between code from inside and outside the framework: >>> http://felix.apache.org/site/apache-felix-framework-launching-and-em >>> b >>> e >>> dding.html >>> >>> Regards, >>> >>> Clement >>> >>> >>> On 25 janv. 2014, at 14:33, Zaid Jamal Saeed Al Mahmoud < >>> [email protected]> wrote: >>> >>>> Dear Mr. Clement, >>>> >>>> I really want to know so bad, why you told the person in this post: >>> http://apache-felix.18485.x6.nabble.com/Using-iPOJO-API-to-create-components-and-instances-td4881802.htmlthat >>> his code should work if he used the following way: >>>> >>>> new PrimitiveComponentType() >>>> .setBundleContext(localContext) >>>> .setClassName(ProviderA.class.getName()) >>>> .setValidateMethod("start") >>>> .setInvalidateMethod("stop") >>>> .addService(new Service()) >>>> .createInstance("TestProviderA"); >>>> >>>> But you told me not to use this way and to use >>> DefaultInstanceDeclaration instead. >>>> >>>> This really confused me because I saw an answer for you in the same >>>> post >>> with the following code: >>>> >>>> type = new >>> PrimitiveComponentType().setBundleContext(bundle.getBundleContext()) >>>> .setComponentTypeName("raw.type") >>>> .setClassName("org.apache.felix.ipojo.test.asm.Raw") >>>> .setImmediate(true); >>>> type.start(); >>>> >>>> instance = type.createInstance(); >>>> >>>> >>>> What's different in my case? I can maybe switch to the other way if >>> Declaration Instance doesn't work. So, I need a clarification from you. >>>> >>>> >>>> >>>> Zaid >>>> >>>> -----Original Message----- >>>> From: Zaid Jamal Saeed Al Mahmoud >>>> Sent: Saturday, January 25, 2014 12:03 AM >>>> To: '[email protected]' >>>> Subject: RE: iPOJO Components instantiated but no visible output >>>> >>>> Yes. This is the output: >>>> >>>> ipojo:instances >>>> Instance org.apache.felix.ipojo.arch.gogo.Arch-0 -> valid >>>> >>>> >>>> >>>> -----Original Message----- >>>> From: Clement Escoffier [mailto:[email protected]] >>>> Sent: Saturday, January 25, 2014 12:01 AM >>>> To: Apache Felix - Users Mailing List >>>> Subject: Re: iPOJO Components instantiated but no visible output >>>> >>>> Hi, >>>> >>>> Could you try : >>>> >>>>> ipojo:instances >>>> >>>> Regards, >>>> >>>> Clement >>>> >>>> On 24 janv. 2014, at 20:49, Zaid Jamal Saeed Al Mahmoud < >>> [email protected]> wrote: >>>> >>>>> Hey, I manipulated my bundle using Ipojo Ant Task, as the following: >>>>> >>>>> <project> >>>>> <target name="main"> >>>>> <!-- Change the path to point on the iPOJO Ant task jar--> >>>>> <taskdef name="ipojo" >>>>> classname="org.apache.felix.ipojo.task.IPojoTask" >>>>> >>> classpath="C:/Users/zaid.almahmoud/Dropbox/EBTIC/ADERE/feasibility-c >>> o >>> d >>> es/ipojo/ipojo-distribution-1.11.0/bundle/org.apache.felix.ipojo.ant >>> - >>> 1 >>> .11.0.jar"/> >>>>> <ipojo >>>>> >>> input="C:/Users/zaid.almahmoud/Desktop/plugins/HelloService_1.0.0.201401222235.jar" >>>>> >>> output="C:/Users/zaid.almahmoud/Desktop/plugins/Manipulated_HelloService.jar" >>>>> /> >>>>> </target> >>>>> </project> >>>>> >>>>> >>>>> Now, I can see in my app that the factory is valid. This is the >>>>> output >>> in the command: >>>>> g! ipojo:factories >>>>> Factory my-factory (VALID) >>>>> Factory org.apache.felix.ipojo.arch.gogo.Arch (UNKNOWN) - Private >>>>> >>>>> Therefore the factory "my-factory" is available unlike before. >>>>> >>>>> >>>>> However, my instance is not available, which was created as the >>> following: >>>>> DefaultInstanceDeclaration providerDeclaration = new >>> DefaultInstanceDeclaration(b.getBundleContext(), "my-factory"); >>>>> providerDeclaration.start(); >>>>> >>>>> Again, this does not show an error, but it doesn't display the >>>>> expected >>> output in the start() method of the bundle, and on the command, I can see: >>>>> >>>>> g! ipojo:instance my-factory-0 >>>>> Instance named 'my-factory-0' not found >>>>> >>>>> >>>>> Can you help please? Thanks. >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> -----Original Message----- >>>>> From: Zaid Jamal Saeed Al Mahmoud >>>>> [mailto:[email protected]] >>>>> Sent: Thursday, January 23, 2014 2:15 PM >>>>> To: [email protected] >>>>> Subject: RE: iPOJO Components instantiated but no visible output >>>>> >>>>> It displays this: >>>>> >>>>> ipojo:factories >>>>> Factory org.apache.felix.ipojo.arch.gogo.Arch (UNKNOWN) - Private >>>>> >>>>> >>>>> I am not sure what you mean by iPOJO manipulation on my bundles, >>>>> But again, I am not using ANT or MAVEN. I export the bundles >>>>> normally in >>> eclipse (Using export->deployable plugins and fragments). >>>>> Could it be the issue? >>>>> >>>>> >>>>> -----Original Message----- >>>>> From: Clement Escoffier [mailto:[email protected]] >>>>> Sent: Thursday, January 23, 2014 11:52 AM >>>>> To: Apache Felix - Users Mailing List >>>>> Subject: Re: iPOJO Components instantiated but no visible output >>>>> >>>>> Hi, >>>>> >>>>> The output are interesting, it looks like your instances are not >>> declared correctly. Can you try: >>>>> >>>>>> ipojo:factories >>>>> >>>>> >>>>> By the way, how are you applying the iPOJO manipulation on your >>>>> bundles >>> ? >>>>> >>>>> Regards, >>>>> >>>>> Clement >>>>> >>>>> On 23 janv. 2014, at 08:30, Zaid Jamal Saeed Al Mahmoud < >>> [email protected]> wrote: >>>>> >>>>>> Okay, I did that. Here's the output: >>>>>> >>>>>> g! ipojo:instances >>>>>> Instance org.apache.felix.ipojo.arch.gogo.Arch-0 -> valid >>>>>> >>>>>> g! ipojo:instance my-factory-0 >>>>>> g! Instance named 'my-factory-0' not found >>>>>> >>>>>> g! ipojo:instance my-consumer-factory-0 Instance named >>>>>> 'my-consumer-factory-0' not found >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -----Original Message----- >>>>>> From: Clement Escoffier [mailto:[email protected]] >>>>>> Sent: Thursday, January 23, 2014 10:58 AM >>>>>> To: Apache Felix - Users Mailing List >>>>>> Subject: Re: iPOJO Components instantiated but no visible output >>>>>> >>>>>> Hi, >>>>>> >>>>>> Could you use the 'instances' command to retrieve the list of >>> instances and their state ? >>>>>> (http://felix.apache.org/documentation/subprojects/apache-felix-i >>>>>> p >>>>>> oj >>>>>> o >>>>>> /apache-felix-ipojo-tools/ipojo-arch-command.html) >>>>>> >>>>>>> ipojo:instances >>>>>> // dump all instances and declaration >>>>>>> ipojo:instance my-factory-0 >>>>>> // introspect the first instance >>>>>>> ipojo:instance my-consumer-factory-0 >>>>>> // introspect the second instance >>>>>> >>>>>> Regards, >>>>>> >>>>>> Clement >>>>>> >>>>>> >>>>>> On 22 janv. 2014, at 20:38, Zaid Jamal Saeed Al Mahmoud < >>> [email protected]> wrote: >>>>>> >>>>>>> I have 2 iPOJO Components. >>>>>>> 1- A Provider bundle that provides "Hello" service. Below is the >>> implementation of the component: >>>>>>> package helloipojo; >>>>>>> >>>>>>> >>>>>>> import helloipojo.service.HelloService; >>>>>>> >>>>>>> import org.apache.felix.ipojo.annotations.Component; >>>>>>> import org.apache.felix.ipojo.annotations.Invalidate; >>>>>>> import org.apache.felix.ipojo.annotations.Provides; >>>>>>> import org.apache.felix.ipojo.annotations.Validate; >>>>>>> >>>>>>> >>>>>>> @Component(name="my-factory") >>>>>>> @Provides >>>>>>> public class HelloServiceImpl implements HelloService{ >>>>>>> >>>>>>> @Override >>>>>>> public void sayHello() { >>>>>>> >>>>>>> System.out.println("Hello iPojo!"); >>>>>>> >>>>>>> } >>>>>>> >>>>>>> >>>>>>> @Validate >>>>>>> public void start() throws Exception { >>>>>>> >>>>>>> System.out.println("Hello, I am ipojo bundle start method"); >>>>>>> >>>>>>> } >>>>>>> >>>>>>> @Invalidate >>>>>>> public void stop() throws Exception { >>>>>>> >>>>>>> System.out.println("Bye Bye, I am ipojo bundle stop method"); >>>>>>> >>>>>>> } >>>>>>> >>>>>>> >>>>>>> >>>>>>> } >>>>>>> 2- Consumer bundle that uses HelloService object as the follwing: >>>>>>> package helloserviceconsumer; >>>>>>> >>>>>>> import helloipojo.service.HelloService; >>>>>>> >>>>>>> import org.apache.felix.ipojo.annotations.Component; >>>>>>> import org.apache.felix.ipojo.annotations.Invalidate; >>>>>>> import org.apache.felix.ipojo.annotations.Requires; >>>>>>> import org.apache.felix.ipojo.annotations.Validate; >>>>>>> >>>>>>> @Component(name="my-consumer-factory") >>>>>>> public class HelloConsumer { >>>>>>> @Requires >>>>>>> HelloService helloObject; >>>>>>> >>>>>>> @Validate >>>>>>> private void start() { >>>>>>> // Starting method >>>>>>> //... >>>>>>> helloObject.sayHello(); >>>>>>> //... >>>>>>> } >>>>>>> >>>>>>> @Invalidate >>>>>>> protected void stop() { >>>>>>> // Stopping method >>>>>>> if(helloObject!=null) { >>>>>>> helloObject.sayHello(); } >>>>>>> >>>>>>> else System.out.println("hello service GONE!"); >>>>>>> } >>>>>>> } >>>>>>> In a seperate Java application, I load these two bundles and >>>>>>> start >>> them on Apache Felix as the following: >>>>>>> Bundle b = >>>>>>> bundleContext1.installBundle("file:C:\\Users\\zaid.almahmoud\\De >>>>>>> s kt o p\ \plugins\\HelloService_1.0.0.201401222235.jar"); >>>>>>> b.start(); >>>>>>> >>>>>>> Bundle c = >>>>>>> bundleContext1.installBundle("file:C:\\Users\\zaid.almahmoud\\De >>>>>>> s kt o p\ >>>>>>> \plugins\\HelloServiceConsumer_1.0.0.201401222257.jar"); >>>>>>> c.start(); >>>>>>> All the above works fine. >>>>>>> Now, I would like to instantiate these two components >>>>>>> dynamically and >>> observe the consumption of the bundle provider service by the bundle >>> consumer. I used Instance Declaration, as the following: >>>>>>> DefaultInstanceDeclaration providerDeclaration = new >>> DefaultInstanceDeclaration(b.getBundleContext(), "my-factory"); >>>>>>> providerDeclaration.start(); >>>>>>> >>>>>>> DefaultInstanceDeclaration consumerDeclaration = new >>> DefaultInstanceDeclaration(c.getBundleContext(), >>> "my-consumer-factory"); >>>>>>> consumerDeclaration.start(); No errors >>>>>>> when running the application. However, I could not see the "Hello" >>> Messages that exists in the start() methods of both the service >>> provider and consumer. I see absolutely NOTHING. That means the >>> components are not instantiated correctly. Where did I go wrong? Thanks. >>>>>>> >>>>>>> >>>>>>> >>>>>>> Zaid. >>>>>>> >>>>>> >>>>>> >>>>>> ----------------------------------------------------------------- >>>>>> - >>>>>> -- >>>>>> - 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] >>>>> >>>>> >>>>> ------------------------------------------------------------------ >>>>> - >>>>> -- 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] >>>>> >>>> >>>> >>>> ------------------------------------------------------------------- >>>> - >>>> - 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] >>>> >>> >>> >>> -------------------------------------------------------------------- >>> - 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] >> > > > --------------------------------------------------------------------- > 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] > --------------------------------------------------------------------- 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]

