Created
February 1, 2009 02:29
-
-
Save talios/55763 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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