int invokeMethod(const cppintrospection::Value classInstance,
                 const cppintrospection::Type &classType,
                 const std::string& method,
                 cppintrospection::ValueList theArgs,
                 cppintrospection::Value &rval)
{

    // TODO: we should try to store this globally somewhere, so that we don't do
    // a lookup every time there is a message:
    /*
    //const cppintrospection::Type &ReferencedNodeType = cppintrospection::Reflection::getType("ReferencedNode");
    if ((classType==ReferencedNodeType) || (classType.isSubclassOf(ReferencedNodeType)))
    {
    */
        try {
            rval = classType.invokeMethod(method, classInstance, theArgs, true);
            // if we get this far, then the method invocation succeeded and
            // we can return:
            return 1;
        }
        catch (cppintrospection::Exception & ex)
        {
            //std::cerr << "catch exception: " << ex.what() << std::endl;
        }

        // If the method wasn't found in the classInstance, then we need to go
        // through all base classes to see if method is contained in a parent class:
        for (int i=0; i<classType.getNumBaseTypes(); i++)
        {
            if (invokeMethod(classInstance, classType.getBaseType(i), method, theArgs, rval)) return 1;
        }
   // }
    return 0;
}
示例#2
0
jsi::Value TurboCxxModule::get(jsi::Runtime& runtime, const jsi::PropNameID& propName) {
  std::string propNameUtf8 = propName.utf8(runtime);

  if (propNameUtf8 == "getConstants") {
    // This is special cased because `getConstants()` is already a part of CxxModule.
    return jsi::Function::createFromHostFunction(
        runtime,
        propName,
        0,
        [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) {
          jsi::Object result(rt);
          auto constants = cxxModule_->getConstants();
          for (auto &pair : constants) {
            result.setProperty(rt, pair.first.c_str(), jsi::valueFromDynamic(rt, pair.second));
          }
          return result;
        });
  }

  for (auto &method : cxxMethods_) {
    if (method.name == propNameUtf8) {
      return jsi::Function::createFromHostFunction(
          runtime,
          propName,
          0,
          [this, propNameUtf8](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) {
            return invokeMethod(rt, VoidKind, propNameUtf8, args, count);
          });
    }
  }

  throw std::runtime_error("Function '" + propNameUtf8 + "' cannot be found on cxxmodule: " + name_);
}
示例#3
0
void SmokeObject::maybeDestroy() {
  if (_allocated && !memoryIsOwned()) {
#ifdef MEM_DEBUG
    qDebug("%p: invoking destructor on %p", this, ptr());
#endif
    const char *cname = _klass->smokeBase()->name();
    const char *colon = strrchr(cname, ':');
    if (colon)
      cname = colon + 1;
    char *destructor = new char[strlen(cname) + 2];
    destructor[0] = '~';
    strcpy(destructor + 1, cname);
    invokeMethod(destructor); // might cause 'this' to be destructed
    delete[] destructor;
    if (instances.contains(_ptr)) // we are still around
      delete this;
  } else if (!_allocated) {
#ifdef MEM_DEBUG
    if (!_allocated)
      qDebug("%p: unallocated, deleting reference", this);
#endif
    /* If _allocated is FALSE, we do not have a Smoke binding, so we
       will not be alerted if the memory is deleted by Qt. Thus, we
       have to forfeit our reference; otherwise, the contents of the
       memory will be replaced without our knowledge. Note that the
       lack of a Smoke binding means that there is very little
       information associated with this reference, so there are
       probably few consequences to its deletion.  */
    delete this;
  }
}
示例#4
0
int printExceptionAndFreeV(JNIEnv *env, jthrowable exc, int noPrintFlags,
        const char *fmt, va_list ap)
{
    int i, noPrint, excErrno;
    char *className = NULL;
    jstring jStr = NULL;
    jvalue jVal;
    jthrowable jthr;
    const char *stackTrace;

    jthr = classNameOfObject(exc, env, &className);
    if (jthr) {
        fprintf(stderr, "PrintExceptionAndFree: error determining class name "
            "of exception.\n");
        className = strdup("(unknown)");
        destroyLocalReference(env, jthr);
    }
    for (i = 0; i < EXCEPTION_INFO_LEN; i++) {
        if (!strcmp(gExceptionInfo[i].name, className)) {
            break;
        }
    }
    if (i < EXCEPTION_INFO_LEN) {
        noPrint = (gExceptionInfo[i].noPrintFlag & noPrintFlags);
        excErrno = gExceptionInfo[i].excErrno;
    } else {
        noPrint = 0;
        excErrno = EINTERNAL;
    }
    if (!noPrint) {
        vfprintf(stderr, fmt, ap);
        fprintf(stderr, " error:\n");

        // We don't want to  use ExceptionDescribe here, because that requires a
        // pending exception.  Instead, use ExceptionUtils.
        jthr = invokeMethod(env, &jVal, STATIC, NULL, 
            "org/apache/commons/lang/exception/ExceptionUtils",
            "getStackTrace", "(Ljava/lang/Throwable;)Ljava/lang/String;", exc);
        if (jthr) {
            fprintf(stderr, "(unable to get stack trace for %s exception: "
                    "ExceptionUtils::getStackTrace error.)\n", className);
            destroyLocalReference(env, jthr);
        } else {
            jStr = jVal.l;
            stackTrace = (*env)->GetStringUTFChars(env, jStr, NULL);
            if (!stackTrace) {
                fprintf(stderr, "(unable to get stack trace for %s exception: "
                        "GetStringUTFChars error.)\n", className);
            } else {
                fprintf(stderr, "%s", stackTrace);
                (*env)->ReleaseStringUTFChars(env, jStr, stackTrace);
            }
        }
    }
    destroyLocalReference(env, jStr);
    destroyLocalReference(env, exc);
    free(className);
    return excErrno;
}
示例#5
0
    /*!
        \relates QxtMetaObject
        This overload always invokes the member using the connection type Qt::AutoConnection.

        \sa QMetaObject::invokeMethod()
     */
    bool invokeMethod(QObject* object, const char* member, const QVariant& arg0,
                      const QVariant& arg1, const QVariant& arg2, const QVariant& arg3,
                      const QVariant& arg4, const QVariant& arg5, const QVariant& arg6,
                      const QVariant& arg7, const QVariant& arg8, const QVariant& arg9)
    {
        return invokeMethod(object, member, Qt::AutoConnection,
                            arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
    }
void StopServiceInstruction::run()
{
    try {
        Pegasus::CIMValue ret = invokeMethod("StopService");

        if (!ret.equal(Pegasus::CIMValue(Pegasus::Uint32(0)))) {
            Logger::getInstance()->info("Unable to stop service.");
        }
    } catch (Pegasus::Exception &ex) {
        Logger::getInstance()->critical(CIMValue::to_string(ex.getMessage()));
    }
}
void ConnectionManager::Private::PendingNames::continueProcessing()
{
    if (!mMethodsQueue.isEmpty()) {
        QLatin1String method = mMethodsQueue.dequeue();
        invokeMethod(method);
    }
    else {
        debug() << "Success: list" << mResult;
        setResult(mResult.toList());
        setFinished();
    }
}
示例#8
0
/***************************************************************************
 * Convert var and store to type constraint var
 * Src is on the top of eval stack
 ***************************************************************************/
void CCilVm::storeAsRestrictedType( CVariable& varDest )
{
	assert( varDest.getFlag() & OPERAND_FLAG_STRICT );

	switch( varDest.iOperandType )
	{
	case OPERAND_UNDEFINED:
	case OPERAND_NULL:
	case OPERAND_NAN:
		//Throw TypeError
		ThrowExceptionFromVm( &wstring( ERRORSTRING_TYPEERROR_STORESTATICFIELD ),
			&wstring( NAME_BUILTIN_ERROR_OBJECT ),
			ERROR_TYPEERROR_STORESTATICFIELD );
		break;
	case OPERAND_INT:
		varDest.iValue = getEvalStackFirstEntry().toInt();
		break;
	case OPERAND_INT64:
		varDest.i64Value = getEvalStackFirstEntry().toInt64();
		break;
	case OPERAND_FLOAT:
		varDest.fValue = getEvalStackFirstEntry().toFloat();
		break;
	case OPERAND_DOUBLE:
		varDest.dValue = getEvalStackFirstEntry().toDouble();
		break;
	case OPERAND_BOOLEAN:
		varDest.bValue = getEvalStackFirstEntry().toBoolean();
		break;
	case OPERAND_STRING:
		varDest.pString = getEvalStackFirstEntry().toString( this );
		break;
	case OPERAND_OBJECTREF:
		{
			//Try object conversion
			CObjectTypeInfo& info = getMetaData().getObject( varDest.GetConstraintRid() );
			RID ridCtor = info.getConstructor();
			CVariable vars[ 2 ];
			vars[ 0 ] = varDest;
			vars[ 1 ] = getEvalStackFirstEntry();
			CVariable* pVar = invokeMethod( ridCtor, 2, vars );
			delete( pVar );
		}
		break;
	case OPERAND_UNSIGNEDINT:
	case OPERAND_UNSIGNEDINT64:
	case OPERAND_SYSTEM_DELETION:
	default:
		Debug_Fatal( "Unhandled type constraint");
		break;
	}
}
示例#9
0
void MethodCall::eval() {
  if (_mode == RToSmoke) 
    _stack = new Smoke::StackItem[length(_args) + 1];
  else if (_mode == SmokeToR)
    PROTECT(_args = allocVector(VECSXP, stackSize() - 1));
  if (_mode != Identity) {
    marshal();
    _called = false;
  } else invokeMethod();
  if (_mode == RToSmoke) {
    delete[] _stack;
    _stack = NULL;
  } else if (_mode == SmokeToR) {
    UNPROTECT(1);
    _args = NULL;
  }
}
示例#10
0
int nmdWaitClusterUp(struct NativeMiniDfsCluster *cl)
{
    jthrowable jthr;
    JNIEnv *env = getJNIEnv();
    if (!env) {
        fprintf(stderr, "nmdWaitClusterUp: getJNIEnv failed\n");
        return -EIO;
    }
    jthr = invokeMethod(env, NULL, INSTANCE, cl->obj,
            MINIDFS_CLUSTER, "waitClusterUp", "()V");
    if (jthr) {
        printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
            "nmdWaitClusterUp: MiniDFSCluster#waitClusterUp ");
        return -EIO;
    }
    return 0;
}
示例#11
0
int nmdGetNameNodePort(const struct NativeMiniDfsCluster *cl)
{
    JNIEnv *env = getJNIEnv();
    jvalue jVal;
    jthrowable jthr;

    if (!env) {
        fprintf(stderr, "nmdHdfsConnect: getJNIEnv failed\n");
        return -EIO;
    }
    // Note: this will have to be updated when HA nativeMiniDfs clusters are
    // supported
    jthr = invokeMethod(env, &jVal, INSTANCE, cl->obj,
            MINIDFS_CLUSTER, "getNameNodePort", "()I");
    if (jthr) {
        printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
            "nmdHdfsConnect: MiniDFSCluster#getNameNodePort");
        return -EIO;
    }
    return jVal.i;
}
示例#12
0
void MethodCall::marshal() {
  int oldcur = _cur;
  _cur++; // handle arguments

  while(!_called && _cur < stackSize()) {
    marshalItem();
    _cur++;
  }

  if (!_called) {
    _called = true;
    _cur = 0;
    invokeMethod();
    if (_method->lastError() == Method::NoError) {
      flip();
      marshalItem();
      flip();
    }
  }

  _cur = oldcur;
}
示例#13
0
struct NativeMiniDfsCluster* nmdCreate(struct NativeMiniDfsConf *conf)
{
    struct NativeMiniDfsCluster* cl = NULL;
    jobject bld = NULL, cobj = NULL, cluster = NULL;
    jvalue  val;
    JNIEnv *env = getJNIEnv();
    jthrowable jthr;
    jstring jconfStr = NULL;

    if (!env) {
        fprintf(stderr, "nmdCreate: unable to construct JNIEnv.\n");
        return NULL;
    }
    cl = calloc(1, sizeof(struct NativeMiniDfsCluster));
    if (!cl) {
        fprintf(stderr, "nmdCreate: OOM");
        goto error;
    }
    jthr = constructNewObjectOfClass(env, &cobj, HADOOP_CONF, "()V");
    if (jthr) {
        printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
            "nmdCreate: new Configuration");
        goto error;
    }
    if (conf->webhdfsEnabled) {
        jthr = newJavaStr(env, DFS_WEBHDFS_ENABLED_KEY, &jconfStr);
        if (jthr) {
            printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
                                  "nmdCreate: new String");
            goto error;
        }
        jthr = invokeMethod(env, NULL, INSTANCE, cobj, HADOOP_CONF,
                            "setBoolean", "(Ljava/lang/String;Z)V",
                            jconfStr, conf->webhdfsEnabled);
        if (jthr) {
            printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
                                  "nmdCreate: Configuration::setBoolean");
            goto error;
        }
    }
    jthr = constructNewObjectOfClass(env, &bld, MINIDFS_CLUSTER_BUILDER,
                    "(L"HADOOP_CONF";)V", cobj);
    if (jthr) {
        printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
            "nmdCreate: NativeMiniDfsCluster#Builder#Builder");
        goto error;
    }
    jthr = invokeMethod(env, &val, INSTANCE, bld, MINIDFS_CLUSTER_BUILDER,
            "format", "(Z)L" MINIDFS_CLUSTER_BUILDER ";", conf->doFormat);
    if (jthr) {
        printExceptionAndFree(env, jthr, PRINT_EXC_ALL, "nmdCreate: "
                              "Builder::format");
        goto error;
    }
    (*env)->DeleteLocalRef(env, val.l);
    if (conf->webhdfsEnabled) {
        jthr = invokeMethod(env, &val, INSTANCE, bld, MINIDFS_CLUSTER_BUILDER,
                        "nameNodeHttpPort", "(I)L" MINIDFS_CLUSTER_BUILDER ";",
                        conf->namenodeHttpPort);
        if (jthr) {
            printExceptionAndFree(env, jthr, PRINT_EXC_ALL, "nmdCreate: "
                                  "Builder::nameNodeHttpPort");
            goto error;
        }
        (*env)->DeleteLocalRef(env, val.l);
    }
    jthr = invokeMethod(env, &val, INSTANCE, bld, MINIDFS_CLUSTER_BUILDER,
            "build", "()L" MINIDFS_CLUSTER ";");
    if (jthr) {
        printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
                              "nmdCreate: Builder#build");
        goto error;
    }
    cluster = val.l;
	  cl->obj = (*env)->NewGlobalRef(env, val.l);
    if (!cl->obj) {
        printPendingExceptionAndFree(env, PRINT_EXC_ALL,
            "nmdCreate: NewGlobalRef");
        goto error;
    }
    (*env)->DeleteLocalRef(env, cluster);
    (*env)->DeleteLocalRef(env, bld);
    (*env)->DeleteLocalRef(env, cobj);
    (*env)->DeleteLocalRef(env, jconfStr);
    return cl;

error:
    (*env)->DeleteLocalRef(env, cluster);
    (*env)->DeleteLocalRef(env, bld);
    (*env)->DeleteLocalRef(env, cobj);
    (*env)->DeleteLocalRef(env, jconfStr);
    free(cl);
    return NULL;
}
示例#14
0
int nmdGetNameNodeHttpAddress(const struct NativeMiniDfsCluster *cl,
                               int *port, const char **hostName)
{
    JNIEnv *env = getJNIEnv();
    jvalue jVal;
    jobject jNameNode, jAddress;
    jthrowable jthr;
    int ret = 0;
    const char *host;
    
    if (!env) {
        fprintf(stderr, "nmdHdfsConnect: getJNIEnv failed\n");
        return -EIO;
    }
    // First get the (first) NameNode of the cluster
    jthr = invokeMethod(env, &jVal, INSTANCE, cl->obj, MINIDFS_CLUSTER,
                        "getNameNode", "()L" HADOOP_NAMENODE ";");
    if (jthr) {
        printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
                              "nmdGetNameNodeHttpAddress: "
                              "MiniDFSCluster#getNameNode");
        return -EIO;
    }
    jNameNode = jVal.l;
    
    // Then get the http address (InetSocketAddress) of the NameNode
    jthr = invokeMethod(env, &jVal, INSTANCE, jNameNode, HADOOP_NAMENODE,
                        "getHttpAddress", "()L" JAVA_INETSOCKETADDRESS ";");
    if (jthr) {
        ret = printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
                                    "nmdGetNameNodeHttpAddress: "
                                    "NameNode#getHttpAddress");
        goto error_dlr_nn;
    }
    jAddress = jVal.l;
    
    jthr = invokeMethod(env, &jVal, INSTANCE, jAddress,
                        JAVA_INETSOCKETADDRESS, "getPort", "()I");
    if (jthr) {
        ret = printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
                                    "nmdGetNameNodeHttpAddress: "
                                    "InetSocketAddress#getPort");
        goto error_dlr_addr;
    }
    *port = jVal.i;
    
    jthr = invokeMethod(env, &jVal, INSTANCE, jAddress, JAVA_INETSOCKETADDRESS,
                        "getHostName", "()Ljava/lang/String;");
    if (jthr) {
        ret = printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
                                    "nmdGetNameNodeHttpAddress: "
                                    "InetSocketAddress#getHostName");
        goto error_dlr_addr;
    }
    host = (*env)->GetStringUTFChars(env, jVal.l, NULL);
    *hostName = strdup(host);
    (*env)->ReleaseStringUTFChars(env, jVal.l, host);
    
error_dlr_addr:
    (*env)->DeleteLocalRef(env, jAddress);
error_dlr_nn:
    (*env)->DeleteLocalRef(env, jNameNode);
    
    return ret;
}
int main(int argc, char** argv)
{
    const char* arg0 = System::findBaseName(argv[0]);

#ifdef PEGASUS_OS_ZOS
    // for z/OS set stdout and stderr to EBCDIC
    setEBCDICEncoding(STDOUT_FILENO);
    setEBCDICEncoding(STDERR_FILENO);
#endif
 
#ifdef PEGASUS_OS_PASE
    // Allow user group name larger than 8 chars in PASE environemnt
    setenv("PASE_USRGRP_LIMITED","N",1);
#endif
    // If no arguments, simply print usage message and terminate.
    MessageLoader::_useProcessLocale = true;

    if (argc == 1)
    {
        showUsage();
        exit(0);
    }

    //****** Show the args diagnostic display
    if (strcmp(argv[1],"displayargs") == 0)
    {
        cout << "argc = " << argc << endl;
        for (int i = 0; i < argc; i++)
            cout << "argv[" << i << "] = " << argv[i] << endl;
    }

    // Get options (from command line and from configuration file); this
    // removes corresponding options and their arguments from the command
    // line.
    OptionManager om;
    Options opts;
    try
    {
        // assume that the config file is local to directory where called.
        String testHome = ".";
        om.setMessagePath("pegasus/pegasusCLI");
        GetOptions(om, argc, argv, testHome);

        // Initialize all of the function input parameters.
        opts.location =  String::EMPTY;
#ifdef PEGASUS_HAS_SSL
        opts.ssl = false;
        opts.clientCert = String::EMPTY;
        opts.clientKey = String::EMPTY;
#endif
        opts.nameSpace = "root/cimv2";
        opts.cimCmd = "unknown";
        opts.className = CIMName();
        opts.objectName = "unknown";

        opts.isXmlOutput = false;
        opts.outputFormatType = OUTPUT_MOF;
        opts.user = String::EMPTY;
        opts.password = String::EMPTY;
        opts.verboseTest = false;

        opts.localOnly = true;
        opts.deepInheritance = false;
        opts.includeQualifiers = true;
        opts.includeClassOrigin = false;
        opts.assocClassName = String::EMPTY;
        opts.assocClass = CIMName();
        opts.resultClassName = String::EMPTY;
        opts.resultClass = CIMName();
        opts.role = String::EMPTY;
        opts.resultRole = String::EMPTY;
        opts.propertyListText = String::EMPTY;
        opts.propertyList.clear();
        opts.propertyName = String::EMPTY;
        opts.methodName = CIMName("unknown");
        opts.delay = 0;
        opts.trace = 0;
        opts.count= 97832;
        opts.repeat = 0;
        opts.time = false;
        opts.termCondition = 0;
        opts.debug = false;
        opts.queryLanguage = "WQL";

        // move any other input parameters left to the extraParams List
        CheckCommonOptionValues(om, argv, opts);

        /* note that this is in error since it assumes a fixed
           number of parameters will be used for all of the commands
           It needs to be expanded to allow for a variable minimum
           number of commands before it picks up any extras
        */
        if (argc > 2)
        {
            for (int i = 2 ; i < argc ; i++ )
                opts.extraParams.append(argv[i]);
        }
    }

    catch(CIMException& e)
    {
        cerr << argv[0] << " Caught CIMException during init: "
             << "\n" << e.getMessage()
             << endl;
        exit(1);
    }

    catch (Exception& e)
    {
        cerr << argv[0] << ": " << e.getMessage() << endl;
        exit(1);
    }
    catch(...)
    {
        cerr << argv[0] << " Caught General Exception During Init:" << endl;
        exit(1);
    }

    // if there is still an arg1, assume it is the command name.
    if (argc > 1)
    {
        opts.cimCmd = argv[1];
    }
    else
    {
        cout << " Command name must be first parameter or --c parameter."
            << " \n  ex. " << argv[0] <<  " enumerateclasses\n"
            << "Enter " << argv[0] << " -h for help."
            << endl;
        exit(1);
    }

    // if the trace option was set initialize the trace function.
    if (opts.trace != 0)
    {
        const char* tmpDir = getenv ("PEGASUS_TMP");
            if (tmpDir == NULL)
            {
                tmpDir = ".";
            }
            String traceFile (tmpDir);
            traceFile.append("/cliTrace.trc");
            Tracer::setTraceFile (traceFile.getCString());
            Tracer::setTraceComponents("ALL");
            Tracer::setTraceLevel(opts.trace);
    }

    // Find the command and save index in cmdIndex
    Uint32 cmdIndex = 0;
    
    if (opts.verboseTest && opts.debug)
        cout << "TEST Command = " << opts.cimCmd << endl;

    // Find the command or the short cut name
    for( ; cmdIndex < NUM_COMMANDS; cmdIndex++ )
    {
        if ((String::equalNoCase(opts.cimCmd, 
                CommandTable[cmdIndex].CommandName)) 
                ||
                (opts.cimCmd == CommandTable[cmdIndex].ShortCut))
            // Break if found
                    break;
    }

    Stopwatch totalElapsedExecutionTime;

    totalElapsedExecutionTime.start();

    // Now try to open the connection to the cim server
    CIMClient client;
    try
    {
        if (CommandTable[cmdIndex].ID_Command != ID_ShowOptions)
        {
            String host;
            HostLocator addr;
            if (opts.location != String::EMPTY)
            { 
                addr.setHostLocator(opts.location);
                if (!addr.isValid())
                {
                    throw InvalidLocatorException(opts.location);
                }
                host = addr.getHost();
            } 

            Uint32 portNumber = System::lookupPort( WBEM_HTTP_SERVICE_NAME,
                              WBEM_DEFAULT_HTTP_PORT );

            // Set up SSL port and flag for verbose display
            // if SSL included in build
            String useSSL;
#ifdef PEGASUS_HAS_SSL
            if (opts.ssl)
            {
                portNumber = System::lookupPort( WBEM_HTTPS_SERVICE_NAME,
                              WBEM_DEFAULT_HTTPS_PORT );
            }
            useSSL = " ssl=";
            useSSL.append((opts.ssl)? "true" : "false");
#endif

            if (host != String::EMPTY && addr.isPortSpecified())
            {
                portNumber = addr.getPort();
            }

            //check whether we should use connect() or connectLocal()
            //an empty location option indicates to use connectLocal()
            if (String::equal(host, String::EMPTY))
            {
                if (opts.verboseTest)
                {
                    cout << "Connect with connectLocal" << endl;
                }
                client.connectLocal();

            }
            else
            {
                if (opts.verboseTest)
                {
                    cout << "Connect to " << host
                        << " port=" << portNumber
                        << useSSL
                         << " for User="******"SSL options " 
                                << "Cert = " << opts.clientCert
                                << "clientKey = "  << opts.clientKey << endl;
                        }
                        client.connect(host,
                                       portNumber,
                                       SSLContext("", 
                                           opts.clientCert, 
                                           opts.clientKey,
                                           NULL, "ssl.rnd"),
                                       opts.user,
                                       opts.password);
                    } else
                    {
                        client.connect(host,
                                       portNumber,
                                       SSLContext("", NULL, "ssl.rnd"),
                                       opts.user,
                                       opts.password);
                    }
                } else //connect over HTTP
                {
                    client.connect(host, portNumber, opts.user, opts.password);
                }
#else
                client.connect(host, portNumber, opts.user, opts.password);
#endif
            }
        }
    }    
    catch(Exception &e)
    {
        cerr << "Pegasus Exception: " << e.getMessage() <<
              " Trying to connect to " << opts.location << endl;
        exit(1);
    }

    // Register for Client statistics.
    ClientStatistics statistics = ClientStatistics();
    client.registerClientOpPerformanceDataHandler(statistics);

    if (opts.delay != 0)
    {
        // This was a test because of some delay caused problems.
        Threads::sleep(opts.delay * 1000);
    }

    // If the timeout is not zero, set the timeout for this connection.
    if (opts.connectionTimeout != 0)
    {
        client.setTimeout(opts.connectionTimeout * 1000);
    }

    // Save the total connect time.
    double totalConnectTime = opts.elapsedTime.getElapsed();

    double totalTime = 0;
    Uint32 repeatCount = opts.repeat;
    double maxTime = 0;
    double minTime = 10000000;

    Uint64 serverTotalTime = 0;
    Uint64 maxServerTime = 0;
    Uint64 minServerTime = 10000000;

    Uint64 rtTotalTime = 0;
    Uint64 maxRtTime = 0;
    Uint64 minRtTime = 10000000;

    // Process the input command within a try block.
    try
    {
        // Loop to repeat the command a number of times.
        do
        {
            // or exit with error through default of case logic
            switch(CommandTable[cmdIndex].ID_Command)
                {
                case ID_EnumerateInstanceNames :
                    if (!_getClassNameInput(argc, argv, opts, true))
                        exit(1);
                    enumerateInstanceNames(client, opts);
                    break;

                case ID_EnumerateAllInstanceNames :
                    if (!_getClassNameInput(argc, argv, opts, false))
                        exit(1);
                    enumerateAllInstanceNames(client, opts);
                    break;

                case ID_EnumerateInstances :
                    if (!_getClassNameInput(argc, argv, opts, true))
                        exit(1);
                    enumerateInstances(client, opts);
                    break;
                case ID_GetInstance :
                    if (!_getObjectNameInput(argc, argv, opts, true))
                        exit(1);
                    getInstance(client, opts);
                    break;

                case ID_EnumerateClassNames :
                    if (!_getClassNameInput(argc, argv, opts, false))
                        exit(1);
                    enumerateClassNames(client, opts);
                    break;

                case ID_EnumerateClasses :
                    if (!_getClassNameInput(argc, argv, opts, false))
                        exit(1);
                    enumerateClasses(client, opts);
                    break;

                case ID_GetClass :
                    if (!_getClassNameInput(argc, argv, opts, true))
                        exit(1);
                    getClass(client, opts);
                    break;

                case ID_CreateInstance :
                    if (!_getClassNameInput(argc, argv, opts, true))
                        exit(1);
                    createInstance(client, opts);
                    break;

                case ID_DeleteInstance :
                    if (!_getObjectNameInput(argc, argv, opts, true))
                        exit(1);
                    deleteInstance(client, opts);
                    break;

                case ID_CreateClass :
                    cerr << "CreateClass not implemented" << endl;
                    break;

                case ID_DeleteClass :
                    if (!_getClassNameInput(argc, argv, opts, true))
                        exit(1);
                    deleteClass(client, opts);
                    break;

                case ID_GetProperty :
                    if (argc != 4)
                    {
                        cout << "Usage: " << arg0 <<
                            " getproperty <instancename> <propertyname>" << 
                            endl;
                        exit(1);
                    }

                    opts.instanceName = argv[2];
                    opts.inputObjectName = argv[2];
                    opts.propertyName = argv[3];

                    getProperty(client, opts);
                    break;

                case ID_SetProperty :
                    if (argc != 5)
                        cout <<"Usage: " << arg0 << 
                          " setproperty instancename propertyname value "
                           << endl;
                    setProperty(client, opts);
                    break;

                case ID_EnumerateQualifiers :
                    enumerateQualifiers(client, opts);
                    break;

                case ID_SetQualifier :
                    cerr << "SetQualifer not implemented" << endl;
                        exit(1);
                    break;

                case ID_GetQualifier :
                    if (!_getQualifierNameInput(argc, argv, opts))
                        exit(1);
                    getQualifier(client, opts);
                    break;

                case ID_DeleteQualifier :
                    if (!_getQualifierNameInput(argc, argv, opts))
                        exit(1);
                    deleteQualifier(client, opts);
                    break;

                /* Reference params are
                    [IN] <objectName> ObjectName,
                    [IN,OPTIONAL,NULL] <className> ResultClass = NULL,
                    [IN,OPTIONAL,NULL] string Role = NULL,
                    [IN,OPTIONAL] boolean IncludeQualifiers = false,
                    [IN,OPTIONAL] boolean IncludeClassOrigin = false,
                    [IN,OPTIONAL,NULL] string PropertyList [] = NULL
                */
                case ID_References  :
                    if (!_getObjectNameInput(argc, argv, opts, true))
                        exit(1);
                    references(client, opts);
                    break;

                case ID_ReferenceNames :
                    if (!_getObjectNameInput(argc, argv, opts, true))
                        exit(1);
                    referenceNames(client, opts);
                    break;

                case ID_Associators :
                    if (!_getObjectNameInput(argc, argv, opts, true))
                        exit(1);
                    associators(client, opts);
                    break;

                case ID_AssociatorNames :
                    if (!_getObjectNameInput(argc, argv, opts, true))
                        exit(1);
                    associatorNames(client,opts);
                    break;

                case ID_EnumerateNamespaces :
                    // Note that the following constants are fixed here.  We
                    // should be getting them from the environment to assure
                    // that others know that we are using them.
                    opts.className = CIMName("CIM_Namespace");
                    if (argc > 2)
                    {
                        opts.nameSpace = argv[2];
                        opts.inputObjectName = argv[2];
                    }
                    else
                        // set nameSpace to interop namespace name
                        opts.nameSpace = 
                            PEGASUS_NAMESPACENAME_INTEROP.getString();

                    enumerateNamespaces_Namespace(client,opts);
                    break;

                    /*
                        CIMValue invokeMethod(
                            const CIMNamespaceName& nameSpace,
                            const CIMObjectPath& instanceName,
                            const CIMName& methodName,
                            const Array<CIMParamValue>& inParameters,

                    Array<CIMParamValue>& outParameters
                    */
                case ID_InvokeMethod :
                    if (argc < 4)
                    {
                        cout << "Usage: InvokeMethod requires that object and"
                            " method names be specified.\n"
                            "Input parameters are optional and can be"
                            " specified with the -ip option or as"
                            " additional parameters to this call. "
                            "Enter each input parameter as name=value"
                            " (no spaces around equal sign)."
                            << endl;
                        exit(1);
                    }
                    opts.objectName = argv[2];
                    opts.inputObjectName = argv[2];
                    opts.methodName = CIMName(argv[3]);

                    // If there are any extra arguments they must be parameters
                    // These parameters  can be used in addtion to parameters
                    // ifrom the -ip option setting. Parameters found here must
                    // be key=value pairs or they will generate an exception.
                    if (argc > 4)
                    {
                        // get input params from command line
                        for (Sint32 i = 4 ; i < argc; i++)
                        {
                            CIMParamValue pv;
                            String s = argv[i];
                            pv = _createMethodParamValue(s, opts);
                            opts.inParams.append(pv);
                        }
                    }
                    invokeMethod(client, opts);
                    break;

                case ID_ShowOptions :
                    showUsage();
                    break;

                case ID_ExecQuery:
                    opts.query = argv[2];
                    if (argc==4)
                        opts.queryLanguage = argv[3];
                    executeQuery(client, opts);
                    break;

                case ID_StatisticsOn:
                    setObjectManagerStatistics(client, true);
                    break;

                case ID_StatisticsOff:
                    setObjectManagerStatistics(client, false);
                    break;

                //case ID_Unknown :
                default:
                    cout << "Invalid Command. Command name must be first parm"
                            " or --c parameter."
                        << " \n  ex. " << arg0 << " enumerateclasses\n"
                        << "Enter " << argv[0] << " -h for help."
                        << endl;
                    exit(1);
                    break;
            }
            if (opts.repeat > 0)
            {
                if (opts.verboseTest)
                {
                    cout << "Repetitition " << opts.repeat << endl;
                }
                opts.repeat--;
                if (opts.time)
                {
                    totalTime += opts.saveElapsedTime;
                    maxTime = LOCAL_MAX(maxTime, opts.saveElapsedTime);
                    minTime = LOCAL_MIN(minTime, opts.saveElapsedTime);
                    rtTotalTime += (returnedPerformanceData.roundTripTime);
                    maxRtTime = LOCAL_MAX(maxRtTime,
                            returnedPerformanceData.roundTripTime);
                    minRtTime = LOCAL_MIN(minRtTime,
                            returnedPerformanceData.roundTripTime);

                    if (returnedPerformanceData.serverTimeKnown)
                    {
                        serverTotalTime += (returnedPerformanceData.serverTime);
                        maxServerTime = LOCAL_MAX(maxServerTime,
                                returnedPerformanceData.serverTime);
                        minServerTime = LOCAL_MIN(minServerTime,
                                returnedPerformanceData.serverTime);
                    }
                }
            }
        } while (opts.repeat > 0  );

        if (opts.time)
        {
            if (repeatCount == 0)
            {
                cout << CommandTable[cmdIndex].CommandName
                    << " "
                    << opts.inputObjectName
                    << " Time= "
                    << opts.saveElapsedTime
                    << " Sec "
                    << " SvrTime= "
                    << CIMValue(returnedPerformanceData.serverTime).toString()
                    << " us "
                    << " RtTime= "
                    << CIMValue(returnedPerformanceData.roundTripTime).
                           toString()
                    << " us "
                    << "Req size= "
                    << CIMValue(returnedPerformanceData.requestSize).toString()
                    << " b Resp size= "
                    << CIMValue(returnedPerformanceData.responseSize).toString()
                    << " b"
                    << endl;
            }
            else
            {
                cout << CommandTable[cmdIndex].CommandName
                    << " "
                    << opts.inputObjectName
                    << " Total Time "
                    << totalTime
                    << " for "
                    << repeatCount
                    << " ops. Avg= "
                    << (totalTime * 1000000)/repeatCount
                    << " us min= "
                    << minTime * 1000000
                    << " us max= "
                    << (maxTime * 1000000) 
                    << " us SvrTime avg= "
                    << CIMValue(serverTotalTime/repeatCount).toString()
                    << " us SvrTime min= "
                    << CIMValue(minServerTime).toString()
                    << " us SvrTime max= "
                    << CIMValue(maxServerTime).toString()
                    << " us"
                    << " RtTime avg= "
                    << CIMValue(rtTotalTime/repeatCount).toString()
                    << " us RtTime min= "
                    << CIMValue(minRtTime).toString()
                    << " us RtTime max= "
                    << CIMValue(maxRtTime).toString()
                    << " us"
                    << endl;
            }
        }
    }
    catch(CIMException& e)
    {
        cerr << argv[0] << " CIMException: "<<" Cmd= " << opts.cimCmd
            << " Object= " << opts.inputObjectName
             << "\n" << e.getMessage()
             << endl;
        opts.termCondition = 1;
    }
    catch(Exception& e)
    {
        PEGASUS_STD(cerr) << argv[0] << " Pegasus Exception: " << e.getMessage()
                <<  ". Cmd = " << opts.cimCmd 
                << " Object = " << opts.inputObjectName
                << PEGASUS_STD(endl);
            opts.termCondition = 1;
    }
    catch(...)
    {
        cerr << argv[0] << " Caught General Exception:" << endl;
        opts.termCondition = 1;
    }

    totalElapsedExecutionTime.stop();

    if (opts.time)
    {
        // if abnormal term, dump all times
        if (opts.termCondition == 1)
        {
            cout << "Exception" << endl;
            cout << "Prev Time " << opts.saveElapsedTime << " Sec" << endl;
            opts.saveElapsedTime = opts.elapsedTime.getElapsed();
            cout << "Last Time " << opts.saveElapsedTime << " Sec" << endl;
            cout << "Total Time " << totalTime << " for "
                << repeatCount << " operations. Avg.= " << totalTime/repeatCount
                << " min= " << minTime << " max= " << maxTime << endl;
        }

        cout << "Total Elapsed Time= " << totalElapsedExecutionTime.getElapsed()
             << " Sec. Terminated at " << System::getCurrentASCIITime() << endl;
    }
    if (opts.delay != 0)
    {
        Threads::sleep(opts.delay * 1000);
    }
    return(opts.termCondition);
}
示例#16
0
/**
 * To retrieve the default configuration value for NameNode's hostName and port
 * TODO: This function currently is using JNI, 
 *       we need to do this without using JNI (HDFS-3917)
 *
 * @param bld The hdfsBuilder handle
 * @param port Used to get the default value for NameNode's port
 * @param nn Used to get the default value for NameNode's hostName
 * @return 0 for success and non-zero value for failure
 */
static int retrieveDefaults(const struct hdfsBuilder *bld, tPort *port,
                            char **nn)
{
    JNIEnv *env = 0;
    jobject jHDFSConf = NULL, jAddress = NULL;
    jstring jHostName = NULL;
    jvalue jVal;
    jthrowable jthr = NULL;
    int ret = 0;
    char buf[512];
    
    env = getJNIEnv();
    if (!env) {
        return EINTERNAL;
    }
    
    jthr = constructNewObjectOfClass(env, &jHDFSConf, HADOOP_HDFS_CONF, "()V");
    if (jthr) {
        ret = printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
                                    "hdfsBuilderConnect(%s)",
                                    hdfsBuilderToStr(bld, buf, sizeof(buf)));
        goto done;
    }
    
    jthr = invokeMethod(env, &jVal, STATIC, NULL,
        HADOOP_NAMENODE, "getHttpAddress",
        "(Lorg/apache/hadoop/conf/Configuration;)Ljava/net/InetSocketAddress;",
        jHDFSConf);
    if (jthr) {
        ret = printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
                                    "hdfsBuilderConnect(%s)",
                                    hdfsBuilderToStr(bld, buf, sizeof(buf)));
        goto done;
    }
    jAddress = jVal.l;
    
    jthr = invokeMethod(env, &jVal, INSTANCE, jAddress,
                        JAVA_INETSOCKETADDRESS, "getPort", "()I");
    if (jthr) {
        ret = printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
                                    "hdfsBuilderConnect(%s)",
                                    hdfsBuilderToStr(bld, buf, sizeof(buf)));
        goto done;
    }
    *port = jVal.i;
    
    jthr = invokeMethod(env, &jVal, INSTANCE, jAddress,
                        JAVA_INETSOCKETADDRESS,
                        "getHostName", "()Ljava/lang/String;");
    if (jthr) {
        ret = printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
                                    "hdfsBuilderConnect(%s)",
                                    hdfsBuilderToStr(bld, buf, sizeof(buf)));
        goto done;
    }
    jHostName = jVal.l;
    jthr = newCStr(env, jHostName, nn);
    if (jthr) {
        ret = printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
                                    "hdfsBuilderConnect(%s)",
                                    hdfsBuilderToStr(bld, buf, sizeof(buf)));
        goto done;
    }

done:
    destroyLocalReference(env, jHDFSConf);
    destroyLocalReference(env, jAddress);
    destroyLocalReference(env, jHostName);
    return ret;
}
//这个地方接收处理数据,返回给服务器需要处理的方法
void BaseHTTPRequestHandler::handler_request(void *recvbuf, DWORD len, BaseDataHandler_RET * ret)//在这个位置,buf所指内存已经没有意义了
{
    BaseDataHandler_RET* p_ret = NULL;
    size_t headersize = 0;
    int result = BaseSocketStream::BSS_RET_UNKNOWN;

    ret->dwOpt = RET_UNKNOWN;
    result = m_pBaseSockeStream->read(recvbuf, len); //buf就是接受到的数据,在这个函数调用完之后,buf就已经不在使用了

    if (result == BaseSocketStream::BSS_RET_RESULT) {
        if (m_len_recvbuf > 0 && m_precv_buf != NULL) {//处理的数据正确,在查找数据,否则不处理

            if ((headersize = find_httpheader(m_precv_buf,m_len_recvbuf)) > 0) {

                if (http_items.parse_httpheaders((const char*)m_precv_buf, 
                                                m_len_recvbuf, 
                                                HttpHeaders::HTTP_REQUEST)) {
                    //获取到分类的信息
                    char *pTemp = NULL;
                    if ((pTemp = http_items["Content-Length"]) != NULL) {
                        
                        int content_length = strtol(pTemp, NULL, 10);
                        if (headersize + content_length <= m_len_recvbuf) {
                         
                            httpcontent.insert(m_precv_buf + headersize, content_length);
                            invokeRequestCallback(&http_items);
                            invokeMethod(http_items.m_method);
                            reset();
                            RELEASE_RECVBUF()
                            ret->dwOpt = RET_SEND; 
                        }
                        else {
                            invokeRequestCallback(&http_items);
                            invokeMethod(http_items.m_method);
                            reset();
                            ret->dwOpt = RET_RECV;
                        }
                    }
                    else {
                        invokeRequestCallback(&http_items);
                        invokeMethod(http_items.m_method);
                        reset(); 
                        RELEASE_RECVBUF()
                        ret->dwOpt = RET_SEND; 
                    }
                }//if (http_items.parse_httpheaders((const char*)m_precv_b........
                else {
                    reset();                //清理用不到的内存
                    RELEASE_RECVBUF()
                    ret->dwOpt = RET_RECV;
                }
            }
            else {
                ret->dwOpt = RET_RECV;
            }
        }//if (m_len_recvbuf > 0 && m_precv_buf == NULL) 
    }
    else if (result == BaseSocketStream::BSS_RET_RECV) {
        ret->dwOpt = RET_RECV;
    }
    else if (result == BaseSocketStream::BSS_RET_SEND) {
        RELEASE_RECVBUF()
        ret->dwOpt = RET_SEND;
    }
    else {

    }
    return;
}
示例#18
0
ValueWrapper SceneManagerCallback_script( const char* symName, const char* method,
                                          boost::python::list& argList, int cascadeEvents )
{
    //int i;
    std::string    theMethod( method );
    cppintrospection::ValueList theArgs;
    //printf("SceneManagerCallback_script: hi! %s, %s, [%s]\n", symName, types, args.c_str());
    t_symbol *s = gensym( symName );

    if (!s->s_thing)
    {
        //std::cout << "oscParser: Could not find referenced object named: " << symName << std::endl;
        return ValueWrapper(0);
    }

    // get osgInrospection::Value from passed UserData by casting as the proper
    // referenced object pointer:
    cppintrospection::Value classInstance;
    if (s->s_type == REFERENCED_STATESET)
        classInstance = cppintrospection::Value(dynamic_cast<ReferencedStateSet*>(s->s_thing));
    else
        classInstance = cppintrospection::Value(dynamic_cast<ReferencedNode*>(s->s_thing));

    // the getInstanceType() method however, gives us the real type being pointed at:
    const cppintrospection::Type &classType = classInstance.getInstanceType();

    if (! classType.isDefined())
    {
        std::cout << "ERROR: oscParser cound not process message '" << symName
                  << ". cppintrospection has no data for that node." << std::endl;
        return ValueWrapper(0);
    }

    size_t nbArgs = boost::python::len( argList );
    double da; float fa; int ia; std::string sa;

    for ( size_t i = 0; i < nbArgs; i++ )
    {

        if ( pyextract( argList[i], &da ) )
            theArgs.push_back( (double) da );
        else if ( pyextract( argList[i], &fa ) )
            theArgs.push_back( (float) fa );
        else if ( pyextract( argList[i], &ia ) )
            theArgs.push_back( (int) ia );
        else
        {
            sa = pyextract( argList[i] );
            if (sa != "" )
                theArgs.push_back( (const char*) sa.c_str() );
        }
    }

    // invoke the method on the node, and if it doesn't work, then just forward
    // the message:
    cppintrospection::Value v;
    bool eventScriptCalled = false;
    if (cascadeEvents)
    {
        if (s->s_type == REFERENCED_NODE)
        {
            //printf("calling eventscript...\n");
            eventScriptCalled = dynamic_cast<ReferencedNode*>(s->s_thing)->callEventScript( theMethod, theArgs );
        }
    }

    if (eventScriptCalled)
    { // cascaded event script called successful, do not invokeMethod, return nothing to the python script
        return ValueWrapper(0);
    }
    else
    { // no cascaded event assigned to theMethod or cascaded event script failed.  call invokeMethod and return result to python script
        if (invokeMethod(classInstance, classType, theMethod, theArgs, v))
        {
            return ValueWrapper(v);
        }
        else
        {
            if (spinApp::Instance().getContext()->isServer())
            {
                lo_message msg = lo_message_new();
                lo_message_add_string(msg, theMethod.c_str());
                for ( size_t i = 0; i < nbArgs; i++ )
                {
                    if ( pyextract( argList[i], &da ) ) lo_message_add_float(msg, (float) da );
                    else if ( pyextract( argList[i], &fa ) ) lo_message_add_float(msg, (float) fa );
                    else if ( pyextract( argList[i], &ia ) ) lo_message_add_float(msg, (float) ia );
                    else
                    {
                        sa = pyextract( argList[i] );
                        if (sa != "" ) lo_message_add_string(msg, (const char*) sa.c_str() );
                    }
                }
                std::string path = "/SPIN/" + spinApp::Instance().getSceneID() + "/" + s->s_name;
                std::vector<lo_address>::iterator addrIter;
                for (addrIter = spinApp::Instance().getContext()->lo_txAddrs_.begin(); addrIter != spinApp::Instance().getContext()->lo_txAddrs_.end(); ++addrIter)
                {
                    lo_send_message_from((*addrIter), spinApp::Instance().getContext()->lo_infoServ_, path.c_str(), msg);
                }
            }
        }

    }
    //pthread_mutex_unlock(&sceneMutex);
    return ValueWrapper(0);
}
示例#19
0
int hdfsGetConf(const char *&host, unsigned short &port, const char *&user, char *group[], int &group_size)
{
  jobject jConfiguration = NULL;
  JNIEnv *env = 0;
  jthrowable jExc = NULL;
  int ret = 0;

  env = getJNIEnv();
  if (env == NULL) {
    fprintf(stderr, "can't JNI Env\n");
    return -1;
  }

  jConfiguration =
    constructNewObjectOfClass(env, &jExc, HADOOP_CONF, "()V");
  if (jConfiguration == NULL) {
    fprintf(stderr, "Can't construct instance of class "
            "org.apache.hadoop.conf.Configuration\n");
    if (jExc != NULL) {
      env->ExceptionDescribe();
    }

    return -1;
  }

  jvalue jVal;
  jstring ugiStr = (env)->NewStringUTF(UGI_INFO);
  jstring fsStr = env->NewStringUTF(DEFAULT_FS);

  if (invokeMethod(env, &jVal, NULL, jConfiguration, HADOOP_CONF, "get", JMETHOD1(JPARAM(JAVA_STRING), JPARAM(JAVA_STRING)), ugiStr) != 0) {
    //set err return
    ret = -1;

    fprintf(stderr, "can't invoke method get ugi\n");
    if (env->ExceptionOccurred()) {
      env->ExceptionDescribe();
    }
  }

  //parse group and user info
  if (ret == 0) {
    if (jVal.l != NULL) {
      const char *ugi = (env)->GetStringUTFChars((jstring)jVal.l, NULL);

      if (ugi != NULL) {
        fprintf(stdout, "ugi string is %s\n", ugi);

        if (parseGroup(user, group, group_size, ugi)) {
          fprintf(stderr, "can't parse group info\n");
          ret = -1;
        }

        env->ReleaseStringUTFChars((jstring)jVal.l, ugi);
      }
    } else {
      fprintf(stdout, "can't find gui=%s\n", UGI_INFO);
    }
  }

  if (ret == 0) {                               /* get host and port info */
    if (invokeMethod(env, &jVal, NULL, jConfiguration, HADOOP_CONF, "get", JMETHOD1(JPARAM(JAVA_STRING), JPARAM(JAVA_STRING)), fsStr) != 0) {
      ret = -1;

      fprintf(stderr, "can't invoke method get default fs\n");
      if (env->ExceptionOccurred()) {
        env->ExceptionDescribe();
      }
    } else {
      if (jVal.l != NULL) {
        const char *str = (env)->GetStringUTFChars((jstring)jVal.l, NULL);

        if (str != NULL) {
          fprintf(stdout, "fs string is %s\n", str);
          if (parseHostAndPort(host, port, str)) {
            fprintf(stderr, "can't parse host and port info\n");
            ret = -1;
          }

          env->ReleaseStringUTFChars((jstring)jVal.l, str);
        }
      } else {
        fprintf(stdout, "can't find gui=%s\n", UGI_INFO);
      }
    }
  }

  destroyLocalReference(env, ugiStr);
  destroyLocalReference(env, jConfiguration);

  return ret;
}