当前位置: 首页>>代码示例>>Java>>正文


Java RConnection.close方法代码示例

本文整理汇总了Java中org.rosuda.REngine.Rserve.RConnection.close方法的典型用法代码示例。如果您正苦于以下问题:Java RConnection.close方法的具体用法?Java RConnection.close怎么用?Java RConnection.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.rosuda.REngine.Rserve.RConnection的用法示例。


在下文中一共展示了RConnection.close方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isRserveRunning

import org.rosuda.REngine.Rserve.RConnection; //导入方法依赖的package包/类
/** check whether Rserve is currently running (on local machine and default port).
@return <code>true</code> if local Rserve instance is running, <code>false</code> otherwise
 */
public static boolean isRserveRunning() {
    try {
        RConnection c = new RConnection();
        System.err.println("Rserve is running.");
        c.close();
        return true;
    } catch (Exception e) {
        System.err.println("First connect try failed with: " + e.getMessage());
    }
    return false;
}
 
开发者ID:mzmine,项目名称:mzmine2,代码行数:15,代码来源:StartRserve.java

示例2: close

import org.rosuda.REngine.Rserve.RConnection; //导入方法依赖的package包/类
/**
 * Close R connection
 */
private static void close(RConnection conn) {
    try {
        REXP xp = conn.parseAndEval("gc()");
        if (xp.inherits("try-error")) {
            throw new IOException("failed to load R workspace; \nError: " + xp.asString());
        }
        conn.close();
    }
    catch (Exception e) {
        // do nothing
        // should not occur
        // TODO: ...
    }
}
 
开发者ID:52North,项目名称:movingcode,代码行数:18,代码来源:RServerController.java

示例3: isRserveRunning

import org.rosuda.REngine.Rserve.RConnection; //导入方法依赖的package包/类
/** check whether Rserve is currently running (on local machine and default port).
 @return <code>true</code> if local Rserve instance is running, <code>false</code> otherwise
 */
public static boolean isRserveRunning() {
	try {
		RConnection c = new RConnection();
		System.out.println("Rserve is running.");
		c.close();
		return true;
	} catch (Exception e) {
		System.out.println("First connect try failed with: "+e.getMessage());
	}
	return false;
}
 
开发者ID:erickalendra,项目名称:JavaRserveREngineClient,代码行数:15,代码来源:StartRserve.java

示例4: launchRserve

import org.rosuda.REngine.Rserve.RConnection; //导入方法依赖的package包/类
/** attempt to start Rserve. Note: parameters are <b>not</b> quoted, so avoid using any quotes in arguments
 @param cmd command necessary to start R
 @param rargs arguments are are to be passed to R
 @param rsrvargs arguments to be passed to Rserve
 @return <code>true</code> if Rserve is running or was successfully started, <code>false</code> otherwise.
 */
public static boolean launchRserve(String cmd, String rargs, String rsrvargs, boolean debug) {
	try {
		Process p;
		boolean isWindows = false;
		String osname = System.getProperty("os.name");
		if (osname != null && osname.length() >= 7 && osname.substring(0,7).equals("Windows")) {
			isWindows = true; /* Windows startup */
			p = Runtime.getRuntime().exec("\""+cmd+"\" -e \"library(Rserve);Rserve("+(debug?"TRUE":"FALSE")+",args='"+rsrvargs+"')\" "+rargs);
		} else /* unix startup */
			p = Runtime.getRuntime().exec(new String[] {
						      "/bin/sh", "-c",
						      "echo 'library(Rserve);Rserve("+(debug?"TRUE":"FALSE")+",args=\""+rsrvargs+"\")'|"+cmd+" "+rargs
						      });
		System.out.println("waiting for Rserve to start ... ("+p+")");
		// we need to fetch the output - some platforms will die if you don't ...
		StreamHog errorHog = new StreamHog(p.getErrorStream(), false);
		StreamHog outputHog = new StreamHog(p.getInputStream(), false);
		if (!isWindows) /* on Windows the process will never return, so we cannot wait */
			p.waitFor();
		System.out.println("call terminated, let us try to connect ...");
	} catch (Exception x) {
		System.out.println("failed to start Rserve process with "+x.getMessage());
		return false;
	}
	int attempts = 5; /* try up to 5 times before giving up. We can be conservative here, because at this point the process execution itself was successful and the start up is usually asynchronous */
	while (attempts > 0) {
		try {
			RConnection c = new RConnection();
			System.out.println("Rserve is running.");
			c.close();
			return true;
		} catch (Exception e2) {
			System.out.println("Try failed with: "+e2.getMessage());
		}
		/* a safety sleep just in case the start up is delayed or asynchronous */
		try { Thread.sleep(500); } catch (InterruptedException ix) { };
		attempts--;
	}
	return false;
}
 
开发者ID:erickalendra,项目名称:JavaRserveREngineClient,代码行数:47,代码来源:StartRserve.java


注:本文中的org.rosuda.REngine.Rserve.RConnection.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。