|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.rosuda.REngine.REngine org.rosuda.REngine.Rserve.RConnection
public class RConnection
class providing TCP/IP connection to an Rserve
Field Summary | |
---|---|
static int |
AT_crypt
authorization type: unix crypt |
static int |
AT_plain
authorization type: plain text |
protected int |
rsrvVersion
version of the server (as reported in IDstring just after Rsrv) |
static java.lang.String |
transferCharset
This static variable specifies the character set used to encode string for transfer. |
Fields inherited from class org.rosuda.REngine.REngine |
---|
lastEngine |
Constructor Summary | |
---|---|
RConnection()
make a new local connection on default port (6311) |
|
RConnection(java.lang.String host)
make a new connection to specified host on default port (6311) |
|
RConnection(java.lang.String host,
int port)
make a new connection to specified host and given port. |
Method Summary | |
---|---|
void |
assign(java.lang.String sym,
REXP rexp)
assign a content of a REXP to a symbol in R. |
void |
assign(java.lang.String symbol,
REXP value,
REXP env)
assign into an environment |
void |
assign(java.lang.String sym,
java.lang.String ct)
assign a string value to a symbol in R. |
boolean |
close()
closes current connection |
RFileOutputStream |
createFile(java.lang.String fn)
create a file on the Rserve for writing |
REXP |
createReference(REXP ref)
create a reference by pushing local data to R and returning a reference to the data. |
RSession |
detach()
detaches the session and closes the connection (requires Rserve 0.4+). |
REXP |
eval(REXP what,
REXP where,
boolean resolve)
evaluate an expression vector |
REXP |
eval(java.lang.String cmd)
evaluates the given command and retrieves the result |
void |
finalize()
|
void |
finalizeReference(REXP ref)
removes reference from the R side. |
REXP |
get(java.lang.String symbol,
REXP env,
boolean resolve)
get a value from an environment |
java.lang.String |
getLastError()
get last error string |
REXP |
getParentEnvironment(REXP env,
boolean resolve)
get the parent environemnt of an environemnt |
int |
getServerVersion()
get server version as reported during the handshake. |
boolean |
isConnected()
check connection state. |
void |
login(java.lang.String user,
java.lang.String pwd)
login using supplied user/pwd. |
boolean |
needLogin()
check authentication requirement sent by server |
REXP |
newEnvironment(REXP parent,
boolean resolve)
create a new environemnt |
RFileInputStream |
openFile(java.lang.String fn)
open a file on the Rserve for reading |
REXP |
parse(java.lang.String text,
boolean resolve)
parse a string into an expression vector |
REXP |
parseAndEval(java.lang.String text,
REXP where,
boolean resolve)
convenince method equivalent to eval(parse(text, false), where, resolve); |
void |
removeFile(java.lang.String fn)
remove a file on the Rserve |
REXP |
resolveReference(REXP ref)
fetch the contents of the given reference. |
void |
serverEval(java.lang.String cmd)
evaluates the given command in the master server process asynchronously (control command). |
void |
serverShutdown()
attempt to shut down the server process cleanly. |
void |
serverSource(java.lang.String serverFile)
sources the given file (the path must be local to the server!) |
void |
setSendBufferSize(long sbs)
Sets send buffer size of the Rserve (in bytes) for the current connection. |
void |
setStringEncoding(java.lang.String enc)
set string encoding for this session. |
void |
shutdown()
shutdown remote Rserve. |
void |
voidEval(java.lang.String cmd)
evaluates the given command, but does not fetch the result (useful for assignment operations) |
RSession |
voidEvalDetach(java.lang.String cmd)
evaluates the given command, detaches the session (see @link{detach()}) and closes connection while the command is being evaluted (requires Rserve 0.4+). |
Methods inherited from class org.rosuda.REngine.REngine |
---|
assign, assign, assign, assign, engineForClass, engineForClass, getLastEngine, lock, parseAndEval, supportsEnvironments, supportsLocking, supportsReferences, supportsREPL, toString, tryLock, unlock, wrap |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static java.lang.String transferCharset
public static final int AT_plain
public static final int AT_crypt
protected int rsrvVersion
Constructor Detail |
---|
public RConnection() throws RserveException
RserveException
public RConnection(java.lang.String host) throws RserveException
host
- host name/IP
RserveException
public RConnection(java.lang.String host, int port) throws RserveException
isConnected()
to ensure the connection was successfully created.
host
- host name/IPport
- TCP port
RserveException
Method Detail |
---|
public void finalize()
finalize
in class java.lang.Object
public int getServerVersion()
public boolean close()
close
in class REngine
true
if the close opetaion was successful, false
otherwise.public void voidEval(java.lang.String cmd) throws RserveException
cmd
- command/expression string
RserveException
public RSession voidEvalDetach(java.lang.String cmd) throws RserveException
cmd
- command/expression string
RserveException
public REXP eval(java.lang.String cmd) throws RserveException
cmd
- command/expression string
null
if an error occured
RserveException
public void assign(java.lang.String sym, java.lang.String ct) throws RserveException
assign
in class REngine
sym
- symbol name. Currently assign uses CMD_setSEXP command of Rserve, i.e. the symbol value is NOT parsed. It is the responsibility of the user to make sure that the symbol name is valid in R (recall the difference between a symbol and an expression!). In fact R will always create the symbol, but it may not be accessible (examples: "bar\nfoo" or "bar$foo").ct
- contents
RserveException
public void assign(java.lang.String sym, REXP rexp) throws RserveException
assign
in class REngine
sym
- symbol name. Currently assign uses CMD_setSEXP command of Rserve, i.e. the symbol value is NOT parsed. It is the responsibility of the user to make sure that the symbol name is valid in R (recall the difference between a symbol and an expression!). In fact R will always create the symbol, but it may not be accessible (examples: "bar\nfoo" or "bar$foo").rexp
- contents
RserveException
public RFileInputStream openFile(java.lang.String fn) throws java.io.IOException
fn
- file name. should not contain any path delimiters, since Rserve may restrict the access to local working directory.
java.io.IOException
public RFileOutputStream createFile(java.lang.String fn) throws java.io.IOException
fn
- file name. should not contain any path delimiters, since Rserve may restrict the access to local working directory.
java.io.IOException
public void removeFile(java.lang.String fn) throws RserveException
fn
- file name. should not contain any path delimiters, since Rserve may restrict the access to local working directory.
RserveException
public void shutdown() throws RserveException
RserveException
public void setSendBufferSize(long sbs) throws RserveException
sbs
- send buffer size (in bytes) min=32k, max=1GB
RserveException
public void setStringEncoding(java.lang.String enc) throws RserveException
encoding
option in the server or by calling
setStringEncoding("utf8") at the beginning of a session (but
after login).
enc
- name of the encoding as defined by Rserve - as of
Rserve version 0.5-3 valid values are "utf8", "latin1" and
"native" (case-sensitive)
RserveException
public void login(java.lang.String user, java.lang.String pwd) throws RserveException
user
- usernamepwd
- password
RserveException
public RSession detach() throws RserveException
RserveException
public boolean isConnected()
true
if this connection is alivepublic boolean needLogin()
true
is server requires authentication. In such case first
command after connecting must be login(java.lang.String, java.lang.String)
.public java.lang.String getLastError()
public void serverEval(java.lang.String cmd) throws RserveException
cmd
- command/expression string
RserveException
public void serverSource(java.lang.String serverFile) throws RserveException
#serverEval()
for details on control commands.
serverFile
- path to a file on the server (it is recommended to always use full paths, because the server process has a different working directory than the client child process!).
RserveException
public void serverShutdown() throws RserveException
shutdown()
method and this method: serverShutdown()
is a proper control command and thus fully authentication controllable, whereas shutdown()
is a client-side command sent to the client child process and thus relying on the ability of the client to signal the server process which may be disabled. Therefore serverShutdown()
is preferred and more reliable for Rserve 0.6-0 and higher.
RserveException
public REXP parse(java.lang.String text, boolean resolve) throws REngineException
REngine
parse
in class REngine
text
- string to parseresolve
- resolve the resulting REXP (true
) or just return a reference (false
)
REngineException
public REXP eval(REXP what, REXP where, boolean resolve) throws REngineException
REngine
eval
in class REngine
what
- an expression (or vector of such) to evaluatewhere
- environment to evaluate in (use null
for the global environemnt and/or if environments are not supported by the engine)resolve
- resolve the resulting REXP or just return a reference
REngineException
public REXP parseAndEval(java.lang.String text, REXP where, boolean resolve) throws REngineException
REngine
eval(parse(text, false), where, resolve);
parseAndEval
in class REngine
text
- to parse (see REngine.parse(java.lang.String, boolean)
)where
- environment to evaluate in (see REngine.eval(org.rosuda.REngine.REXP, org.rosuda.REngine.REXP, boolean)
)resolve
- whether to resolve the resulting reference or not (see REngine.eval(org.rosuda.REngine.REXP, org.rosuda.REngine.REXP, boolean)
)
REngineException
public void assign(java.lang.String symbol, REXP value, REXP env) throws REngineException
assign
in class REngine
symbol
- symbol namevalue
- value to assignenv
- environment to assign to
REngineException
public REXP get(java.lang.String symbol, REXP env, boolean resolve) throws REngineException
get
in class REngine
symbol
- symbol nameenv
- environmentresolve
- resolve the resulting REXP or just return a reference
REngineException
public REXP resolveReference(REXP ref) throws REngineException
resolveReference
in class REngine
ref
- reference to resolve
REngineException
public REXP createReference(REXP ref) throws REngineException
REngine
#REngineException
exception if REngine.supportsReferences()
returns false
.
createReference
in class REngine
ref
- to create reference to
REngineException
public void finalizeReference(REXP ref) throws REngineException
REngine
REXPReference
and should never be called directly.
finalizeReference
in class REngine
ref
- reference to finalize
REngineException
public REXP getParentEnvironment(REXP env, boolean resolve) throws REngineException
REngine
getParentEnvironment
in class REngine
env
- environment to queryresolve
- whether to resolve the resulting environment reference
REngineException
public REXP newEnvironment(REXP parent, boolean resolve) throws REngineException
REngine
newEnvironment
in class REngine
parent
- parent environmentresolve
- whether to resolve the reference to the environemnt (usually false
since the returned environment will be empty)
REngineException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |