Hi Hamlet, My responses inline below.
On Fri, Mar 4, 2011 at 6:50 AM, Hamlet DArcy <[email protected]> wrote: > Hi all, > > I am hoping for some architectural/design guidance. > > I have an existing application that loads & executes Groovy scripts from disk > in order to provide custom logic to different customers. For instance, > Customer X is mapped to a certain directory and the custom validation rules > sit in "validation.groovy" in that customer's directory. We have almost 5000 > scripts that get executed this way. I want to use OSGi to execute the scripts > because then each customer can specify which version of Groovy to use > (modularity) but the calls are still in process and fast. > > My idea is to define an OSGi service interface and have 3 implementations > (Groovy 1.6, Groovy 1.7, and Groovy 1.8). The script controller will know > what version to execute against and dispatch processing to the correct OSGi > bundle that has that version of Groovy as a private dependency. > > My questions: > 1) Do you see any obvious problems with this approach? I'm not sure if you will be able to do it using a service oriented approach. The reason is that I believe that your customer's Groovy scripts will have dependencies on the Groovy standard library. I don't know much about Groovy but I expect that it has some kind of standard library, equivalent to java.lang, java.util etc in the Java language... am I correct? If that's the case then each customer's bundle has a *static* dependency on a specific version of Groovy that is best expressed through Import-Package. For example: Import-Package: groovy.lang;version="[1.6,2.0)" This allows your customer's bundle to express that it depends on at least Groovy 1.6, but it will also run on 1.7, 1.8, 1.256 etc. > 2) How easy & performant is it to embed an OSGi container into my existing > application? Very easy if you use the OSGi R4.2 framework launching API. Just the following few lines of code will start an OSGi framework: FrameworkFactory factory = ServiceLoader.load(FrameworkFactory.class); Map<String,String> props = new HashMap<String,String>(); // set some properties Framework framework = factory.newFramework(props); framework.start(); Now install and start a bundle: Bundle b = framework.getBundleContext().installBundle("file:/path/to/my/bundle.jar"); b.start(); Finally wait for the OSGi framework to shutdown: framework.waitForStop(0); > 3) Do you have any recommendations on which container to use? Equinox, Felix and Knopflerfish are all fine containers and they all support the above API. If you stick to the standard API then you can remain independent of any specific container. I recommend you do this... then after building your application you can evaluate which container offers the best non-functional environment for your needs. > 4) Do you have an links or examples that are a good starting point on how to > do this? > > Thanks in advance, > > -- > Hamlet D'Arcy > [email protected] > > _______________________________________________ > OSGi Developer Mail List > [email protected] > https://mail.osgi.org/mailman/listinfo/osgi-dev > _______________________________________________ OSGi Developer Mail List [email protected] https://mail.osgi.org/mailman/listinfo/osgi-dev
