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[] {});
}
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;
}
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 });
}
Aggregations