]> git.argeo.org Git - gpl/argeo-slc.git/commitdiff
Use SLC Detached (aka. SLC AutoUI) as a bundle.
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 28 Sep 2008 12:41:53 +0000 (12:41 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 28 Sep 2008 12:41:53 +0000 (12:41 +0000)
Move servers config to end bundle.

git-svn-id: https://svn.argeo.org/slc/trunk@1651 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

org.argeo.slc.autoui/src/main/java/org/argeo/slc/autoui/AbstractDetachedActivator.java
org.argeo.slc.autoui/src/main/java/org/argeo/slc/autoui/AutoUiActivator.java
org.argeo.slc.autoui/src/main/java/org/argeo/slc/autoui/DetachedExecutionServerImpl.java [new file with mode: 0644]
org.argeo.slc.autoui/src/main/java/org/argeo/slc/autoui/SimpleDetachedActivator.java [new file with mode: 0644]
org.argeo.slc.autoui/src/main/java/org/argeo/slc/autoui/internal/DetachedExecutionServerImpl.java [deleted file]
org.argeo.slc.autoui/src/main/java/org/argeo/slc/autoui/rmi/AutoUiServerImpl.java
org.argeo.slc.autoui/src/main/resources/META-INF/MANIFEST.MF
org.argeo.slc.autoui/src/main/resources/META-INF/slc/conf/applicationContext.xml [deleted file]
org.argeo.slc.autoui/src/test/java/org/argeo/slc/detached/DetachedTest.java

index b1fe56922695f39f6c55141a557cfa20b38fc665..877d8b6742483ae4649cb9c734980982c45e1d3a 100644 (file)
@@ -3,6 +3,8 @@ 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;
@@ -13,24 +15,24 @@ 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 {
-               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");
@@ -38,15 +40,17 @@ public class AbstractDetachedActivator implements BundleActivator {
                                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();
@@ -56,6 +60,9 @@ public class AbstractDetachedActivator implements BundleActivator {
                }
 
                startAutoBundle(context);
+
+               log.info("SLC Detached bundle " + bundle.getSymbolicName() + " ("
+                               + bundle.getBundleId() + ") started");
        }
 
        /** Does nothing by default. */
index 01b2492534451be9cb9891445ddde22d819716bf..21c7d49cd32eb40a752976f898f33a029d6723a5 100644 (file)
@@ -1,32 +1,5 @@
 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");
-       }
 }
diff --git a/org.argeo.slc.autoui/src/main/java/org/argeo/slc/autoui/DetachedExecutionServerImpl.java b/org.argeo.slc.autoui/src/main/java/org/argeo/slc/autoui/DetachedExecutionServerImpl.java
new file mode 100644 (file)
index 0000000..27fe50a
--- /dev/null
@@ -0,0 +1,77 @@
+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();
+       }
+
+}
diff --git a/org.argeo.slc.autoui/src/main/java/org/argeo/slc/autoui/SimpleDetachedActivator.java b/org.argeo.slc.autoui/src/main/java/org/argeo/slc/autoui/SimpleDetachedActivator.java
new file mode 100644 (file)
index 0000000..4a7f3e4
--- /dev/null
@@ -0,0 +1,28 @@
+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");
+       }
+
+}
diff --git a/org.argeo.slc.autoui/src/main/java/org/argeo/slc/autoui/internal/DetachedExecutionServerImpl.java b/org.argeo.slc.autoui/src/main/java/org/argeo/slc/autoui/internal/DetachedExecutionServerImpl.java
deleted file mode 100644 (file)
index cc6c97a..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-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();
-       }
-
-}
index ef078aea2f72c2713821b1fcefae17e62ebb155c..a3a7e7a263a1a36fa5d9b911d8088ed0cc792e41 100644 (file)
@@ -2,8 +2,6 @@ package org.argeo.slc.autoui.rmi;
 
 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;
index 112e547b179ec0fee1f2258e45a0319987c7c549..7657296870bda5ff8908871275d2e498a01ed735 100644 (file)
@@ -1,29 +1,27 @@
 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
diff --git a/org.argeo.slc.autoui/src/main/resources/META-INF/slc/conf/applicationContext.xml b/org.argeo.slc.autoui/src/main/resources/META-INF/slc/conf/applicationContext.xml
deleted file mode 100644 (file)
index 2deaa4d..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<?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
index 09d7bba9799ec57735f9553e32737c026d412cec..be8bc8c65a50dbe43d7b01d512adcc23f72daf80 100644 (file)
@@ -11,8 +11,10 @@ import org.argeo.slc.autoui.drivers.FileDriver;
 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());