Package rstatistics

Source Code of rstatistics.RServerConnector

package rstatistics;

import rstatistics.interfaces.IRService;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.rosuda.REngine.REXP;
import org.rosuda.REngine.Rserve.RConnection;
import org.rosuda.REngine.Rserve.RserveException;

/**
*
* @author vaio
*/
public class RServerConnector extends Singleton implements IRService {

    private RConnection rConnection;

    /**
     *
     */
    public RServerConnector() {
        try {
            rConnection = new RConnection();
        } catch (RserveException ex) {
            Logger.getLogger(RServerConnector.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     *
     * @return
     */
    public static IRService getResource() {
        if (resource == null) {
            resource = new RServerConnector();
        }
        return resource;
    }

    /**
     *
     * @param cmd
     * @return
     */
    @Override
    public RExpressionServer eval(String cmd) {
        REXP ret = null;
        try {
            ret = rConnection.eval(cmd);
        } catch (RserveException ex) {
            Logger.getLogger(RServerConnector.class.getName()).log(Level.SEVERE, null, ex);
        }
        return new RExpressionServer(ret);
    }

    /**
     *
     * @param cmd
     */
    @Override
    public void voidEval(String cmd) {
        try {
            rConnection.voidEval(cmd);
        } catch (RserveException ex) {
            Logger.getLogger(RServerConnector.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     *
     * @return
     */
    @Override
    public boolean isConnected() {
        return rConnection.isConnected();
    }

    /**
     *
     * @return
     */
    @Override
    public IRService getRService() {
        return this;
    }
}
TOP

Related Classes of rstatistics.RServerConnector

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.