Hi, Dan,
Our extension is an impl of FactoryBeanListener, looks like:
public class RegistryFactoryBeanListener implements FactoryBeanListener {
public void handleEvent(Event ev, AbstractServiceFactoryBean factory,
Object... args) {
switch (ev) {
case CLIENT_CREATED: {
// do something
}case SERVER_CREATED: {
// do something
}
}
Now I found a solution which make changes to the service of "old" bus, to new a
new bus instead of the old one, then the extension will added to the new bus
successfully and will send the CLIENT_CREATED/ SERVER_CREATED event to the
extension class object.
With your proposal (bus.setExtension(...)), the extension also can be added to
the bus successfully, but doesn't send the events to the extension class
object, so the extension did nothing which is not we expected.
Thanks!
Xilai
-----Original Message-----
From: Daniel Kulp [mailto:[email protected]]
Sent: Tuesday, April 09, 2013 11:31 PM
To: [email protected]; XiLai Dai
Subject: Re: how to add bus extension to the existing bus on the osgi env?
On Apr 9, 2013, at 5:32 AM, XiLai Dai <[email protected]> wrote:
> Hi,
> I've tried with your suggestion but :
> bus.setExtension(.......);
> doesn't work. The only way I can find to add extension class to bus
> is by provide /META-INF/bus-extensions.txt :(
Well, what does your extension do? At some point, something would need to
query the extension in order for it to be of any use. Thus, a custom
extension that then doesn't have some sort of implementation to use it may not
be usable.
If the extension is some sort of listener (ClientLifecyleListener, etc...),
then it's quite likely that these have already been queried and cached. Thus,
you would need to grab the appropriate manager and register it manually similar
to:
bus.getExcention(ClientLifecycleManager.class).register(ext);
If the extension does something to the bus like add interceptors, it's likely
easier to just add them in your activate.
You MAY be able to do something like:
((ExtensionMangerImpl)bus.get(ExtensionManager.class)).add(ext)
but I'm not sure if that would affect anything or not.
Dan
>
> Thanks!
> Xilai
> -----Original Message-----
> From: Daniel Kulp [mailto:[email protected]]
> Sent: Monday, April 08, 2013 10:38 PM
> To: [email protected]; XiLai Dai
> Subject: Re: how to add bus extension to the existing bus on the osgi env?
>
>
> This isn't something that's "easy" to do right now, but it is possible.
>
> In your bundle activator, you can do something like:
>
> ServiceReference[] references =
> bundleContext.getServiceReferences(Bus.class.getName(), null);
> if (references != null) {
> for (ServiceReference reference : references) {
> if (reference != null) {
> Bus bus = (Bus) bundleContext.getService(reference);
> bus.setExtension(.......);
> }
> }
> }
>
> or similar to add extensions to the existing bus's. If you need to add
> things to existing services, you can extend that to something like:
>
> ServerRegistry reg = bus.getExtension(ServerRegistry.class);
> List<Server> servers = reg.getServers();
> for (Server serv : servers) {
> ... do whatever ...
> }
>
> You really cannot add anything to existing clients very easily at all as we
> do not hold onto anything client related so they can be fully garbage
> collected as appropriate.
>
>
> Dan
>
>
>
> On Apr 7, 2013, at 5:48 AM, XiLai Dai <[email protected]> wrote:
>
>> Hi,
>>
>> We have a CustomerFactoryBeanListener looks like:
>> public class RegistryFactoryBeanListener implements
>> FactoryBeanListener { public void handleEvent(Event ev,
>> AbstractServiceFactoryBean factory, Object... args) {
>> switch (ev) {
>> case CLIENT_CREATED: {
>> // do something
>> }case SERVER_CREATED: {
>> // do something
>> }
>> }
>> }
>>
>> And register this class to the bus as a extension (add a line to
>> META-INF/cxf/bus-extensions.txt)
>>
>> There have some existing cxf buses/services installed on the osgi
>> (karak) container before we install this extension bundle into
>> container, the problem is the extension isn't added to these "old"
>> buses. (it only works for the new installed buses/services)
>>
>> Is it an know issue or maybe a cxf extension problem? Any workaround? Now we
>> have to refresh the "old" bundles (with cxf bus) manually to get the
>> extension added.
>>
>> Thanks!
>> Xilai
>
> --
> Daniel Kulp
> [email protected] - http://dankulp.com/blog Talend Community Coder -
> http://coders.talend.com
>
--
Daniel Kulp
[email protected] - http://dankulp.com/blog Talend Community Coder -
http://coders.talend.com