]> gerrit.simantics Code Review - simantics/r.git/blob - bundles/org.simantics.r.scl/src/org/rosuda/REngine/Rserve/RSession.java
(refs #6833) Test RExp inheritance in SCL
[simantics/r.git] / bundles / org.simantics.r.scl / src / org / rosuda / REngine / Rserve / RSession.java
1 package org.rosuda.REngine.Rserve;
2
3 import org.rosuda.REngine.Rserve.protocol.RPacket;
4 import org.rosuda.REngine.Rserve.protocol.RTalk;
5
6 public class RSession implements java.io.Serializable {
7     // serial version UID should only change if method signatures change
8     // significantly enough that previous versions cannot be used with
9     // current versions
10     private static final long serialVersionUID = -7048099825974875604l;
11
12     String host;
13     int port;
14     byte[] key;
15
16     transient RPacket attachPacket=null; // response on session attach
17     int rsrvVersion;
18
19     protected RSession() {
20         // default no-args constructor for serialization
21     }
22
23     RSession(RConnection c, RPacket p) throws RserveException {
24         this.host=c.host;
25         this.rsrvVersion=c.rsrvVersion;
26         byte[] ct = p.getCont();
27         if (ct==null || ct.length!=32+3*4)
28             throw new RserveException(c, "Invalid response to session detach request.");
29         this.port = RTalk.getInt(ct, 4);
30         this.key=new byte[32];
31         System.arraycopy(ct, 12, this.key, 0, 32);
32     }
33
34     /** attach/resume this session */
35     public RConnection attach() throws RserveException {
36         RConnection c = new RConnection(this);
37         attachPacket = c.rt.request(-1);
38         return c;
39     }
40 }