You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Martin Lichtin <li...@yahoo.com> on 2017/06/02 18:23:15 UTC
Karaf 4 - how to set properties for commands
In Karaf 3, a command can be defined in Blueprint as:
<command>
<action class="my.Cmd">
<property name="producerTemplate" ref="producerTemplate" />
</action>
</command>
where in my case "producerTemplate" comes from a CamelContext created in the same Blueprint context.
Now in Karaf 4, how would I do the same, i.e. set the property?
- Martin
Re: Karaf 4 - how to set properties for commands
Posted by Martin Lichtin <li...@yahoo.com>.
Right, thanks. @Reference should really support a filter, not just for this case.
Also, exposing local beans as services seems a clumsy way, just to be able to use them in commands.
On 17.06.2017 09:52, Christian Schneider wrote:
> The karaf @Reference annotation is not only a special annotation. The karaf commands are run completely independent of the blueprint container.
> So the only way to use a blueprint bean from a command is to export it as a service. As the @Reference does not have a filter you should use a specific interface for this service that is unique.
>
> Christian
>
> 2017-06-16 18:36 GMT+02:00 Martin Lichtin <lichtin@yahoo.com <ma...@yahoo.com>>:
>
> Hi Achim
>
> Right, I can still use the "old"-style with Blueprint. But all this code is marked as deprecated.
> So I'm desparately trying to find a solution using the "new"-style Karaf commands, as the old-style will disappear.
> I would not spend time on this, if it wasn't marked deprecated.
>
> I could switch if BlueprintContainer.getComponentInstance("id") was fixed, so I could use the ids as set in Blueprint cfg file.
>
> - Martin
>
> On 15.06.2017 10:03, Achim Nierbeck wrote:
>
> Hi Martin,
>
> afaik you still can also use the "old" style with blueprint.
> As you are using blueprint anyway that shouldn't be much of a big deal.
> The idea about the new command way is to not depend on blueprint for Karaf internals.
>
> The @Reference annotation is actually a karaf own annotation,
> org.apache.karaf.shell.api.action.lifecycle.Reference
> There is no filtering available on that annotation.
>
> regards, Achim
>
>
> 2017-06-15 8:38 GMT+02:00 Martin Lichtin <lichtin@yahoo.com <ma...@yahoo.com> <mailto:lichtin@yahoo.com <ma...@yahoo.com>>>:
>
> So far I could not find a way to do this in the new Karaf command framework.
> A command is now instantiated each time it is invoked.
> It can use OSGi services (@Reference) but there doesn't seem to be a way to set a filter for it.
> I can access the BlueprintContainer (it's available as a service), but not the beans by their name.
> oh well..
>
>
>
> On 02.06.2017 20 <tel:02.06.2017%2020>:23, Martin Lichtin wrote:
>
> In Karaf 3, a command can be defined in Blueprint as:
>
> <command>
> <action class="my.Cmd">
> <property name="producerTemplate" ref="producerTemplate" />
> </action>
> </command>
>
> where in my case "producerTemplate" comes from a CamelContext created in the same Blueprint context.
>
> Now in Karaf 4, how would I do the same, i.e. set the property?
>
> - Martin
>
> --
>
> Apache Member
> Apache Karaf <http://karaf.apache.org/> Committer & PMC
> OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/ <http://wiki.ops4j.org/display/paxweb/Pax+Web/>> Committer & Project Lead
> blog <http://notizblog.nierbeck.de/>
> Co-Author of Apache Karaf Cookbook <http://bit.ly/1ps9rkS>
>
> Software Architect / Project Manager / Scrum Master
>
Re: Re: Karaf 4 - how to set properties for commands
Posted by Christian Schneider <ch...@die-schneider.net>.
The karaf @Reference annotation is not only a special annotation. The karaf
commands are run completely independent of the blueprint container.
So the only way to use a blueprint bean from a command is to export it as a
service. As the @Reference does not have a filter you should use a specific
interface for this service that is unique.
Christian
2017-06-16 18:36 GMT+02:00 Martin Lichtin <li...@yahoo.com>:
> Hi Achim
>
> Right, I can still use the "old"-style with Blueprint. But all this code
> is marked as deprecated.
> So I'm desparately trying to find a solution using the "new"-style Karaf
> commands, as the old-style will disappear.
> I would not spend time on this, if it wasn't marked deprecated.
>
> I could switch if BlueprintContainer.getComponentInstance("id") was
> fixed, so I could use the ids as set in Blueprint cfg file.
>
> - Martin
>
> On 15.06.2017 10:03, Achim Nierbeck wrote:
>
>> Hi Martin,
>>
>> afaik you still can also use the "old" style with blueprint.
>> As you are using blueprint anyway that shouldn't be much of a big deal.
>> The idea about the new command way is to not depend on blueprint for
>> Karaf internals.
>>
>> The @Reference annotation is actually a karaf own annotation,
>> org.apache.karaf.shell.api.action.lifecycle.Reference
>> There is no filtering available on that annotation.
>>
>> regards, Achim
>>
>>
>> 2017-06-15 8:38 GMT+02:00 Martin Lichtin <lichtin@yahoo.com <mailto:
>> lichtin@yahoo.com>>:
>>
>> So far I could not find a way to do this in the new Karaf command
>> framework.
>> A command is now instantiated each time it is invoked.
>> It can use OSGi services (@Reference) but there doesn't seem to be a
>> way to set a filter for it.
>> I can access the BlueprintContainer (it's available as a service),
>> but not the beans by their name.
>> oh well..
>>
>>
>>
>> On 02.06.2017 20 <tel:02.06.2017%2020>:23, Martin Lichtin wrote:
>>
>> In Karaf 3, a command can be defined in Blueprint as:
>>
>> <command>
>> <action class="my.Cmd">
>> <property name="producerTemplate" ref="producerTemplate"
>> />
>> </action>
>> </command>
>>
>> where in my case "producerTemplate" comes from a CamelContext
>> created in the same Blueprint context.
>>
>> Now in Karaf 4, how would I do the same, i.e. set the property?
>>
>> - Martin
>>
>>
>>
>>
>> --
>>
>> Apache Member
>> Apache Karaf <http://karaf.apache.org/> Committer & PMC
>> OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer
>> & Project Lead
>> blog <http://notizblog.nierbeck.de/>
>> Co-Author of Apache Karaf Cookbook <http://bit.ly/1ps9rkS>
>>
>> Software Architect / Project Manager / Scrum Master
>>
>>
>
--
--
Christian Schneider
http://www.liquid-reality.de
<https://owa.talend.com/owa/redir.aspx?C=3aa4083e0c744ae1ba52bd062c5a7e46&URL=http%3a%2f%2fwww.liquid-reality.de>
Open Source Architect
http://www.talend.com
<https://owa.talend.com/owa/redir.aspx?C=3aa4083e0c744ae1ba52bd062c5a7e46&URL=http%3a%2f%2fwww.talend.com>
Re: Re: Karaf 4 - how to set properties for commands
Posted by Martin Lichtin <li...@yahoo.com>.
Hi Achim
Right, I can still use the "old"-style with Blueprint. But all this code is marked as deprecated.
So I'm desparately trying to find a solution using the "new"-style Karaf commands, as the old-style will disappear.
I would not spend time on this, if it wasn't marked deprecated.
I could switch if BlueprintContainer.getComponentInstance("id") was fixed, so I could use the ids as set in Blueprint cfg file.
- Martin
On 15.06.2017 10:03, Achim Nierbeck wrote:
> Hi Martin,
>
> afaik you still can also use the "old" style with blueprint.
> As you are using blueprint anyway that shouldn't be much of a big deal.
> The idea about the new command way is to not depend on blueprint for Karaf internals.
>
> The @Reference annotation is actually a karaf own annotation,
> org.apache.karaf.shell.api.action.lifecycle.Reference
> There is no filtering available on that annotation.
>
> regards, Achim
>
>
> 2017-06-15 8:38 GMT+02:00 Martin Lichtin <lichtin@yahoo.com <ma...@yahoo.com>>:
>
> So far I could not find a way to do this in the new Karaf command framework.
> A command is now instantiated each time it is invoked.
> It can use OSGi services (@Reference) but there doesn't seem to be a way to set a filter for it.
> I can access the BlueprintContainer (it's available as a service), but not the beans by their name.
> oh well..
>
>
>
> On 02.06.2017 20 <tel:02.06.2017%2020>:23, Martin Lichtin wrote:
>
> In Karaf 3, a command can be defined in Blueprint as:
>
> <command>
> <action class="my.Cmd">
> <property name="producerTemplate" ref="producerTemplate" />
> </action>
> </command>
>
> where in my case "producerTemplate" comes from a CamelContext created in the same Blueprint context.
>
> Now in Karaf 4, how would I do the same, i.e. set the property?
>
> - Martin
>
>
>
>
> --
>
> Apache Member
> Apache Karaf <http://karaf.apache.org/> Committer & PMC
> OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer & Project Lead
> blog <http://notizblog.nierbeck.de/>
> Co-Author of Apache Karaf Cookbook <http://bit.ly/1ps9rkS>
>
> Software Architect / Project Manager / Scrum Master
>
Re: Karaf 4 - how to set properties for commands
Posted by Achim Nierbeck <bc...@googlemail.com>.
Hi Martin,
afaik you still can also use the "old" style with blueprint.
As you are using blueprint anyway that shouldn't be much of a big deal.
The idea about the new command way is to not depend on blueprint for Karaf
internals.
The @Reference annotation is actually a karaf own annotation,
org.apache.karaf.shell.api.action.lifecycle.Reference
There is no filtering available on that annotation.
regards, Achim
2017-06-15 8:38 GMT+02:00 Martin Lichtin <li...@yahoo.com>:
> So far I could not find a way to do this in the new Karaf command
> framework.
> A command is now instantiated each time it is invoked.
> It can use OSGi services (@Reference) but there doesn't seem to be a way
> to set a filter for it.
> I can access the BlueprintContainer (it's available as a service), but
> not the beans by their name.
> oh well..
>
>
>
> On 02.06.2017 20:23, Martin Lichtin wrote:
>
>> In Karaf 3, a command can be defined in Blueprint as:
>>
>> <command>
>> <action class="my.Cmd">
>> <property name="producerTemplate" ref="producerTemplate" />
>> </action>
>> </command>
>>
>> where in my case "producerTemplate" comes from a CamelContext created in
>> the same Blueprint context.
>>
>> Now in Karaf 4, how would I do the same, i.e. set the property?
>>
>> - Martin
>>
>
--
Apache Member
Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer &
Project Lead
blog <http://notizblog.nierbeck.de/>
Co-Author of Apache Karaf Cookbook <http://bit.ly/1ps9rkS>
Software Architect / Project Manager / Scrum Master
Re: Karaf 4 - how to set properties for commands
Posted by Martin Lichtin <li...@yahoo.com>.
So far I could not find a way to do this in the new Karaf command framework.
A command is now instantiated each time it is invoked.
It can use OSGi services (@Reference) but there doesn't seem to be a way to set a filter for it.
I can access the BlueprintContainer (it's available as a service), but not the beans by their name.
oh well..
On 02.06.2017 20:23, Martin Lichtin wrote:
> In Karaf 3, a command can be defined in Blueprint as:
>
> <command>
> <action class="my.Cmd">
> <property name="producerTemplate" ref="producerTemplate" />
> </action>
> </command>
>
> where in my case "producerTemplate" comes from a CamelContext created in the same Blueprint context.
>
> Now in Karaf 4, how would I do the same, i.e. set the property?
>
> - Martin