[ 
https://issues.apache.org/jira/browse/FELIX-2815?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12991246#comment-12991246
 ] 

Richard S. Hall commented on FELIX-2815:
----------------------------------------

I'm not sure how else to say it. Defining the component is equivalent to 
defining a class that implements some interface. Creating and instance of the 
component is equivalent to doing "new" on the a class. Just like a class is not 
an instance of its implemented interfaces until you actually create an object, 
neither does a component actually provide its service until it is instantiated. 
The only difference between the two is that a componen may have dependencies 
that if not satisfied may prevent the instance from being created, thus 
preventing its service from being published and this can also change at 
runtime. Otherwise, the concepts are the same.

To give you an example of why you might want this, imagine you have some class 
that provides some remote service on a configurable port number. In Java you 
might do something like this:

    Service s1 = new org.foo.ServiceImpl(6666);
    Service s2 = new org.foo.ServiceImpl(6667);
    Service s2 = new org.foo.ServiceImpl(6668);

In iPOJO you could specify the port as a configurable property in your 
<component> declaration, then you could do something like this:

    <instance component="org.foo.ServiceImpl">
        <property name="port" value="6666"/>
    </instance>
    <instance component="org.foo.ServiceImpl">
        <property name="port" value="6667"/>
    </instance>
    <instance component="org.foo.ServiceImpl">
        <property name="port" value="6668"/>
    </instance>

So, just like classes and objects separate types and instances in Java, 
components and component instances provide the same separation in iPOJO.

> Difference between "instance" and "provides"
> --------------------------------------------
>
>                 Key: FELIX-2815
>                 URL: https://issues.apache.org/jira/browse/FELIX-2815
>             Project: Felix
>          Issue Type: Bug
>          Components: iPOJO
>            Reporter: Andriyko
>            Assignee: Clement Escoffier
>              Labels: documentation, felix,, ipojo
>
> In the documentation on iPOJO Services:
> http://felix.apache.org/site/providing-osgi-services.html#ProvidingOSGiservices-Instancereconfiguration
> There is no clear explanation of what is the difference between <provides> 
> and <instance>.
> It is not clear why "instance" is needed at all.
> Under the "Service Properties" heading on the page, the two are used 
> interchangeably in the examples.
> For example, first "property" is configured with <provides>:
> <component classname="...FooProviderType1">
>             <provides>
>                         <property name="foo" field="m_foo" value="Foo"/>
>                         <property name="static" type="java.lang.String" 
> value="this is a static property"/>
>             </provides>
> </component>
> and then immediately, with no explanation what-so-ever and <intsance> is 
> used, with a tiny explanation that "The value can be given in the instance 
> configuration":
> <instance component="...FooProviderType1">
>    <property name="foo" value="My New Foo Value"/>
>    <property name="static" value="My Value For Static"/>
> </instance>

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to