Skip to content

Instantly share code, notes, and snippets.

@talios
Created February 1, 2009 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talios/55763 to your computer and use it in GitHub Desktop.
Save talios/55763 to your computer and use it in GitHub Desktop.
package com.theoryinpractise.clojure;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.ComponentContext;
import java.util.Properties;
/**
* @scr.component
*/
public class ClojureProvidingComponent {
protected void activate(ComponentContext context) {
System.out.println("Java OSGi activator!" );
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(
ClojureProvidingComponent.class.getClassLoader());
Runnable run = (Runnable) context.getBundleContext().getBundle().loadClass(
"com.theoryinpractise.clojure.runnable").newInstance();
context.getBundleContext().registerService(
Runnable.class.getName(), run, new Properties());
} catch(Exception e) {
e.printStackTrace();
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
// Now look up the service
ServiceReference runReference = context.getBundleContext()
.getServiceReference(Runnable.class.getName());
Runnable theRunnable = (Runnable) context.getBundleContext()
.getService(runReference);
theRunnable.run();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment