On 08/13/2013 06:08 PM, Erik Jansman wrote:
For the implementation I have taken a look at the Felix version and I will continue to do so but seeing this discussion I makes me unsure if it's the right thing to do. I would like to see the test bundle and if possible more of the test results regarding Felix and Knopflerfish so I can better understand what is being tested and how.
You should definitely try to produce your own test results and do some profiling. I attached my test bundle which should run in any OSGi container providing the framework and event admin dependencies, plus the sources. I would also be interested in your findings, so please keep me posted.
In case the attachments are not going through to the mailing list, I added Erik's Email address CC.
Best, Sascha
perftest_1.0.0.jar
Description: application/java-archive
package eventtest;
import java.util.Dictionary;
import java.util.Hashtable;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventAdmin;
public class Activator implements BundleActivator {
/*
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
EventAdmin ea = null;
ServiceReference sr = context.getServiceReference(EventAdmin.class.getName());
if (sr != null)
{
ea = context.getService(sr);
}
if (ea != null)
{
new EventAdminTest(context, ea);
}
else
{
System.err.println("Event admin service not available");
}
}
/*
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
System.out.println("Goodbye World!!");
}
}
package eventtest;
import java.util.Dictionary;
import java.util.Hashtable;
import org.osgi.framework.BundleContext;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventAdmin;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;
public class EventAdminTest {
int event1Handled = 0;
int event2Handled = 0;
public EventAdminTest(BundleContext bc, EventAdmin ea)
{
addHandler(bc);
runSendEvents(ea);
runPostEvents(ea);
}
private void runSendEvents(EventAdmin ea)
{
long start = System.currentTimeMillis();
sendEvents(ea);
long time = System.currentTimeMillis() - start;
if(event1Handled != 100000) throw new RuntimeException("event1Handled != 100000 but is " + event1Handled);
if(event2Handled != 300000) throw new RuntimeException("event2Handled != 300000 but is " + event2Handled);
System.out.println("sending sync events took " + time + "ms");
}
private void runPostEvents(EventAdmin ea)
{
long start = System.currentTimeMillis();
postEvents(ea);
long time = System.currentTimeMillis() - start;
System.out.println("sending async events took " + time + "ms");
}
private void addHandler(BundleContext bc)
{
System.out.println("Adding event handler");
for (int i = 0; i < 100; ++i)
{
EventHandler h1 = new EventHandler() {
@Override
public void handleEvent(Event e) {
event1Handled++;
}
};
Dictionary props = new Hashtable();
props.put(EventConstants.EVENT_TOPIC, "org/mbi/1");
bc.registerService(EventHandler.class.getName(), h1, props);
EventHandler h2 = new EventHandler() {
@Override
public void handleEvent(Event e) {
event2Handled++;
}
};
props = new Hashtable();
props.put(EventConstants.EVENT_TOPIC, "org/mbi/*");
bc.registerService(EventHandler.class.getName(), h2, props);
EventHandler h3 = new EventHandler() {
@Override
public void handleEvent(Event e) {
event2Handled++;
}
};
props = new Hashtable<String,Object>();
props.put(EventConstants.EVENT_TOPIC, "org/mbi/*");
props.put(EventConstants.EVENT_FILTER, "(name=bla)");
bc.registerService(EventHandler.class.getName(), h3, props);
}
}
private void sendEvents(EventAdmin ea)
{
Dictionary props = null;
Event event1 = new Event("org/mbi/1", props);
for (int i = 0; i < 1000; ++i)
{
ea.sendEvent(event1);
}
for (int i = 0; i < 1000; ++i)
{
props = new Hashtable();
props.put("name", "bla");
props.put("level", i);
Event event2 = new Event("org/mbi/2", props);
ea.sendEvent(event2);
}
}
private void postEvents(EventAdmin ea)
{
Dictionary props = null;
Event event1 = new Event("org/mbi/1", props);
for (int i = 0; i < 1000; ++i)
{
ea.postEvent(event1);
}
for (int i = 0; i < 1000; ++i)
{
props = new Hashtable();
props.put("name", "bla");
props.put("level", i);
Event event2 = new Event("org/mbi/2", props);
ea.postEvent(event2);
}
}
}
