import java.net.URL;
import java.util.Properties;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.springframework.core.io.UrlResource;
public class AbstractDetachedActivator implements BundleActivator {
+ private final Log log = LogFactory.getLog(getClass());
+
private SpringStaticRefProvider staticRefProvider;
public final void start(BundleContext context) throws Exception {
- ClassLoader classLoader = getClass().getClassLoader();
- // Creates application context
+ Bundle bundle = context.getBundle();
+
+ // Creates application context with this class class loader
+ ClassLoader classLoader = getClass().getClassLoader();
Thread cur = Thread.currentThread();
ClassLoader save = cur.getContextClassLoader();
cur.setContextClassLoader(classLoader);
try {
- // applicationContext = new ClassPathXmlApplicationContext(
- // "/slc/conf/applicationContext.xml");
-
AbstractApplicationContext applicationContext = new GenericApplicationContext();
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(
(BeanDefinitionRegistry) applicationContext);
- Bundle bundle = context.getBundle();
URL url = bundle
.getResource("META-INF/slc/conf/applicationContext.xml");
System.out.println("Loads application context from bundle "
+ bundle.getSymbolicName() + " (url=" + url + ")");
xmlReader.loadBeanDefinitions(new UrlResource(url));
- }
- // Register static ref provider
- staticRefProvider = new SpringStaticRefProvider(applicationContext);
- Properties properties = new Properties();
- properties.setProperty("slc.detached.bundle", bundle
- .getSymbolicName());
- context.registerService(StaticRefProvider.class.getName(),
- staticRefProvider, properties);
+ // Register static ref provider
+ staticRefProvider = new SpringStaticRefProvider(
+ applicationContext);
+ Properties properties = new Properties();
+ properties.setProperty("slc.detached.bundle", bundle
+ .getSymbolicName());
+ context.registerService(StaticRefProvider.class.getName(),
+ staticRefProvider, properties);
+
+ }
} catch (Exception e) {
e.printStackTrace();
}
startAutoBundle(context);
+
+ log.info("SLC Detached bundle " + bundle.getSymbolicName() + " ("
+ + bundle.getBundleId() + ") started");
}
/** Does nothing by default. */
package org.argeo.slc.autoui;
-import java.util.Properties;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.slc.autoui.internal.DetachedExecutionServerImpl;
-import org.osgi.framework.BundleContext;
public class AutoUiActivator extends AbstractDetachedActivator {
- private final Log log = LogFactory.getLog(getClass());
-
- private DetachedExecutionServerImpl executionServer;
-
- public void startAutoBundle(BundleContext context) throws Exception {
- Object obj = getStaticRefProvider().getStaticRef("executionServer");
- if (obj != null)
- executionServer = (DetachedExecutionServerImpl) obj;
- else
- throw new DetachedException("Could not find execution server.");
-
- executionServer.init(context);
-
- context.registerService(DetachedExecutionServer.class.getName(),
- executionServer, new Properties());
- log.info("AutoUi started");
- }
-
- public void stopAutoBundle(BundleContext context) throws Exception {
- log.info("AutoUi stopped");
- }
}
--- /dev/null
+package org.argeo.slc.autoui;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+public class DetachedExecutionServerImpl implements DetachedExecutionServer {
+ private final DetachedContextImpl detachedContext;
+
+ private BundleContext bundleContext;
+ private DetachedDriver driver;
+
+ private boolean active = false;
+
+ public void setDriver(DetachedDriver driver) {
+ this.driver = driver;
+ }
+
+ public DetachedExecutionServerImpl() {
+ detachedContext = new DetachedContextImpl();
+ }
+
+ public DetachedStepAnswer executeStep(DetachedStepRequest request) {
+ try {
+ DetachedStep step = null;
+
+ // Find step
+ ServiceReference[] refs = bundleContext.getAllServiceReferences(
+ StaticRefProvider.class.getName(), null);
+ for (int i = 0; i < refs.length; i++) {
+ StaticRefProvider provider = (StaticRefProvider) bundleContext
+ .getService(refs[i]);
+ Object obj = provider.getStaticRef(request.getStepRef());
+ if (obj != null) {
+ step = (DetachedStep) obj;
+ break;
+ }
+ }
+
+ if (step == null)
+ throw new DetachedException("Could not find step with ref "
+ + request.getStepRef());
+
+ return step.execute(detachedContext, request);
+ } catch (DetachedException e) {
+ throw e;
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new DetachedException(
+ "Unexpected exception while executing request " + request,
+ e);
+ }
+ }
+
+ public void init(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ Thread driverThread = new Thread(new Runnable() {
+
+ public void run() {
+ while (active) {
+ try {
+ DetachedStepRequest request = driver.receiveRequest();
+ executeStep(request);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ }
+ },"driverThread");
+
+ active = true;
+
+ driverThread.start();
+ }
+
+}
--- /dev/null
+package org.argeo.slc.autoui;
+
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.osgi.framework.BundleContext;
+
+public class SimpleDetachedActivator extends AbstractDetachedActivator {
+ private final Log log = LogFactory.getLog(getClass());
+
+ private DetachedExecutionServerImpl executionServer;
+
+ protected void startAutoBundle(BundleContext context) throws Exception {
+ Object obj = getStaticRefProvider().getStaticRef("executionServer");
+ if (obj != null)
+ executionServer = (DetachedExecutionServerImpl) obj;
+ else
+ throw new DetachedException("Could not find execution server.");
+
+ executionServer.init(context);
+
+ context.registerService(DetachedExecutionServer.class.getName(),
+ executionServer, new Properties());
+ log.info("SimpleDetachedActivator started");
+ }
+
+}
+++ /dev/null
-package org.argeo.slc.autoui.internal;
-
-import org.argeo.slc.autoui.DetachedContextImpl;
-import org.argeo.slc.autoui.DetachedDriver;
-import org.argeo.slc.autoui.DetachedException;
-import org.argeo.slc.autoui.DetachedExecutionServer;
-import org.argeo.slc.autoui.DetachedStep;
-import org.argeo.slc.autoui.DetachedStepAnswer;
-import org.argeo.slc.autoui.DetachedStepRequest;
-import org.argeo.slc.autoui.StaticRefProvider;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-
-public class DetachedExecutionServerImpl implements DetachedExecutionServer {
- private final DetachedContextImpl detachedContext;
-
- private BundleContext bundleContext;
- private DetachedDriver driver;
-
- private boolean active = false;
-
- public void setDriver(DetachedDriver driver) {
- this.driver = driver;
- }
-
- public DetachedExecutionServerImpl() {
- detachedContext = new DetachedContextImpl();
- }
-
- public DetachedStepAnswer executeStep(DetachedStepRequest request) {
- try {
- DetachedStep step = null;
-
- // Find step
- ServiceReference[] refs = bundleContext.getAllServiceReferences(
- StaticRefProvider.class.getName(), null);
- for (int i = 0; i < refs.length; i++) {
- StaticRefProvider provider = (StaticRefProvider) bundleContext
- .getService(refs[i]);
- Object obj = provider.getStaticRef(request.getStepRef());
- if (obj != null) {
- step = (DetachedStep) obj;
- break;
- }
- }
-
- if (step == null)
- throw new DetachedException("Could not find step with ref "
- + request.getStepRef());
-
- return step.execute(detachedContext, request);
- } catch (DetachedException e) {
- throw e;
- } catch (Exception e) {
- e.printStackTrace();
- throw new DetachedException(
- "Unexpected exception while executing request " + request,
- e);
- }
- }
-
- public void init(BundleContext bundleContext) {
- this.bundleContext = bundleContext;
- Thread driverThread = new Thread(new Runnable() {
-
- public void run() {
- while (active) {
- try {
- DetachedStepRequest request = driver.receiveRequest();
- executeStep(request);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- }
- },"driverThread");
-
- active = true;
-
- driverThread.start();
- }
-
-}
import java.rmi.Naming;
import java.rmi.RemoteException;
-import java.rmi.registry.LocateRegistry;
-import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.Map;
import java.util.TreeMap;
Manifest-Version: 1.0\r
Export-Package: org.argeo.slc.autoui.rmi,org.argeo.slc.autoui;uses:="o\r
- rg.apache.commons.logging,org.springframework.context.support,org.spr\r
- ingframework.core.io,org.springframework.context,org.springframework.\r
- beans.factory.xml,org.argeo.slc.autoui.internal,org.springframework.b\r
- eans.factory.support,org.osgi.framework,org.springframework.beans.fac\r
- tory",org.argeo.slc.autoui.internal;uses:="org.argeo.slc.autoui,org.o\r
- sgi.framework",org.argeo.slc.autoui.drivers;uses:="org.argeo.slc.auto\r
- ui"\r
+ rg.springframework.beans.factory.support,org.apache.commons.logging,o\r
+ rg.springframework.context.support,org.springframework.core.io,org.os\r
+ gi.framework,org.springframework.beans.factory.xml,org.springframewor\r
+ k.context,org.springframework.beans.factory",org.argeo.slc.autoui.dri\r
+ vers;uses:="org.argeo.slc.autoui"\r
Built-By: mbaudier\r
Tool: Bnd-0.0.255\r
Bundle-Name: SLC Auto UI\r
Created-By: Apache Maven Bundle Plugin\r
Bundle-Vendor: Argeo\r
-Build-Jdk: 1.6.0_0\r
+Build-Jdk: 1.6.0\r
Bundle-Version: 0.11.1.SNAPSHOT\r
-Bnd-LastModified: 1222532180778\r
+Bnd-LastModified: 1222605231968\r
Bundle-ManifestVersion: 2\r
Bundle-Activator: org.argeo.slc.autoui.AutoUiActivator\r
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt\r
Import-Package: org.apache.commons.logging,org.argeo.slc.autoui,org.ar\r
- geo.slc.autoui.drivers,org.argeo.slc.autoui.internal,org.argeo.slc.au\r
- toui.rmi,org.osgi.framework;version="1.4",org.springframework.beans.f\r
- actory,org.springframework.beans.factory.support,org.springframework.\r
- beans.factory.xml,org.springframework.context,org.springframework.con\r
- text.support,org.springframework.core.io\r
+ geo.slc.autoui.drivers,org.argeo.slc.autoui.rmi,org.osgi.framework;ve\r
+ rsion="1.4",org.springframework.beans.factory,org.springframework.bea\r
+ ns.factory.support,org.springframework.beans.factory.xml,org.springfr\r
+ amework.context,org.springframework.context.support,org.springframewo\r
+ rk.core.io\r
Bundle-SymbolicName: org.argeo.slc.autoui\r
Bundle-DocURL: http://www.argeo.org\r
Originally-Created-By: Apache Maven Bundle Plugin\r
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
-
- <bean id="executionServer"
- class="org.argeo.slc.autoui.internal.DetachedExecutionServerImpl">
- <property name="driver" ref="driver"/>
- </bean>
- <bean id="driver"
- class="org.argeo.slc.autoui.drivers.FileDriver">
- <property name="requestDir" value="/home/mbaudier/dev/test/SLC/detachedRequests"/>
- </bean>
-
-</beans>
\ No newline at end of file
public class DetachedTest extends TestCase {
public void testSendRequest() throws Exception {
FileDriver client = new FileDriver();
- client.setRequestDir(new File(
- "/home/mbaudier/dev/test/SLC/detachedRequests"));
+ File requestDir = new File(
+ "/home/mbaudier/dev/test/SLC/detachedRequests");
+ requestDir.mkdirs();
+ client.setRequestDir(requestDir);
DetachedStepRequest request = new DetachedStepRequest();
request.setUuid(UUID.randomUUID().toString());