Search in sources :

Example 6 with PackageClassLoader

use of com.bluenimble.platform.PackageClassLoader in project serverless by bluenimble.

the class BlueNimble method main.

public static void main(String[] args) throws Exception {
    String installHomePath = System.getProperty(InstallHome);
    if (Lang.isNullOrEmpty(installHomePath)) {
        installHomePath = System.getProperty("user.dir");
    }
    File installHome = new File(installHomePath);
    File runtimeHome = null;
    if (args != null && args.length > 0 && args[0] != null) {
        File customHome = new File(args[0]);
        if (!customHome.exists()) {
            System.out.println("BlueNimble Home " + customHome.getAbsolutePath() + " doesn't exist, It will be created ...");
            customHome.mkdirs();
        }
        runtimeHome = customHome;
    }
    if (runtimeHome == null) {
        runtimeHome = installHome;
    }
    File tenantHome = null;
    if (args != null && args.length > 1 && args[1] != null) {
        tenantHome = new File(args[1]);
        if (!tenantHome.isDirectory() || !tenantHome.exists()) {
            tenantHome = null;
        }
    }
    @SuppressWarnings("resource") PackageClassLoader scl = new PackageClassLoader("BlueNimblePlatform", BlueNimble.class.getClassLoader(), toUrls(new File(installHome, "lib")));
    System.setProperty(BlueNimbleHomeKey, installHome.getAbsolutePath());
    System.setProperty(BlueNimbleRuntimeKey, runtimeHome.getAbsolutePath());
    Class<?> serverClass = scl.loadClass("com.bluenimble.platform.server.impls.fs.FileSystemApiServer");
    Constructor<?> constructor = serverClass.getConstructor(File.class, File.class, File.class);
    Object server = constructor.newInstance(installHome, runtimeHome, tenantHome);
    serverClass.getMethod("start", new Class[] {}).invoke(server, new Object[] {});
}
Also used : File(java.io.File) PackageClassLoader(com.bluenimble.platform.PackageClassLoader)

Example 7 with PackageClassLoader

use of com.bluenimble.platform.PackageClassLoader in project serverless by bluenimble.

the class BeanUtils method create.

public static Object create(ClassLoader loader, JsonObject definition, ClassLoaderRegistry registry) throws Exception {
    if (definition == null) {
        return null;
    }
    if (loader == null) {
        loader = Thread.currentThread().getContextClassLoader();
    }
    boolean enabled = Json.getBoolean(definition, Enabled, true);
    if (!enabled) {
        return null;
    }
    String clazz = Json.getString(definition, Clazz);
    if (clazz == null) {
        throw new Exception("Property " + Clazz + " not found");
    }
    int indexOfColon = clazz.indexOf(Lang.COLON);
    if (indexOfColon > 0) {
        String loaderName = clazz.substring(0, indexOfColon);
        clazz = clazz.substring(indexOfColon + 1);
        boolean required = !loaderName.startsWith(Lang.XMARK);
        if (!required) {
            loaderName = loaderName.substring(1);
        }
        if (registry != null) {
            ClassLoader rLoader = registry.find(loaderName);
            if (rLoader != null) {
                loader = rLoader;
            } else if (!required) {
                return null;
            }
        }
    }
    Object bean = null;
    if (PackageClassLoader.class.isAssignableFrom(loader.getClass())) {
        PackageClassLoader pcl = (PackageClassLoader) loader;
        if (pcl.hasSynonym(clazz)) {
            clazz = pcl.synonym(clazz);
        }
        // check if there is a singleton object registered for this name
        bean = ((PackageClassLoader) loader).lookupObject(clazz);
    }
    if (bean == null) {
        bean = loader.loadClass(clazz).newInstance();
        apply(bean, definition, registry);
    }
    return bean;
}
Also used : PackageClassLoader(com.bluenimble.platform.PackageClassLoader) JsonObject(com.bluenimble.platform.json.JsonObject) PackageClassLoader(com.bluenimble.platform.PackageClassLoader)

Example 8 with PackageClassLoader

use of com.bluenimble.platform.PackageClassLoader in project serverless by bluenimble.

the class BnMgmICli method start.

private static void start() throws Exception {
    String homePath = System.getProperty(InstallHome);
    if (homePath == null || homePath.trim().equals("")) {
        homePath = System.getProperty("user.dir");
    }
    Home = new File(homePath);
    Software = Json.load(new File(Home, "update.json"));
    if (!Json.isNullOrEmpty(Software)) {
        upgrade();
    }
    Scl = new PackageClassLoader("BlueNimbleICli", toUrls(new File(Home, "lib")), (ClassLoader[]) null);
    Class<?> toolClass = Scl.loadClass("com.bluenimble.platform.icli.mgm.BlueNimble");
    Constructor<?> constructor = toolClass.getConstructor(File.class);
    tool = constructor.newInstance(Home);
    toolClass.getMethod("startup", new Class[] { String[].class }).invoke(tool, new Object[] { args });
}
Also used : File(java.io.File) PackageClassLoader(com.bluenimble.platform.PackageClassLoader)

Aggregations

PackageClassLoader (com.bluenimble.platform.PackageClassLoader)8 Feature (com.bluenimble.platform.Feature)3 ApiSpace (com.bluenimble.platform.api.ApiSpace)3 JsonObject (com.bluenimble.platform.json.JsonObject)3 Plugin (com.bluenimble.platform.plugins.Plugin)3 AbstractPlugin (com.bluenimble.platform.plugins.impls.AbstractPlugin)3 ServerFeature (com.bluenimble.platform.server.ServerFeature)3 File (java.io.File)3 ActivateServiceSpi (com.bluenimble.platform.api.impls.im.ActivateServiceSpi)1 ChangePasswordSpi (com.bluenimble.platform.api.impls.im.ChangePasswordSpi)1 LoginServiceSpi (com.bluenimble.platform.api.impls.im.LoginServiceSpi)1 OAuthServiceSpi (com.bluenimble.platform.api.impls.im.OAuthServiceSpi)1 ResendActivationRequestSpi (com.bluenimble.platform.api.impls.im.ResendActivationRequestSpi)1 SignupServiceSpi (com.bluenimble.platform.api.impls.im.SignupServiceSpi)1 ScriptableApiServiceSpi (com.bluenimble.platform.api.impls.scripting.ScriptableApiServiceSpi)1 ScriptableApiSpi (com.bluenimble.platform.api.impls.scripting.ScriptableApiSpi)1 DefaultScriptingEngine (com.bluenimble.platform.api.scripting.impls.DefaultScriptingEngine)1 ElasticSearchIndexer (com.bluenimble.platform.indexer.impls.ElasticSearchIndexer)1 Remote (com.bluenimble.platform.remote.Remote)1 HttpRemote (com.bluenimble.platform.remote.impls.http.HttpRemote)1