File: RSession.java

package info (click to toggle)
rjava 1.0-14-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,188 kB
  • sloc: java: 13,223; ansic: 5,503; sh: 3,776; xml: 325; makefile: 250; perl: 33
file content (40 lines) | stat: -rw-r--r-- 1,223 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package org.rosuda.REngine.Rserve;

import org.rosuda.REngine.Rserve.protocol.RPacket;
import org.rosuda.REngine.Rserve.protocol.RTalk;

public class RSession implements java.io.Serializable {
    // serial version UID should only change if method signatures change
    // significantly enough that previous versions cannot be used with
    // current versions
    private static final long serialVersionUID = -7048099825974875604l;

    String host;
    int port;
    byte[] key;

    transient RPacket attachPacket=null; // response on session attach
    int rsrvVersion;

    protected RSession() {
        // default no-args constructor for serialization
    }

    RSession(RConnection c, RPacket p) throws RserveException {
	this.host=c.host;
	this.rsrvVersion=c.rsrvVersion;
	byte[] ct = p.getCont();
	if (ct==null || ct.length!=32+3*4)
	    throw new RserveException(c, "Invalid response to session detach request.");
	this.port = RTalk.getInt(ct, 4);
	this.key=new byte[32];
	System.arraycopy(ct, 12, this.key, 0, 32);
    }

    /** attach/resume this session */
    public RConnection attach() throws RserveException {
	RConnection c = new RConnection(this);
	attachPacket = c.rt.request(-1);
	return c;
    }
}