felix-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Clement Escoffier <clement.escoff...@gmail.com>
Subject Re: iPOJO Components instantiated but no visible output
Date Sat, 25 Jan 2014 14:32:29 GMT
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-embedding.html

Regards,

Clement


On 25 janv. 2014, at 14:33, Zaid Jamal Saeed Al Mahmoud <zaid.almahmoud@kustar.ac.ae>
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.html
that 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: 'users@felix.apache.org'
> 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:clement.escoffier@gmail.com]
> 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 <zaid.almahmoud@kustar.ac.ae>
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-codes/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:zaid.almahmoud@kustar.ac.ae]
>> Sent: Thursday, January 23, 2014 2:15 PM
>> To: users@felix.apache.org
>> 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:clement.escoffier@gmail.com]
>> 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 <zaid.almahmoud@kustar.ac.ae>
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:clement.escoffier@gmail.com]
>>> 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-ipojo
>>> /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 <zaid.almahmoud@kustar.ac.ae>
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\\Deskto
>>>> p\ \plugins\\HelloService_1.0.0.201401222235.jar");
>>>> b.start();
>>>> 
>>>> Bundle c =
>>>> bundleContext1.installBundle("file:C:\\Users\\zaid.almahmoud\\Deskto
>>>> 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: users-unsubscribe@felix.apache.org
>>> For additional commands, e-mail: users-help@felix.apache.org
>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
> 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message