Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » BundleContext - ServiceTracker
BundleContext - ServiceTracker [message #488244] Sat, 26 September 2009 15:57 Go to next message
Walter Mising name is currently offline Walter Mising nameFriend
Messages: 128
Registered: July 2009
Senior Member
In E4 - RCP application, how to get the instance of BundleContext so that it
can be used in ServiceTracker.
Or is there a different way to get the instance of ServiceTracker instead of
ServiceTracker oSTEventAdmin = new ServiceTracker(bundlecontext,
EventAdmin.class.getName(), null);

My Objective is to get the EventAdmin service in E4.

- Walter.
Re: BundleContext - ServiceTracker [message #488392 is a reply to message #488244] Mon, 28 September 2009 14:11 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

For the simple cases, you can just ask your part IEclipseContext (the topmost application context talks to OSGi).

ex: context.get(EventAdmin.class.getName())

Otherwise you need your context to set up your ServiceTracker yourself: org.osgi.framework.FrameworkUtil (1.3) can get your Bundle if you don't have an activator

PW


Re: BundleContext - ServiceTracker [message #489326 is a reply to message #488392] Fri, 02 October 2009 13:04 Go to previous messageGo to next message
Walter Mising name is currently offline Walter Mising nameFriend
Messages: 128
Registered: July 2009
Senior Member
Hi Paul,

Context is null
---------------

Bundle oB = org.osgi.framework.FrameworkUtil.getBundle ( oClass ) ;
System.out.println ( "Bundle: " + oB ) ;
System.out.println ( "BundleContext: " + oB.getBundleContext ( ) ) ;

Output
--------
Bundle: com.javacraft.trader_1.0.0.qualifier [66]
BundleContext: null

Any idea why the context is null ?

Thanks,
Best Regards,
Walter G. Prabhakar.

"Paul Webster" <pwebster@ca.ibm.com> wrote in message
news:h9qg5p$uol$1@build.eclipse.org...
> For the simple cases, you can just ask your part IEclipseContext (the
> topmost application context talks to OSGi).
>
> ex: context.get(EventAdmin.class.getName())
>
> Otherwise you need your context to set up your ServiceTracker yourself:
> org.osgi.framework.FrameworkUtil (1.3) can get your Bundle if you don't
> have an activator
>
> PW
>
> --
> Paul Webster
> http://wiki.eclipse.org/Platform_Command_Framework
> http://wiki.eclipse.org/Command_Core_Expressions
> http://wiki.eclipse.org/Menu_Contributions
Re: BundleContext - ServiceTracker [message #489658 is a reply to message #489326] Mon, 05 October 2009 13:50 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Walter wrote on Fri, 02 October 2009 09:04
Hi Paul,

Context is null
---------------

Bundle oB = org.osgi.framework.FrameworkUtil.getBundle ( oClass ) ;
System.out.println ( "Bundle: " + oB ) ;
System.out.println ( "BundleContext: " + oB.getBundleContext ( ) ) ;

Output
--------
Bundle: com.javacraft.trader_1.0.0.qualifier [66]
BundleContext: null

Any idea why the context is null ?


Has that bundle been started yet? See the javadoc for getBundleContext() which explains when it will return null.

PW


Re: BundleContext - ServiceTracker [message #563525 is a reply to message #488244] Mon, 28 September 2009 14:11 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

For the simple cases, you can just ask your part IEclipseContext (the topmost application context talks to OSGi).

ex: context.get(EventAdmin.class.getName())

Otherwise you need your context to set up your ServiceTracker yourself: org.osgi.framework.FrameworkUtil (1.3) can get your Bundle if you don't have an activator

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions


Re: BundleContext - ServiceTracker [message #563595 is a reply to message #563525] Fri, 02 October 2009 13:04 Go to previous messageGo to next message
Walter Mising name is currently offline Walter Mising nameFriend
Messages: 128
Registered: July 2009
Senior Member
Hi Paul,

Context is null
---------------

Bundle oB = org.osgi.framework.FrameworkUtil.getBundle ( oClass ) ;
System.out.println ( "Bundle: " + oB ) ;
System.out.println ( "BundleContext: " + oB.getBundleContext ( ) ) ;

Output
--------
Bundle: com.javacraft.trader_1.0.0.qualifier [66]
BundleContext: null

Any idea why the context is null ?

Thanks,
Best Regards,
Walter G. Prabhakar.

"Paul Webster" <pwebster@ca.ibm.com> wrote in message
news:h9qg5p$uol$1@build.eclipse.org...
> For the simple cases, you can just ask your part IEclipseContext (the
> topmost application context talks to OSGi).
>
> ex: context.get(EventAdmin.class.getName())
>
> Otherwise you need your context to set up your ServiceTracker yourself:
> org.osgi.framework.FrameworkUtil (1.3) can get your Bundle if you don't
> have an activator
>
> PW
>
> --
> Paul Webster
> http://wiki.eclipse.org/Platform_Command_Framework
> http://wiki.eclipse.org/Command_Core_Expressions
> http://wiki.eclipse.org/Menu_Contributions
Re: BundleContext - ServiceTracker [message #563615 is a reply to message #489326] Mon, 05 October 2009 13:50 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Walter wrote on Fri, 02 October 2009 09:04
> Hi Paul,
>
> Context is null
> ---------------
>
> Bundle oB = org.osgi.framework.FrameworkUtil.getBundle ( oClass ) ;
> System.out.println ( "Bundle: " + oB ) ;
> System.out.println ( "BundleContext: " + oB.getBundleContext ( ) ) ;
>
> Output
> --------
> Bundle: com.javacraft.trader_1.0.0.qualifier [66]
> BundleContext: null
>
> Any idea why the context is null ?


Has that bundle been started yet? See the javadoc for getBundleContext() which explains when it will return null.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions


Previous Topic:converting existing rcp application to e4 based
Next Topic:Why is it that on double click on view tab , it doesn't expand
Goto Forum:
  


Current Time: Fri Apr 19 20:04:00 GMT 2024

Powered by FUDForum. Page generated in 0.03558 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top