std::string CreateIgniteClasspath(const std::string* usrCp, const std::string* home) { bool forceTest = false; if (home) { bool envFound; std::string env = GetEnv(IGNITE_NATIVE_TEST_CLASSPATH, &envFound); forceTest = envFound && env.compare("true") == 0; } return CreateIgniteClasspath(usrCp, home, forceTest); }
Ignite Ignition::Start(const IgniteConfiguration& cfg, const char* name, IgniteError* err) { bool failed = false; SharedPointer<IgniteEnvironment> env; SharedPointer<IgniteEnvironment>* envTarget = NULL; jobject javaRef = NULL; factoryLock.Enter(); // 1. Load JVM library if needed. if (!JVM_LIB_LOADED) { bool jvmLibFound; std::string jvmLib; if (cfg.jvmLibPath) { std::string jvmLibPath = std::string(cfg.jvmLibPath); jvmLib = FindJvmLibrary(&jvmLibPath, &jvmLibFound); } else jvmLib = FindJvmLibrary(NULL, &jvmLibFound); if (!jvmLibFound) { *err = IgniteError(IgniteError::IGNITE_ERR_JVM_LIB_NOT_FOUND, "JVM library is not found (did you set JAVA_HOME environment variable?)"); failed = true; } if (!failed) { if (!LoadJvmLibrary(jvmLib)) { *err = IgniteError(IgniteError::IGNITE_ERR_JVM_LIB_LOAD_FAILED, "Failed to load JVM library."); failed = true; } } JVM_LIB_LOADED = true; } if (!failed) { // 2. Resolve IGNITE_HOME. bool homeFound; std::string home; if (cfg.igniteHome) { std::string homePath = std::string(cfg.igniteHome); home = ResolveIgniteHome(&homePath, &homeFound); } else home = ResolveIgniteHome(NULL, &homeFound); // 3. Create classpath. std::string cp; if (cfg.jvmClassPath) { std::string usrCp = cfg.jvmClassPath; cp = CreateIgniteClasspath(&usrCp, homeFound ? &home : NULL); } else cp = CreateIgniteClasspath(NULL, homeFound ? &home : NULL); if (!cp.empty()) { // 4. Start JVM if needed. JniErrorInfo jniErr; env = SharedPointer<IgniteEnvironment>(new IgniteEnvironment()); int optsLen; char** opts = CreateJvmOptions(cfg, homeFound ? &home : NULL, cp, &optsLen); envTarget = new SharedPointer<IgniteEnvironment>(env); SharedPointer<JniContext> ctx( JniContext::Create(opts, optsLen, env.Get()->GetJniHandlers(envTarget), &jniErr)); for (int i = 0; i < optsLen; i++) ReleaseChars(*(opts + i)); delete[] opts; if (!ctx.Get()) { IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err); failed = true; } // 5. Start Ignite. if (!failed) { char* springCfgPath0 = CopyChars(cfg.springCfgPath); if (!springCfgPath0) springCfgPath0 = CopyChars(DFLT_CFG); char* name0 = CopyChars(name); interop::InteropUnpooledMemory mem(16); interop::InteropOutputStream stream(&mem); stream.WriteBool(false); stream.Synchronize(); javaRef = ctx.Get()->IgnitionStart(springCfgPath0, name0, 2, mem.PointerLong(), &jniErr); ReleaseChars(springCfgPath0); ReleaseChars(name0); if (!javaRef) { IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err); failed = true; } else { // 6. Ignite is started at this point. env.Get()->Initialize(ctx); started = true; } } } else { *err = IgniteError(IgniteError::IGNITE_ERR_JVM_NO_CLASSPATH, "Java classpath is empty (did you set IGNITE_HOME environment variable?)"); failed = true; } } factoryLock.Leave(); if (failed) { if (envTarget) delete envTarget; return Ignite(); } else { IgniteImpl* impl = new IgniteImpl(env, javaRef); return Ignite(impl); } }