org.rosuda.REngine.Rserve.protocol
Class RTalk

java.lang.Object
  extended by org.rosuda.REngine.Rserve.protocol.RTalk

public class RTalk
extends java.lang.Object

This class encapsulates the QAP1 protocol used by Rserv. it is independent of the underying protocol(s), therefore RTalk can be used over any transport layer

The current implementation supports long (0.3+/0102) data format only up to 32-bit and only for incoming packets.

Version:
$Id: RTalk.java 3247 2010-01-26 11:40:59Z urbanek $

Field Summary
static int CMD_assignSEXP
           
static int CMD_attachSession
           
static int CMD_closeFile
           
static int CMD_createFile
           
static int CMD_ctrlEval
           
static int CMD_ctrlShutdown
           
static int CMD_ctrlSource
           
static int CMD_detachedVoidEval
           
static int CMD_detachSession
           
static int CMD_eval
           
static int CMD_login
           
static int CMD_openFile
           
static int CMD_readFile
           
static int CMD_removeFile
           
static int CMD_setBufferSize
           
static int CMD_setEncoding
           
static int CMD_setSEXP
           
static int CMD_shutdown
           
static int CMD_voidEval
           
static int CMD_writeFile
           
static int DT_ARRAY
           
static int DT_BYTESTREAM
           
static int DT_CHAR
           
static int DT_DOUBLE
           
static int DT_INT
           
static int DT_LARGE
          this is a flag saying that the contents is large (>0xfffff0) and hence uses 56-bit length field
static int DT_SEXP
           
static int DT_STRING
           
static int ERR_access_denied
           
static int ERR_auth_failed
           
static int ERR_conn_broken
           
static int ERR_ctrl_closed
           
static int ERR_data_overflow
           
static int ERR_detach_failed
           
static int ERR_inv_cmd
           
static int ERR_inv_par
           
static int ERR_IOerror
           
static int ERR_not_open
           
static int ERR_object_too_big
           
static int ERR_out_of_mem
           
static int ERR_Rerror
           
static int ERR_session_busy
           
static int ERR_unknown_cmd
           
static int ERR_unsupported_cmd
           
 
Constructor Summary
RTalk(java.io.InputStream sis, java.io.OutputStream sos)
          constructor; parameters specify the streams
 
Method Summary
static int getInt(byte[] buf, int o)
          converts bit-wise stored int in Intel-endian form into Java int
static int getLen(byte[] buf, int o)
          converts bit-wise stored length from a header.
static long getLong(byte[] buf, int o)
          converts bit-wise Intel-endian format into long
static byte[] newHdr(int ty, int len)
          creates a new header according to the type and length of the parameter
 RPacket request(int cmd)
          sends a request with no attached parameters
 RPacket request(int cmd, byte[] cont)
          sends a request with attached parameters
 RPacket request(int cmd, byte[] prefix, byte[] cont, int offset, int len)
          sends a request with attached prefix and parameters.
 RPacket request(int cmd, int par)
          sends a request with one string parameter attached
 RPacket request(int cmd, java.lang.String par)
          sends a request with one string parameter attached
static int setHdr(int ty, int len, byte[] buf, int o)
          writes cmd/resp/type byte + 3/7 bytes len into a byte buffer at specified offset.
static void setInt(int v, byte[] buf, int o)
          writes bit-wise int to a byte buffer at specified position in Intel-endian form
static void setLong(long l, byte[] buf, int o)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DT_INT

public static final int DT_INT
See Also:
Constant Field Values

DT_CHAR

public static final int DT_CHAR
See Also:
Constant Field Values

DT_DOUBLE

public static final int DT_DOUBLE
See Also:
Constant Field Values

DT_STRING

public static final int DT_STRING
See Also:
Constant Field Values

DT_BYTESTREAM

public static final int DT_BYTESTREAM
See Also:
Constant Field Values

DT_SEXP

public static final int DT_SEXP
See Also:
Constant Field Values

DT_ARRAY

public static final int DT_ARRAY
See Also:
Constant Field Values

DT_LARGE

public static final int DT_LARGE
this is a flag saying that the contents is large (>0xfffff0) and hence uses 56-bit length field

See Also:
Constant Field Values

CMD_login

public static final int CMD_login
See Also:
Constant Field Values

CMD_voidEval

public static final int CMD_voidEval
See Also:
Constant Field Values

CMD_eval

public static final int CMD_eval
See Also:
Constant Field Values

CMD_shutdown

public static final int CMD_shutdown
See Also:
Constant Field Values

CMD_openFile

public static final int CMD_openFile
See Also:
Constant Field Values

CMD_createFile

public static final int CMD_createFile
See Also:
Constant Field Values

CMD_closeFile

public static final int CMD_closeFile
See Also:
Constant Field Values

CMD_readFile

public static final int CMD_readFile
See Also:
Constant Field Values

CMD_writeFile

public static final int CMD_writeFile
See Also:
Constant Field Values

CMD_removeFile

public static final int CMD_removeFile
See Also:
Constant Field Values

CMD_setSEXP

public static final int CMD_setSEXP
See Also:
Constant Field Values

CMD_assignSEXP

public static final int CMD_assignSEXP
See Also:
Constant Field Values

CMD_setBufferSize

public static final int CMD_setBufferSize
See Also:
Constant Field Values

CMD_setEncoding

public static final int CMD_setEncoding
See Also:
Constant Field Values

CMD_detachSession

public static final int CMD_detachSession
See Also:
Constant Field Values

CMD_detachedVoidEval

public static final int CMD_detachedVoidEval
See Also:
Constant Field Values

CMD_attachSession

public static final int CMD_attachSession
See Also:
Constant Field Values

CMD_ctrlEval

public static final int CMD_ctrlEval
See Also:
Constant Field Values

CMD_ctrlSource

public static final int CMD_ctrlSource
See Also:
Constant Field Values

CMD_ctrlShutdown

public static final int CMD_ctrlShutdown
See Also:
Constant Field Values

ERR_auth_failed

public static final int ERR_auth_failed
See Also:
Constant Field Values

ERR_conn_broken

public static final int ERR_conn_broken
See Also:
Constant Field Values

ERR_inv_cmd

public static final int ERR_inv_cmd
See Also:
Constant Field Values

ERR_inv_par

public static final int ERR_inv_par
See Also:
Constant Field Values

ERR_Rerror

public static final int ERR_Rerror
See Also:
Constant Field Values

ERR_IOerror

public static final int ERR_IOerror
See Also:
Constant Field Values

ERR_not_open

public static final int ERR_not_open
See Also:
Constant Field Values

ERR_access_denied

public static final int ERR_access_denied
See Also:
Constant Field Values

ERR_unsupported_cmd

public static final int ERR_unsupported_cmd
See Also:
Constant Field Values

ERR_unknown_cmd

public static final int ERR_unknown_cmd
See Also:
Constant Field Values

ERR_data_overflow

public static final int ERR_data_overflow
See Also:
Constant Field Values

ERR_object_too_big

public static final int ERR_object_too_big
See Also:
Constant Field Values

ERR_out_of_mem

public static final int ERR_out_of_mem
See Also:
Constant Field Values

ERR_ctrl_closed

public static final int ERR_ctrl_closed
See Also:
Constant Field Values

ERR_session_busy

public static final int ERR_session_busy
See Also:
Constant Field Values

ERR_detach_failed

public static final int ERR_detach_failed
See Also:
Constant Field Values
Constructor Detail

RTalk

public RTalk(java.io.InputStream sis,
             java.io.OutputStream sos)
constructor; parameters specify the streams

Parameters:
sis - socket input stream
sos - socket output stream
Method Detail

setInt

public static void setInt(int v,
                          byte[] buf,
                          int o)
writes bit-wise int to a byte buffer at specified position in Intel-endian form

Parameters:
v - value to be written
buf - buffer
o - offset in the buffer to start at. An int takes always 4 bytes

setHdr

public static int setHdr(int ty,
                         int len,
                         byte[] buf,
                         int o)
writes cmd/resp/type byte + 3/7 bytes len into a byte buffer at specified offset.

Parameters:
ty - type/cmd/resp byte
len - length
buf - buffer
o - offset
Returns:
offset in buf just after the header. Please note that since Rserve 0.3 the header can be either 4 or 8 bytes long, depending on the len parameter.

newHdr

public static byte[] newHdr(int ty,
                            int len)
creates a new header according to the type and length of the parameter

Parameters:
ty - type/cmd/resp byte
len - length

getInt

public static int getInt(byte[] buf,
                         int o)
converts bit-wise stored int in Intel-endian form into Java int

Parameters:
buf - buffer containg the representation
o - offset where to start (4 bytes will be used)
Returns:
the int value. no bounds checking is done so you need to make sure that the buffer is big enough

getLen

public static int getLen(byte[] buf,
                         int o)
converts bit-wise stored length from a header. "long" format is supported up to 32-bit

Parameters:
buf - buffer
o - offset of the header (length is at o+1)
Returns:
length

getLong

public static long getLong(byte[] buf,
                           int o)
converts bit-wise Intel-endian format into long

Parameters:
buf - buffer
o - offset (8 bytes will be used)
Returns:
long value

setLong

public static void setLong(long l,
                           byte[] buf,
                           int o)

request

public RPacket request(int cmd)
sends a request with no attached parameters

Parameters:
cmd - command
Returns:
returned packet or null if something went wrong

request

public RPacket request(int cmd,
                       byte[] cont)
sends a request with attached parameters

Parameters:
cmd - command
cont - contents - parameters
Returns:
returned packet or null if something went wrong

request

public RPacket request(int cmd,
                       byte[] prefix,
                       byte[] cont,
                       int offset,
                       int len)
sends a request with attached prefix and parameters. Both prefix and cont can be null. Effectively request(a,b,null) and request(a,null,b) are equivalent.

Parameters:
cmd - command - a special command of -1 prevents request from sending anything
prefix - - this content is sent *before* cont. It is provided to save memory copy operations where a small header precedes a large data chunk (usually prefix conatins the parameter header and cont contains the actual data).
cont - contents
offset - offset in cont where to start sending (if <0 then 0 is assumed, if >cont.length then no cont is sent)
len - number of bytes in cont to send (it is clipped to the length of cont if necessary)
Returns:
returned packet or null if something went wrong

request

public RPacket request(int cmd,
                       java.lang.String par)
sends a request with one string parameter attached

Parameters:
cmd - command
par - parameter - length and DT_STRING will be prepended
Returns:
returned packet or null if something went wrong

request

public RPacket request(int cmd,
                       int par)
sends a request with one string parameter attached

Parameters:
cmd - command
par - parameter of the type DT_INT
Returns:
returned packet or null if something went wrong