You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Zaid Jamal Saeed Al Mahmoud <za...@kustar.ac.ae> on 2014/01/22 20:38:29 UTC
iPOJO Components instantiated but no visible output
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\\Desktop\\plugins\\HelloService_1.0.0.201401222235.jar");
b.start();
Bundle c = bundleContext1.installBundle("file:C:\\Users\\zaid.almahmoud\\Desktop\\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.
Re: iPOJO Components instantiated but no visible output
Posted by "Guillaume Sauthier (OW2/GMail)" <gu...@gmail.com>.
Notice that DefaultInstanceDeclaration is in a private package of iPOJO.
So I assume that there are some duplicate packages under the hood that
causes this issue...
--G
2014/1/24 Zaid Jamal Saeed Al Mahmoud <za...@kustar.ac.ae>
> 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
>
>
RE: iPOJO Components instantiated but no visible output
Posted by Zaid Jamal Saeed Al Mahmoud <za...@kustar.ac.ae>.
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 <za...@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 <za...@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 <za...@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
RE: iPOJO Components instantiated but no visible output
Posted by Zaid Jamal Saeed Al Mahmoud <za...@kustar.ac.ae>.
I even checked iPOJO API for the DefaultInstanceDeclaration.
I cannot find anything related to instantiating the component All I can see is the following:
45 public DefaultInstanceDeclaration(BundleContext bundleContext, String componentName, Dictionary<String, Object> configuration) {
46 super(bundleContext, InstanceDeclaration.class);
47 m_componentName = componentName;
48 m_configuration = configuration;
49 m_componentVersion = initComponentVersion();
50 m_instanceName = initInstanceName();
51 }
Where does the API talk to the factory of the component to call the start and stop methods of the component implementation class?
Even the start method of DefaultInstanceDeclaration only registers a service like:
66 public void start() {
67 m_registration = m_bundleContext.registerService(m_type.getName(), this, getServiceProperties());
68 }
I really need to know the answer urgently because It's been a long time trying to just create a component instance. The instance is just not created.
-----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 <za...@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 <za...@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 <za...@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\\Desktop\
>>> \plugins\\HelloService_1.0.0.201401222235.jar");
>>> b.start();
>>>
>>> Bundle c =
>>> bundleContext1.installBundle("file:C:\\Users\\zaid.almahmoud\\Desktop\
>>> \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
Re: iPOJO Components instantiated but no visible output
Posted by Clement Escoffier <cl...@gmail.com>.
Hi,
Most of the issues you had come from the fact that you are embedding Felix and try to access iPOJO API and services from outside the OSGi framework. You would have run into the same issues with all the technologies you cited. The ‘regular’ setup is much easier and would not have required any additional effort.
Regards,
Clement
On 26 janv. 2014, at 19:45, Zaid Jamal Saeed Al Mahmoud <za...@kustar.ac.ae> wrote:
> 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:clement.escoffier@gmail.com]
> 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 <za...@kustar.ac.ae> 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:clement.escoffier@gmail.com]
>> 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 <za...@kustar.ac.ae> 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:guillaume.ow2@gmail.com]
>>> Sent: Sunday, January 26, 2014 12:29 PM
>>> To: users@felix.apache.org
>>> 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 <za...@kustar.ac.ae>
>>>
>>>> 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:clement.escoffier@gmail.com]
>>>> 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 <
>>>> 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.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: '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-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: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-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 <
>>>> 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\\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: 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
>>>>>
>>>>
>>>>
>>>> --------------------------------------------------------------------
>>>> - 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
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
RE: iPOJO Components instantiated but no visible output
Posted by Zaid Jamal Saeed Al Mahmoud <za...@kustar.ac.ae>.
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:clement.escoffier@gmail.com]
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 <za...@kustar.ac.ae> 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:clement.escoffier@gmail.com]
> 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 <za...@kustar.ac.ae> 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:guillaume.ow2@gmail.com]
>> Sent: Sunday, January 26, 2014 12:29 PM
>> To: users@felix.apache.org
>> 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 <za...@kustar.ac.ae>
>>
>>> 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:clement.escoffier@gmail.com]
>>> 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 <
>>> 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.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: '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-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: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-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 <
>>> 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\\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: 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
>>>>
>>>
>>>
>>> --------------------------------------------------------------------
>>> - 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
Re: iPOJO Components instantiated but no visible output
Posted by "Guillaume Sauthier (OW2/GMail)" <gu...@gmail.com>.
I still think that the easiest solution might be to use fileinstall and
declares component's instance though the config admin file support.
--G
2014-01-26 Clement Escoffier <cl...@gmail.com>
>
> On 26 janv. 2014, at 18:29, Zaid Jamal Saeed Al Mahmoud <
> zaid.almahmoud@kustar.ac.ae> 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:clement.escoffier@gmail.com]
> > 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 <
> zaid.almahmoud@kustar.ac.ae> 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:guillaume.ow2@gmail.com]
> >> Sent: Sunday, January 26, 2014 12:29 PM
> >> To: users@felix.apache.org
> >> 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 <za...@kustar.ac.ae>
> >>
> >>> 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:clement.escoffier@gmail.com]
> >>> 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-emb
> >>> e
> >>> dding.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.htmlthathis 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-co
> >>> 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: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-ip
> >>>>>> 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 <
> >>> 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\\Des
> >>>>>>> kt o p\ \plugins\\HelloService_1.0.0.201401222235.jar");
> >>>>>>> b.start();
> >>>>>>>
> >>>>>>> Bundle c =
> >>>>>>> bundleContext1.installBundle("file:C:\\Users\\zaid.almahmoud\\Des
> >>>>>>> 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: 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
> >>>>
> >>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> 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
>
>
Re: iPOJO Components instantiated but no visible output
Posted by Clement Escoffier <cl...@gmail.com>.
On 26 janv. 2014, at 18:29, Zaid Jamal Saeed Al Mahmoud <za...@kustar.ac.ae> 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:clement.escoffier@gmail.com]
> 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 <za...@kustar.ac.ae> 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:guillaume.ow2@gmail.com]
>> Sent: Sunday, January 26, 2014 12:29 PM
>> To: users@felix.apache.org
>> 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 <za...@kustar.ac.ae>
>>
>>> 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:clement.escoffier@gmail.com]
>>> 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-emb
>>> e
>>> dding.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.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: '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-co
>>> 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: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-ip
>>>>>> 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 <
>>> 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\\Des
>>>>>>> kt o p\ \plugins\\HelloService_1.0.0.201401222235.jar");
>>>>>>> b.start();
>>>>>>>
>>>>>>> Bundle c =
>>>>>>> bundleContext1.installBundle("file:C:\\Users\\zaid.almahmoud\\Des
>>>>>>> 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: 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
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
Re: iPOJO Components instantiated but no visible output
Posted by "Guillaume Sauthier (OW2/GMail)" <gu...@gmail.com>.
It's probably a timing issue.
Factory are normal OSGi services, that means that they come and go at will
(usually depends if iPOJO has activated a starting bundle); So you should
use a ServiceListener waiting for the Factory service.
Hmmm, using a ServiceTracker is probably a more easier way to achieve this.
Once the tracker gives you the Factory reference, you can use it to create
instances.
--G
2014-01-26 Zaid Jamal Saeed Al Mahmoud <za...@kustar.ac.ae>
> 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.
>
>
>
> -----Original Message-----
> From: Clement Escoffier [mailto:clement.escoffier@gmail.com]
> 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 <
> zaid.almahmoud@kustar.ac.ae> 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:guillaume.ow2@gmail.com]
> > Sent: Sunday, January 26, 2014 12:29 PM
> > To: users@felix.apache.org
> > 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 <za...@kustar.ac.ae>
> >
> >> 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:clement.escoffier@gmail.com]
> >> 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-emb
> >> e
> >> dding.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.htmlthathis 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-co
> >> 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: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-ip
> >>>>> 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 <
> >> 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\\Des
> >>>>>> kt o p\ \plugins\\HelloService_1.0.0.201401222235.jar");
> >>>>>> b.start();
> >>>>>>
> >>>>>> Bundle c =
> >>>>>> bundleContext1.installBundle("file:C:\\Users\\zaid.almahmoud\\Des
> >>>>>> 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: 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
> >>>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> 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
>
>
RE: iPOJO Components instantiated but no visible output
Posted by Zaid Jamal Saeed Al Mahmoud <za...@kustar.ac.ae>.
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.
-----Original Message-----
From: Clement Escoffier [mailto:clement.escoffier@gmail.com]
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 <za...@kustar.ac.ae> 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:guillaume.ow2@gmail.com]
> Sent: Sunday, January 26, 2014 12:29 PM
> To: users@felix.apache.org
> 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 <za...@kustar.ac.ae>
>
>> 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:clement.escoffier@gmail.com]
>> 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-emb
>> e
>> dding.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.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: '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-co
>> 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: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-ip
>>>>> 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 <
>> 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\\Des
>>>>>> kt o p\ \plugins\\HelloService_1.0.0.201401222235.jar");
>>>>>> b.start();
>>>>>>
>>>>>> Bundle c =
>>>>>> bundleContext1.installBundle("file:C:\\Users\\zaid.almahmoud\\Des
>>>>>> 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: 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
>>>
>>
>>
>> ---------------------------------------------------------------------
>> 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
Re: iPOJO Components instantiated but no visible output
Posted by Clement Escoffier <cl...@gmail.com>.
On 26 janv. 2014, at 10:54, Zaid Jamal Saeed Al Mahmoud <za...@kustar.ac.ae> 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:guillaume.ow2@gmail.com]
> Sent: Sunday, January 26, 2014 12:29 PM
> To: users@felix.apache.org
> 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 <za...@kustar.ac.ae>
>
>> 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:clement.escoffier@gmail.com]
>> 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-embe
>> dding.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.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: '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-cod
>> 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: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-ip
>>>>> 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 <
>> 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\\Des
>>>>>> kt o p\ \plugins\\HelloService_1.0.0.201401222235.jar");
>>>>>> b.start();
>>>>>>
>>>>>> Bundle c =
>>>>>> bundleContext1.installBundle("file:C:\\Users\\zaid.almahmoud\\Des
>>>>>> 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: 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
>>>
>>
>>
>> ---------------------------------------------------------------------
>> 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
RE: iPOJO Components instantiated but no visible output
Posted by Zaid Jamal Saeed Al Mahmoud <za...@kustar.ac.ae>.
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;
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:guillaume.ow2@gmail.com]
Sent: Sunday, January 26, 2014 12:29 PM
To: users@felix.apache.org
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 <za...@kustar.ac.ae>
> 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:clement.escoffier@gmail.com]
> 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-embe
> dding.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.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: '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-cod
> 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: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-ip
> >>> 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 <
> 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\\Des
> >>>> kt o p\ \plugins\\HelloService_1.0.0.201401222235.jar");
> >>>> b.start();
> >>>>
> >>>> Bundle c =
> >>>> bundleContext1.installBundle("file:C:\\Users\\zaid.almahmoud\\Des
> >>>> 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: 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
> >
>
>
> ---------------------------------------------------------------------
> 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
Re: iPOJO Components instantiated but no visible output
Posted by "Guillaume Sauthier (OW2/GMail)" <gu...@gmail.com>.
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 <za...@kustar.ac.ae>
> 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:clement.escoffier@gmail.com]
> 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-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.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: '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-ipoj
> >>> 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 <
> 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\\Deskt
> >>>> o p\ \plugins\\HelloService_1.0.0.201401222235.jar");
> >>>> b.start();
> >>>>
> >>>> Bundle c =
> >>>> bundleContext1.installBundle("file:C:\\Users\\zaid.almahmoud\\Deskt
> >>>> 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: 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
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>
RE: iPOJO Components instantiated but no visible output
Posted by Zaid Jamal Saeed Al Mahmoud <za...@kustar.ac.ae>.
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:clement.escoffier@gmail.com]
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-embedding.html
Regards,
Clement
On 25 janv. 2014, at 14:33, Zaid Jamal Saeed Al Mahmoud <za...@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 <za...@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 <za...@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-ipoj
>>> 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 <za...@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\\Deskt
>>>> o p\ \plugins\\HelloService_1.0.0.201401222235.jar");
>>>> b.start();
>>>>
>>>> Bundle c =
>>>> bundleContext1.installBundle("file:C:\\Users\\zaid.almahmoud\\Deskt
>>>> 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: 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
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: iPOJO Components instantiated but no visible output
Posted by Clement Escoffier <cl...@gmail.com>.
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 <za...@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 <za...@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 <za...@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 <za...@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
>
RE: iPOJO Components instantiated but no visible output
Posted by Zaid Jamal Saeed Al Mahmoud <za...@kustar.ac.ae>.
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 <za...@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 <za...@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 <za...@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
Re: iPOJO Components instantiated but no visible output
Posted by Clement Escoffier <cl...@gmail.com>.
Hi,
Could you try :
> ipojo:instances
Regards,
Clement
On 24 janv. 2014, at 20:49, Zaid Jamal Saeed Al Mahmoud <za...@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 <za...@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 <za...@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\\Desktop\
>>> \plugins\\HelloService_1.0.0.201401222235.jar");
>>> b.start();
>>>
>>> Bundle c =
>>> bundleContext1.installBundle("file:C:\\Users\\zaid.almahmoud\\Desktop\
>>> \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
RE: iPOJO Components instantiated but no visible output
Posted by Zaid Jamal Saeed Al Mahmoud <za...@kustar.ac.ae>.
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 <za...@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 <za...@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\\Desktop\
>> \plugins\\HelloService_1.0.0.201401222235.jar");
>> b.start();
>>
>> Bundle c =
>> bundleContext1.installBundle("file:C:\\Users\\zaid.almahmoud\\Desktop\
>> \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
Re: iPOJO Components instantiated but no visible output
Posted by Clement Escoffier <cl...@gmail.com>.
On 23 janv. 2014, at 11:15, Zaid Jamal Saeed Al Mahmoud <za...@kustar.ac.ae> wrote:
> 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?
Actually yes, that’s the issue. The bundle needs to be prepared before being usable by iPOJO. Without this step, iPOJO ignores your bundles. I don’t know how Eclipse works, but you may be able to use the ‘install time’ manipulator:
http://felix.apache.org/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-tools/apache-felix-ipojo-online-manipulator.html
Regards,
Clement
>
>
> -----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 <za...@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 <za...@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\\Desktop\
>>> \plugins\\HelloService_1.0.0.201401222235.jar");
>>> b.start();
>>>
>>> Bundle c =
>>> bundleContext1.installBundle("file:C:\\Users\\zaid.almahmoud\\Desktop\
>>> \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
>
RE: iPOJO Components instantiated but no visible output
Posted by Zaid Jamal Saeed Al Mahmoud <za...@kustar.ac.ae>.
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 <za...@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 <za...@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\\Desktop\
>> \plugins\\HelloService_1.0.0.201401222235.jar");
>> b.start();
>>
>> Bundle c =
>> bundleContext1.installBundle("file:C:\\Users\\zaid.almahmoud\\Desktop\
>> \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
Re: iPOJO Components instantiated but no visible output
Posted by Clement Escoffier <cl...@gmail.com>.
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 <za...@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 <za...@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\\Desktop\
>> \plugins\\HelloService_1.0.0.201401222235.jar");
>> b.start();
>>
>> Bundle c =
>> bundleContext1.installBundle("file:C:\\Users\\zaid.almahmoud\\Desktop\
>> \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
RE: iPOJO Components instantiated but no visible output
Posted by Zaid Jamal Saeed Al Mahmoud <za...@kustar.ac.ae>.
By the way. I don't build my bundles using Ant task or Maven.
I just export it in eclipse as a deployable plugin.
Is that a problem?
Zaid
-----Original Message-----
From: Zaid Jamal Saeed Al Mahmoud [mailto:zaid.almahmoud@kustar.ac.ae]
Sent: Thursday, January 23, 2014 11:30 AM
To: users@felix.apache.org
Subject: RE: iPOJO Components instantiated but no visible output
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 <za...@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\\Desktop\
> \plugins\\HelloService_1.0.0.201401222235.jar");
> b.start();
>
> Bundle c =
> bundleContext1.installBundle("file:C:\\Users\\zaid.almahmoud\\Desktop\
> \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
RE: iPOJO Components instantiated but no visible output
Posted by Zaid Jamal Saeed Al Mahmoud <za...@kustar.ac.ae>.
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 <za...@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\\Desktop\
> \plugins\\HelloService_1.0.0.201401222235.jar");
> b.start();
>
> Bundle c =
> bundleContext1.installBundle("file:C:\\Users\\zaid.almahmoud\\Desktop\
> \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
RE: iPOJO Components instantiated but no visible output
Posted by Zaid Jamal Saeed Al Mahmoud <za...@kustar.ac.ae>.
Thanks. But what are the steps to launch the command ?
Note that I am not deploying my bundles using commands, I am embedding the code into my application, where I load and unload bundles.
Do you mean to make my app as an OSGI bundle and then launch it on a command ?
-----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 <za...@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\\Desktop\
> \plugins\\HelloService_1.0.0.201401222235.jar");
> b.start();
>
> Bundle c =
> bundleContext1.installBundle("file:C:\\Users\\zaid.almahmoud\\Desktop\
> \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
Re: iPOJO Components instantiated but no visible output
Posted by Clement Escoffier <cl...@gmail.com>.
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 <za...@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\\Desktop\\plugins\\HelloService_1.0.0.201401222235.jar");
> b.start();
>
> Bundle c = bundleContext1.installBundle("file:C:\\Users\\zaid.almahmoud\\Desktop\\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.
>