brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aledsage <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: Initial OSGI work
Date Mon, 30 Jun 2014 22:18:02 GMT
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/31#discussion_r14379176
  
    --- Diff: core/src/main/java/brooklyn/management/ha/OsgiManager.java ---
    @@ -0,0 +1,64 @@
    +package brooklyn.management.ha;
    +
    +import java.io.File;
    +
    +import org.osgi.framework.BundleException;
    +import org.osgi.framework.launch.Framework;
    +
    +import brooklyn.config.BrooklynServerConfig;
    +import brooklyn.config.ConfigKey;
    +import brooklyn.util.collections.MutableMap;
    +import brooklyn.util.exceptions.Exceptions;
    +import brooklyn.util.guava.Maybe;
    +import brooklyn.util.os.Os;
    +import brooklyn.util.osgi.Osgis;
    +
    +public class OsgiManager {
    +
    +    public static final ConfigKey<Boolean> USE_OSGI = BrooklynServerConfig.USE_OSGI;
    +    
    +    /* see Osgis for info on starting framework etc */
    +    
    +    protected Framework framework;
    +    protected File osgiTempDir;
    +    
    +    public void start() {
    +        try {
    +            // TODO any extra startup args?
    +            // TODO dir to come from brooklyn properties;
    +            // note dir must be different for each if starting multiple instances
    +            osgiTempDir = Os.newTempDir("brooklyn-osgi-cache");
    +            framework = Osgis.newFrameworkStarted(osgiTempDir.getAbsolutePath(), false,
MutableMap.of());
    +            
    +        } catch (Exception e) {
    +            throw Exceptions.propagate(e);
    +        }
    +    }
    +
    +    public void stop() {
    +        try {
    +            if (framework!=null)
    +                framework.stop();
    +        } catch (BundleException e) {
    +            throw Exceptions.propagate(e);
    +        }
    +        osgiTempDir = Os.deleteRecursively(osgiTempDir).asNullOrThrowing();
    +        framework = null;
    +    }
    +
    +    // TODO: throws BundleException appropriate?
    +    public void registerBundle(String bundleUrl) throws BundleException {
    +        Osgis.install(framework, bundleUrl);
    +    }
    +
    +    // TODO: Handle .get failing
    +    public <T> Maybe<Class<T>> tryResolveClass(String bundleUrl, String
type) {
    +        try {
    +            Class<T> clazz = (Class<T>) Osgis.getBundle(framework, bundleUrl).get().loadClass(type);
    --- End diff --
    
    `loadClass(type)` will throw `ClassNotFoundException` if not found.
    Better to just catch that rather than generic Exception?
    e.g. if bundle name was invalid then fine to throw exception rather than just returning
`Maybe.absent()`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message