Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8830619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:08:12+00:00 2026-06-14T08:08:12+00:00

I am trying to run a demo application for OSGi EventAdmin service, but the

  • 0

I am trying to run a demo application for OSGi EventAdmin service, but the EventHandler I implemented fails to listen the events posted by the EventAdmin publisher:

Below is the code for Event Publisher, followed by the code for Listener(EventHandler):

public class Publisher implements BundleActivator{

static EventAdmin eventAdmin;
ServiceReference ref;
static HashMap properties= null;

@Override
public void start(BundleContext context) throws Exception {
    ref=context.getServiceReference(EventAdmin.class.getName());

    if(ref==null){
        System.err.println("Unable to aquire EventAdmin Ser Ref.");
    }

    eventAdmin=(EventAdmin) context.getService(ref);
    if(eventAdmin==null){
        System.err.println("unable to get service:EventAdmin");
    }

    properties=new HashMap();
    properties.put("XYZ", "Test");
    Event event = new Event("lnu/test/event/Demo", properties);
    eventAdmin.postEvent(event);
    System.out.println("event posted");

}

@Override
public void stop(BundleContext context) throws Exception {
    // TODO Auto-generated method stub
}
}

Code for Listener:

public class Listener implements BundleActivator, EventHandler {    

public void start(BundleContext context) {
Dictionary d = new Hashtable();

d.put(EventConstants.EVENT_TOPIC, "lnu/test/event/Demo" );

context.registerService( EventHandler.class.getName(),
this, d );
System.out.println("event handler is registered now");
}

public void stop( BundleContext context) {}

public void handleEvent(Event event ) {
System.err.println("Event has been captured");
System.out.println("getTopic: "+event.getTopic());
System.out.println("getproperty: "+event.getProperty("XYZ"));
}
}

The print statements in the code show that the event has been posted by the publisher and the Listener is registered with the EventHandler service but still it does not invokes handleEvent method on the listener side, I don’t know why? and can’t understand what is happening behind the scene. There are no runtime exceptions/errors.

The IDE used is Eclipse Juno Build id: 20120614-1722 with Equinox.

Following Target Platform bundles are included in the run configuration:

  1. org.eclipse.osgi
  2. org.eclipse.equinox.event
  3. org.eclipse.equinox.util
  4. org.eclipse.osgi.services

Can some one point me what I am missing or doing wrong? Or if you have some link to working example of OSGi EventAdmin service?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:08:13+00:00Added an answer on June 14, 2026 at 8:08 am

    I would guess that your listener bundle is being registered after the publisher bundle has already posted the Event.

    Testing this in the start methods of the bundles is error prone for this reason unless you control the start order of the bundles. I would suggest for this simple test that you start a separate thread in your publisher to post an event every few seconds. The listener should start getting them once it is registered.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to run Jison unit tests, but the command fails. How do I fix
I am trying to run demo SamplePush application of GCM. When I install it
I'm trying to run the Selenium Grid Demo successfully but I'm having a problem.
As many other newbies to java and android i'm trying to run gcm demo
I am trying to run demo code from Matplotlib: the legend_picking example . This
I'm trying to run NVidia's OpenCL demo oclNbody.exe on ATI Radeo 4850 card and
When I was trying to run the Qt::Phonon::VideoPlayer demo code, I got strange bug.
I am getting the following errors when trying to run my application: Can you
I'm trying to run a demo project downloaded from GITHUB. And inside it, it
I'm trying to run a Web Audio API demo using a nightly build of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.