${pom.artifactId}
</Bundle-SymbolicName>
<Bundle-Activator>
- org.argeo.slc.autoui.AutoUiActivator
+ org.argeo.slc.detached.AutoUiActivator
</Bundle-Activator>
<Export-Package>
- org.argeo.slc.autoui.*
+ org.argeo.slc.detached.*
</Export-Package>
</instructions>
</configuration>
+++ /dev/null
-package org.argeo.slc.autoui;
-
-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.beans.factory.support.BeanDefinitionRegistry;
-import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
-import org.springframework.context.support.AbstractApplicationContext;
-import org.springframework.context.support.GenericApplicationContext;
-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 {
-
- 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 {
- AbstractApplicationContext applicationContext = new GenericApplicationContext();
- XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(
- (BeanDefinitionRegistry) applicationContext);
-
- URL url = bundle
- .getResource("META-INF/slc/conf/applicationContext.xml");
- if (url != null) {
- 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);
-
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- throw new Exception("Could not initialize application context");
- } finally {
- cur.setContextClassLoader(save);
- }
-
- startAutoBundle(context);
-
- log.info("SLC Detached bundle " + bundle.getSymbolicName() + " ("
- + bundle.getBundleId() + ") started");
- }
-
- /** Does nothing by default. */
- protected void startAutoBundle(BundleContext context) throws Exception {
-
- }
-
- public final void stop(BundleContext context) throws Exception {
- stopAutoBundle(context);
-
- if (staticRefProvider != null) {
- staticRefProvider.close();
- }
-
- }
-
- /** Does nothing by default. */
- protected void stopAutoBundle(BundleContext context) throws Exception {
-
- }
-
- protected StaticRefProvider getStaticRefProvider() {
- return staticRefProvider;
- }
-}
+++ /dev/null
-package org.argeo.slc.autoui;
-
-
-public class AutoUiActivator extends AbstractDetachedActivator {
-}
+++ /dev/null
-package org.argeo.slc.autoui;
-
-public interface DetachedClient {
- public void sendRequest(DetachedStepRequest request) throws Exception;
-
- /** Blocks until next answer. */
- public DetachedStepAnswer receiveAnswer() throws Exception;
-}
+++ /dev/null
-package org.argeo.slc.autoui;
-
-import java.util.List;
-
-public interface DetachedContext {
- public Object getDynamicRef(String ref);
-
- public void setDynamicRef(String ref, Object obj);
-
- public String getCurrentPath();
-
- public List getExecutedPaths();
-}
+++ /dev/null
-package org.argeo.slc.autoui;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-import java.util.Vector;
-
-public class DetachedContextImpl implements DetachedContext {
- private List executedPaths = new Vector();
- private String currentPath;
- private Map dynamicRefs = new TreeMap();
-
- public String getCurrentPath() {
- return currentPath;
- }
-
- public void setDynamicRef(String ref, Object obj) {
- dynamicRefs.put(ref, obj);
- }
-
- public Object getDynamicRef(String ref) {
- if (dynamicRefs.containsKey(ref))
- return dynamicRefs.get(ref);
- else
- return null;
- }
-
- public List getExecutedPaths() {
- return new ArrayList(executedPaths);
- }
-
-}
+++ /dev/null
-package org.argeo.slc.autoui;
-
-public interface DetachedDriver {
- /** Blocks until it receives a request. */
- public DetachedStepRequest receiveRequest() throws Exception;
- public void sendAnswer(DetachedStepAnswer answer) throws Exception;
-}
+++ /dev/null
-package org.argeo.slc.autoui;
-
-public class DetachedException extends RuntimeException {
- private Exception cause;
-
- public DetachedException(String message) {
- super(message);
- }
-
- public DetachedException(String message, Exception cause) {
- super(message);
- this.cause = cause;
- }
-}
+++ /dev/null
-package org.argeo.slc.autoui;
-
-public interface DetachedExecutionServer {
- public DetachedStepAnswer executeStep(DetachedStepRequest request);
-}
+++ /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) {
- if (e instanceof RuntimeException)
- throw (RuntimeException) e;
- else
- e.printStackTrace();
- }
- }
-
- }
- }, "driverThread");
-
- active = true;
-
- driverThread.start();
- }
-
-}
+++ /dev/null
-package org.argeo.slc.autoui;
-
-
-public interface DetachedStep {
- public DetachedStepAnswer execute(DetachedContext detachedContext,
- DetachedStepRequest detachedStepRequest);
-}
+++ /dev/null
-package org.argeo.slc.autoui;
-
-import java.util.Properties;
-
-public class DetachedStepAnswer {
- public static int PROCESSED = 0;
- public static int ERROR = 1;
- public static int SKIPPED = 2;
-
- private Properties outputParameters;
- private int outputStatus;
- private String log;
-
- public Properties getOutputParameters() {
- return outputParameters;
- }
-
- public void setOutputParameters(Properties outputParameters) {
- this.outputParameters = outputParameters;
- }
-
- public int getOutputStatus() {
- return outputStatus;
- }
-
- public void setOutputStatus(int outputStatus) {
- this.outputStatus = outputStatus;
- }
-
- public String getLog() {
- return log;
- }
-
- public void setLog(String log) {
- this.log = log;
- }
-
-}
+++ /dev/null
-package org.argeo.slc.autoui;
-
-import java.io.Serializable;
-import java.util.Properties;
-
-public class DetachedStepRequest implements Serializable {
- private String uuid;
- private Properties inputParameters;
- private String stepRef;
- private String path;
-
- public Properties getInputParameters() {
- return inputParameters;
- }
-
- public void setInputParameters(Properties inputParameters) {
- this.inputParameters = inputParameters;
- }
-
- public String getStepRef() {
- return stepRef;
- }
-
- public void setStepRef(String stepRef) {
- this.stepRef = stepRef;
- }
-
- public String getPath() {
- return path;
- }
-
- public void setPath(String path) {
- this.path = path;
- }
-
- public String getUuid() {
- return uuid;
- }
-
- public void setUuid(String uuid) {
- this.uuid = uuid;
- }
-}
+++ /dev/null
-package org.argeo.slc.autoui;
-
-import java.util.Properties;
-
-import org.osgi.framework.BundleContext;
-
-public class SimpleDetachedActivator extends AbstractDetachedActivator {
- 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());
- }
-
-}
+++ /dev/null
-package org.argeo.slc.autoui;
-
-import org.springframework.beans.factory.NoSuchBeanDefinitionException;
-import org.springframework.context.ConfigurableApplicationContext;
-
-public class SpringStaticRefProvider implements StaticRefProvider {
- private final ConfigurableApplicationContext applicationContext;
-
- public SpringStaticRefProvider(
- ConfigurableApplicationContext applicationContext) {
- this.applicationContext = applicationContext;
- }
-
- public Object getStaticRef(String id) {
- try {
- return applicationContext.getBean(id);
- } catch (NoSuchBeanDefinitionException e) {
- // silent
- return null;
- }
- }
-
- public void close(){
- applicationContext.close();
- }
-}
+++ /dev/null
-package org.argeo.slc.autoui;
-
-public interface StaticRefProvider {
- /** Returns null if no such ref. */
- public Object getStaticRef(String id);
-}
+++ /dev/null
-package org.argeo.slc.autoui.drivers;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-
-import org.argeo.slc.autoui.DetachedClient;
-import org.argeo.slc.autoui.DetachedDriver;
-import org.argeo.slc.autoui.DetachedException;
-import org.argeo.slc.autoui.DetachedStepAnswer;
-import org.argeo.slc.autoui.DetachedStepRequest;
-
-public class FileDriver implements DetachedDriver, DetachedClient {
- private File requestDir;
- private File answerDir;
-
- public synchronized DetachedStepRequest receiveRequest() throws Exception {
- if (!requestDir.exists())
- throw new DetachedException("Request dir "
- + requestDir.getCanonicalPath() + " does not exist.");
-
- File file = null;
- while (file == null) {
- File[] files = requestDir.listFiles();
- if (files.length > 0)
- file = files[0];
- else
- Thread.sleep(1000);
- }
-
- ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
- DetachedStepRequest request = (DetachedStepRequest) in.readObject();
- in.close();
-
- file.delete();// move it to a processed dir instead?
- return request;
- }
-
- public void sendAnswer(DetachedStepAnswer answer) throws Exception {
- // TODO Auto-generated method stub
-
- }
-
- public DetachedStepAnswer receiveAnswer() throws Exception {
- // TODO Auto-generated method stub
- return null;
- }
-
- public void sendRequest(DetachedStepRequest request) throws Exception {
- File file = new File(requestDir.getPath() + File.separator
- + request.getUuid());
- ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(
- file));
- out.writeObject(request);
- out.close();
- }
-
- public void setRequestDir(File requestDir) {
- this.requestDir = requestDir;
- }
-
- public void setAnswerDir(File answerDir) {
- this.answerDir = answerDir;
- }
-
-}
+++ /dev/null
-package org.argeo.slc.autoui.rmi;
-
-public interface AutoUiContext {
- public Object getLocalRef(String key);
-
- public void setLocalRef(String key, Object ref);
-}
+++ /dev/null
-package org.argeo.slc.autoui.rmi;
-
-import java.rmi.Remote;
-import java.rmi.RemoteException;
-
-public interface AutoUiServer extends Remote {
- public Object executeTask(AutoUiTask task) throws RemoteException;
-}
+++ /dev/null
-package org.argeo.slc.autoui.rmi;
-
-import java.rmi.Naming;
-import java.rmi.RemoteException;
-import java.rmi.server.UnicastRemoteObject;
-import java.util.Map;
-import java.util.TreeMap;
-
-public class AutoUiServerImpl extends UnicastRemoteObject implements
- AutoUiServer, AutoUiContext {
- private Map map = new TreeMap();
-
- public AutoUiServerImpl() throws RemoteException {
- super();
- }
-
- public Object executeTask(AutoUiTask task) throws RemoteException {
- try {
- return task.execute(this);
- } catch (Exception e) {
- throw new RemoteException("Coul not execute task.", e);
- }
- }
-
- public Object getLocalRef(String key) {
- return map.get(key);
- }
-
- public void setLocalRef(String key, Object ref) {
- map.put(key, ref);
- }
-
- public static void main(String[] args) {
- if (System.getSecurityManager() == null) {
- System.setSecurityManager(new SecurityManager());
- }
- try {
- String name = "AutoUiServer";
- AutoUiServer engine = new AutoUiServerImpl();
- // AutoUiServer stub = (AutoUiServer) UnicastRemoteObject
- // .exportObject(engine, 0);
- // Registry registry = LocateRegistry.getRegistry();
- // registry.rebind(name, stub);
- Naming.rebind(name, engine);
- System.out.println("AutoUiServer bound");
-
- } catch (Exception e) {
- System.err.println("AutoUiServer exception:");
- e.printStackTrace();
- }
-
- }
-}
+++ /dev/null
-package org.argeo.slc.autoui.rmi;
-
-import java.io.Serializable;
-
-public interface AutoUiTask extends Serializable {
- public Object execute(AutoUiContext context) throws Exception;
-}
--- /dev/null
+package org.argeo.slc.detached;
+
+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.beans.factory.support.BeanDefinitionRegistry;
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.GenericApplicationContext;
+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 {
+
+ 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 {
+ AbstractApplicationContext applicationContext = new GenericApplicationContext();
+ XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(
+ (BeanDefinitionRegistry) applicationContext);
+
+ URL url = bundle
+ .getResource("META-INF/slc/conf/applicationContext.xml");
+ if (url != null) {
+ 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);
+
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new Exception("Could not initialize application context");
+ } finally {
+ cur.setContextClassLoader(save);
+ }
+
+ startAutoBundle(context);
+
+ log.info("SLC Detached bundle " + bundle.getSymbolicName() + " ("
+ + bundle.getBundleId() + ") started");
+ }
+
+ /** Does nothing by default. */
+ protected void startAutoBundle(BundleContext context) throws Exception {
+
+ }
+
+ public final void stop(BundleContext context) throws Exception {
+ stopAutoBundle(context);
+
+ if (staticRefProvider != null) {
+ staticRefProvider.close();
+ }
+
+ }
+
+ /** Does nothing by default. */
+ protected void stopAutoBundle(BundleContext context) throws Exception {
+
+ }
+
+ protected StaticRefProvider getStaticRefProvider() {
+ return staticRefProvider;
+ }
+}
--- /dev/null
+package org.argeo.slc.detached;
+
+
+public class AutoUiActivator extends AbstractDetachedActivator {
+}
--- /dev/null
+package org.argeo.slc.detached;
+
+public interface DetachedClient {
+ public void sendRequest(DetachedStepRequest request) throws Exception;
+
+ /** Blocks until next answer. */
+ public DetachedStepAnswer receiveAnswer() throws Exception;
+}
--- /dev/null
+package org.argeo.slc.detached;
+
+import java.util.List;
+
+public interface DetachedContext {
+ public Object getDynamicRef(String ref);
+
+ public void setDynamicRef(String ref, Object obj);
+
+ public String getCurrentPath();
+
+ public List getExecutedPaths();
+}
--- /dev/null
+package org.argeo.slc.detached;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.Vector;
+
+public class DetachedContextImpl implements DetachedContext {
+ private List executedPaths = new Vector();
+ private String currentPath;
+ private Map dynamicRefs = new TreeMap();
+
+ public String getCurrentPath() {
+ return currentPath;
+ }
+
+ public void setDynamicRef(String ref, Object obj) {
+ dynamicRefs.put(ref, obj);
+ }
+
+ public Object getDynamicRef(String ref) {
+ if (dynamicRefs.containsKey(ref))
+ return dynamicRefs.get(ref);
+ else
+ return null;
+ }
+
+ public List getExecutedPaths() {
+ return new ArrayList(executedPaths);
+ }
+
+}
--- /dev/null
+package org.argeo.slc.detached;
+
+public interface DetachedDriver {
+ /** Blocks until it receives a request. */
+ public DetachedStepRequest receiveRequest() throws Exception;
+ public void sendAnswer(DetachedStepAnswer answer) throws Exception;
+}
--- /dev/null
+package org.argeo.slc.detached;
+
+public class DetachedException extends RuntimeException {
+ private Exception cause;
+
+ public DetachedException(String message) {
+ super(message);
+ }
+
+ public DetachedException(String message, Exception cause) {
+ super(message);
+ this.cause = cause;
+ }
+}
--- /dev/null
+package org.argeo.slc.detached;
+
+public interface DetachedExecutionServer {
+ public DetachedStepAnswer executeStep(DetachedStepRequest request);
+}
--- /dev/null
+package org.argeo.slc.detached;
+
+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) {
+ if (e instanceof RuntimeException)
+ throw (RuntimeException) e;
+ else
+ e.printStackTrace();
+ }
+ }
+
+ }
+ }, "driverThread");
+
+ active = true;
+
+ driverThread.start();
+ }
+
+}
--- /dev/null
+package org.argeo.slc.detached;
+
+
+public interface DetachedStep {
+ public DetachedStepAnswer execute(DetachedContext detachedContext,
+ DetachedStepRequest detachedStepRequest);
+}
--- /dev/null
+package org.argeo.slc.detached;
+
+import java.util.Properties;
+
+public class DetachedStepAnswer {
+ public static int PROCESSED = 0;
+ public static int ERROR = 1;
+ public static int SKIPPED = 2;
+
+ private Properties outputParameters;
+ private int outputStatus;
+ private String log;
+
+ public Properties getOutputParameters() {
+ return outputParameters;
+ }
+
+ public void setOutputParameters(Properties outputParameters) {
+ this.outputParameters = outputParameters;
+ }
+
+ public int getOutputStatus() {
+ return outputStatus;
+ }
+
+ public void setOutputStatus(int outputStatus) {
+ this.outputStatus = outputStatus;
+ }
+
+ public String getLog() {
+ return log;
+ }
+
+ public void setLog(String log) {
+ this.log = log;
+ }
+
+}
--- /dev/null
+package org.argeo.slc.detached;
+
+import java.io.Serializable;
+import java.util.Properties;
+
+public class DetachedStepRequest implements Serializable {
+ private String uuid;
+ private Properties inputParameters;
+ private String stepRef;
+ private String path;
+
+ public Properties getInputParameters() {
+ return inputParameters;
+ }
+
+ public void setInputParameters(Properties inputParameters) {
+ this.inputParameters = inputParameters;
+ }
+
+ public String getStepRef() {
+ return stepRef;
+ }
+
+ public void setStepRef(String stepRef) {
+ this.stepRef = stepRef;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public void setUuid(String uuid) {
+ this.uuid = uuid;
+ }
+}
--- /dev/null
+package org.argeo.slc.detached;
+
+import java.util.Properties;
+
+import org.osgi.framework.BundleContext;
+
+public class SimpleDetachedActivator extends AbstractDetachedActivator {
+ 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());
+ }
+
+}
--- /dev/null
+package org.argeo.slc.detached;
+
+import org.springframework.beans.factory.NoSuchBeanDefinitionException;
+import org.springframework.context.ConfigurableApplicationContext;
+
+public class SpringStaticRefProvider implements StaticRefProvider {
+ private final ConfigurableApplicationContext applicationContext;
+
+ public SpringStaticRefProvider(
+ ConfigurableApplicationContext applicationContext) {
+ this.applicationContext = applicationContext;
+ }
+
+ public Object getStaticRef(String id) {
+ try {
+ return applicationContext.getBean(id);
+ } catch (NoSuchBeanDefinitionException e) {
+ // silent
+ return null;
+ }
+ }
+
+ public void close(){
+ applicationContext.close();
+ }
+}
--- /dev/null
+package org.argeo.slc.detached;
+
+public interface StaticRefProvider {
+ /** Returns null if no such ref. */
+ public Object getStaticRef(String id);
+}
--- /dev/null
+package org.argeo.slc.detached.drivers;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.argeo.slc.detached.DetachedClient;
+import org.argeo.slc.detached.DetachedDriver;
+import org.argeo.slc.detached.DetachedException;
+import org.argeo.slc.detached.DetachedStepAnswer;
+import org.argeo.slc.detached.DetachedStepRequest;
+
+public class FileDriver implements DetachedDriver, DetachedClient {
+ private File requestDir;
+ private File answerDir;
+
+ public synchronized DetachedStepRequest receiveRequest() throws Exception {
+ if (!requestDir.exists())
+ throw new DetachedException("Request dir "
+ + requestDir.getCanonicalPath() + " does not exist.");
+
+ File file = null;
+ while (file == null) {
+ File[] files = requestDir.listFiles();
+ if (files.length > 0)
+ file = files[0];
+ else
+ Thread.sleep(1000);
+ }
+
+ ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
+ DetachedStepRequest request = (DetachedStepRequest) in.readObject();
+ in.close();
+
+ file.delete();// move it to a processed dir instead?
+ return request;
+ }
+
+ public void sendAnswer(DetachedStepAnswer answer) throws Exception {
+ // TODO Auto-generated method stub
+
+ }
+
+ public DetachedStepAnswer receiveAnswer() throws Exception {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void sendRequest(DetachedStepRequest request) throws Exception {
+ File file = new File(requestDir.getPath() + File.separator
+ + request.getUuid());
+ ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(
+ file));
+ out.writeObject(request);
+ out.close();
+ }
+
+ public void setRequestDir(File requestDir) {
+ this.requestDir = requestDir;
+ }
+
+ public void setAnswerDir(File answerDir) {
+ this.answerDir = answerDir;
+ }
+
+}
--- /dev/null
+package org.argeo.slc.detached.rmi;
+
+public interface AutoUiContext {
+ public Object getLocalRef(String key);
+
+ public void setLocalRef(String key, Object ref);
+}
--- /dev/null
+package org.argeo.slc.detached.rmi;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+public interface AutoUiServer extends Remote {
+ public Object executeTask(AutoUiTask task) throws RemoteException;
+}
--- /dev/null
+package org.argeo.slc.detached.rmi;
+
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
+import java.util.Map;
+import java.util.TreeMap;
+
+public class AutoUiServerImpl extends UnicastRemoteObject implements
+ AutoUiServer, AutoUiContext {
+ private Map map = new TreeMap();
+
+ public AutoUiServerImpl() throws RemoteException {
+ super();
+ }
+
+ public Object executeTask(AutoUiTask task) throws RemoteException {
+ try {
+ return task.execute(this);
+ } catch (Exception e) {
+ throw new RemoteException("Coul not execute task.", e);
+ }
+ }
+
+ public Object getLocalRef(String key) {
+ return map.get(key);
+ }
+
+ public void setLocalRef(String key, Object ref) {
+ map.put(key, ref);
+ }
+
+ public static void main(String[] args) {
+ if (System.getSecurityManager() == null) {
+ System.setSecurityManager(new SecurityManager());
+ }
+ try {
+ String name = "AutoUiServer";
+ AutoUiServer engine = new AutoUiServerImpl();
+ // AutoUiServer stub = (AutoUiServer) UnicastRemoteObject
+ // .exportObject(engine, 0);
+ // Registry registry = LocateRegistry.getRegistry();
+ // registry.rebind(name, stub);
+ Naming.rebind(name, engine);
+ System.out.println("AutoUiServer bound");
+
+ } catch (Exception e) {
+ System.err.println("AutoUiServer exception:");
+ e.printStackTrace();
+ }
+
+ }
+}
--- /dev/null
+package org.argeo.slc.detached.rmi;
+
+import java.io.Serializable;
+
+public interface AutoUiTask extends Serializable {
+ public Object execute(AutoUiContext context) throws Exception;
+}
Manifest-Version: 1.0\r
-Export-Package: org.argeo.slc.autoui.rmi,org.argeo.slc.autoui;uses:="o\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
+Export-Package: org.argeo.slc.detached.rmi,org.argeo.slc.detached;uses\r
+ :="org.springframework.beans.factory.support,org.apache.commons.loggi\r
+ ng,org.springframework.context.support,org.springframework.core.io,or\r
+ g.osgi.framework,org.springframework.beans.factory.xml,org.springfram\r
+ ework.context,org.springframework.beans.factory",org.argeo.slc.detach\r
+ ed.drivers;uses:="org.argeo.slc.detached"\r
Built-By: mbaudier\r
Tool: Bnd-0.0.255\r
Bundle-Name: Argeo SLC Detached\r
Bundle-Vendor: Argeo\r
Build-Jdk: 1.6.0\r
Bundle-Version: 0.11.1.SNAPSHOT\r
-Bnd-LastModified: 1222612958407\r
+Bnd-LastModified: 1222615485731\r
Bundle-ManifestVersion: 2\r
-Bundle-Activator: org.argeo.slc.autoui.AutoUiActivator\r
+Bundle-Activator: org.argeo.slc.detached.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.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
+Import-Package: org.apache.commons.logging,org.argeo.slc.detached,org.\r
+ argeo.slc.detached.drivers,org.argeo.slc.detached.rmi,org.osgi.framew\r
+ ork,org.springframework.beans.factory,org.springframework.beans.facto\r
+ ry.support,org.springframework.beans.factory.xml,org.springframework.\r
+ context,org.springframework.context.support,org.springframework.core.\r
+ io\r
Bundle-SymbolicName: org.argeo.slc.detached\r
Bundle-DocURL: http://www.argeo.org\r
Originally-Created-By: Apache Maven Bundle Plugin\r