Thank you for the examples, these are very good and clarify creating instances. 
 This will work well in this scenario with a single class creating multiple 
instances with different configurations.

If i could ask, related to another scenario,  related to config admin in 
singleton instances.   i’d like to have some parameters on singleton service 
providers that can be configured and persisted if need be (but not 
necessarily).  Any recommendations on the easiest path would be helpful?

For example, I have the following POJO:
@Component
@Instantiate
@Provides
public class HelloTest1 implements HelloTest {

    @ServiceProperty(name = "message", value = "Hello")
    private String message;

    @Override
    public String getMessage() {
        return message;
    }
}

Say, if i change “message” to something other than Hello?   When i try in 
Karaf, doing:

config:edit com.hdscores.test.HelloTest1-0
config:property-set message “Huh?”
config:update


What it does, it creates a new instance on HelloTest1 and keeps the original 
one, a ipojo:instances reveals:
Instance com.hdscores.test.HelloTest1.02fb3a2b-6522-4874-ad56-5a03b0632c70 -> 
valid
Instance com.hdscores.test.HelloTest1-0 


is this normal?   I thought the creation policy was a singleton by default.   
is this due to the limitation of Instantiate that doesn’t allow service 
configuration?   or is this an issue with the karaf config commands?

Thanks again for all the help!


> On Mar 5, 2015, at 12:53 PM, Matthias Jeschke <[email protected]> wrote:
> 
> Hi,
> 
> Here is a small example to create a configuration for a pax-jdbc database
> (org.ops4j.datasource is the service factory pid):
> 
> @Requires
> private ConfigurationAdmin configurationAdmin;
> 
> Configuration conf =
> configurationAdmin.createFactoryConfiguration("org.ops4j.datasource", "?");
> Dictionary<String, String> props = new Hashtable<>();
> props.put("osgi.jdbc.driver.name", "mysql");
> props.put("databaseName", "ipojotest");
> props.put("user", "xxx");
> props.put("password", "yyy");
> props.put("dataSourceName", "ipojotestsrc");
> conf.update(props);
> 
> On Thu, Mar 5, 2015 at 7:12 PM, clement escoffier <
> [email protected]> wrote:
> 
>> Hi,
>> 
>> Instead of creating the instance with the @Configuration, you may have to
>> create them using 'cfg' files. 'cfg' files are read by Karaf that store the
>> configuration into the Config Admin. Then, iPOJO read the configuration
>> from the Config Admin.
>> 
>> Cheers,
>> 
>> Clement
>> 
>> 2015-03-05 16:49 GMT+01:00 Andrew Phillips <[email protected]>:
>> 
>>> I think i figured it out.   Sorry to be trouble.  I figured out that the
>>> karat config management can change the configuration, but if there isn’t
>> a
>>> configuration file set up, it doesn’t show it in the config:list.
>>> 
>>>> On Mar 5, 2015, at 7:19 AM, Andy Phillips <[email protected]>
>>> wrote:
>>>> 
>>>> I appreciate the feedback, not to be a pain, could you give me an
>>> example?
>>>> 
>>>> 
>>>> 
>>>>> On Mar 5, 2015, at 6:25 AM, Matthias Jeschke <[email protected]>
>>> wrote:
>>>>> 
>>>>> Hi,
>>>>> 
>>>>> After creating the instances I think you have to create the
>>> configuration.
>>>>> What I did was to inject the ConfigurationAdmin and then create a new
>>>>> configuration (with the respective managed service pid) via
>>>>> "createFactoryConfiguration()".
>>>>> 
>>>>> Best regards
>>>>> 
>>>>> Matthias
>>>>> 
>>>>> 
>>>>> On Thu, Mar 5, 2015 at 1:09 PM, Andrew Phillips <
>>> [email protected]>
>>>>> wrote:
>>>>> 
>>>>>> I am using iPojo and trying to create some instances of a component
>>> with
>>>>>> different configuration and tying the configuration to the Config
>>> Admin in
>>>>>> karat (so it can be managed with the config commands).
>>>>>> 
>>>>>> No matter what i do, i cannot get the configuration of these
>> instances
>>> to
>>>>>> show up when i do a config:list in karat.   Any help would be greatly
>>>>>> appreciated!
>>>>>> 
>>>>>> Here is how i am creating the instances:
>>>>>> 
>>>>>> Instance instance =
>>> Instance.instance().of(MapQuestGeocodeProvider.class)
>>>>>> 
>>> .named("com.hdscores.geocode.mapquest.MapQuetGeocodeOpenProvider")
>>>>>> 
>>>>>> 
>>> 
>> .with("managed.service.pid").setto("com.hdscores.geocode.mapquest.MapQuetGeocodeOpenProvider")
>>>>>>      .with(MapQuestGeocodeProvider.API_URL).setto("
>>>>>> http://open.mapquestapi.com/geocoding/v1/address";)
>>>>>> 
>>>>>> 
>>> 
>> .with(MapQuestGeocodeProvider.API_KEY).setto("Fmjtd%7Cluur2d6anu%2C7g%3Do5-9ab55u")
>>>>>>      .with(Constants.SERVICE_RANKING).setto("10")
>>>>>>      .with(GeocodeServiceProperties.USE_IN_MANAGER).setto("true");
>>>>>> 
>>>>>> Instance instance2 =
>>> Instance.instance().of(MapQuestGeocodeProvider.class)
>>>>>> 
>>>>>> 
>> .named("com.hdscores.geocode.mapquest.MapQuetGeocodeLicensedProvider")
>>>>>> 
>>>>>> 
>>> 
>> .with("managed.service.pid").setto("com.hdscores.geocode.mapquest.MapQuetGeocodeLicensedProvider")
>>>>>>      .with(MapQuestGeocodeProvider.API_URL).setto("
>>>>>> http://www.mapquestapi.com/geocoding/v1/address";)
>>>>>> 
>>>>>> 
>>> 
>> .with(MapQuestGeocodeProvider.API_KEY).setto("Gmjtd%7Cluur2gutnq%2C2l%3Do5-lrasd")
>>>>>>      .with(Constants.SERVICE_RANKING).setto("1")
>>>>>>      .with(GeocodeServiceProperties.USE_IN_MANAGER).setto("true”);
>>>>>> 
>>>>>> the GeocodeProvider class starts off like this:
>>>>>> 
>>>>>> @Component()
>>>>>> @Provides(strategy = “SERVICE")
>>>>>> public class MapQuestGeocodeProvider implements GeocodeService {
>>>>>> 
>>>>>>  public static final String API_URL = "apiUrl";
>>>>>>  public static final String API_KEY = "apiKey";
>>>>>> 
>>>>>>  private Client client;
>>>>>> 
>>>>>>  @ServiceProperty(name = GeocodeServiceProperties.USE_IN_MANAGER)
>>>>>>  private boolean useInManager;
>>>>>> 
>>>>>>  @ServiceProperty(name=API_URL)
>>>>>>  private String apiUrl;
>>>>>> 
>>>>>>  @ServiceProperty(name=API_KEY)
>>>>>>  private String apiKey;
>>>>>> 
>>>>>> 
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: [email protected]
>>>>>> For additional commands, e-mail: [email protected]
>>>>>> 
>>>>>> 
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [email protected]
>>> For additional commands, e-mail: [email protected]
>>> 
>>> 
>> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to