{"action":"created","comment":{"url":"https://api.github.com/repos/ow2-proactive/connector-r/pulls/comments/43878294","id":43878294,"diff_hunk":"@@ -0,0 +1,287 @@\n+package org.ow2.parserve.util.rsession;\n+\n+import org.apache.log4j.Logger;\n+import org.rosuda.REngine.REXP;\n+import org.rosuda.REngine.REXPMismatchException;\n+import org.rosuda.REngine.REXPString;\n+import org.rosuda.REngine.REngineException;\n+import org.rosuda.REngine.Rserve.RConnection;\n+import org.rosuda.REngine.Rserve.RserveException;\n+\n+import java.io.File;\n+\n+/**\n+ * Handles all interactions with the R engine\n+ *\n+ * @author Activeeon Team\n+ */\n+public class Rsession {\n+\n+    public final static int MinRserveVersion = 103;\n+    public final static String STATUS_NOT_SET = \"Unknown status\", STATUS_READY = \"Ready\", STATUS_ERROR = \"Error\", STATUS_ENDED = \"End\", STATUS_NOT_CONNECTED = \"Not connected\", STATUS_CONNECTING = \"Connecting...\";\n+    public static final boolean UNIX_OPTIMIZE = true;\n+    public final static String HEAD_SET = \"[set] \";\n+    public final static String HEAD_EVAL = \"[eval] \";\n+    public final static String HEAD_SERVEREVAL = \"[server-eval] \";\n+    public final static String HEAD_EXCEPTION = \"[exception] \";\n+    public final static String HEAD_ERROR = \"[error] \";\n+    public final static String ROUTPUT_END = \"<rsession-end>\";\n+    public final static String IO_HEAD = \"[IO] \";\n+\n+    private static final Logger logger = Logger.getLogger(Rsession.class);\n+    public static RServeConnectionFactory rserveConnectionFactory;\n+    public boolean TRY_MODE_DEFAULT = false;\n+    public boolean TRY_MODE = false;\n+    public RConnection connection;\n+    public boolean connected = false;\n+    public String name;\n+    public RServeConf conf;\n+\n+    public String status = STATUS_NOT_SET;\n+    boolean tryLocalRServe;\n+\n+    private String outputFile;\n+\n+    /**\n+     * create rsession using System as a logger\n+     */\n+    protected Rsession(String name, RServeConf conf) {\n+        this.name = name;\n+        this.conf = conf;\n+        RServeConnectionFactory.initializeOnce(conf);\n+        begin();\n+    }\n+\n+\n+    /**\n+     * Build a new Rsession, connects to an existing server or fork a new one.\n+     *\n+     * @param conf config of RServe\n+     *             port, login, password, rProperties to pass to R (eg http_proxy)\n+     */\n+    public static Rsession newInstanceTry(String name, RServeConf conf) {\n+        return new Rsession(name, conf);\n+    }\n+\n+    /**\n+     * @return status of Rsession\n+     */\n+    public String getStatus() {\n+        return status;\n+    }\n+\n+    void begin() {\n+        status = STATUS_NOT_CONNECTED;\n+\n+        status = STATUS_CONNECTING;\n+\n+        connection = rserveConnectionFactory.connect();\n+        connected = (connection != null);\n+\n+        if (!connected) {\n+            status = STATUS_ERROR;\n+            String message = \"[\" + name + \"]\" + \"Rserve \" + conf + \" is not accessible.\";\n+            logger.error(message);\n+        } else if (connection.getServerVersion() < MinRserveVersion) {\n+            status = STATUS_ERROR;\n+            String message = \"[\" + name + \"]\" + \"Rserve \" + conf + \" version is too old.\";\n+            logger.error(message);\n+        } else {\n+            status = STATUS_READY;\n+            return;\n+        }\n+\n+        if (!connected) {//failed !\n+\n+            String message2 = \"[\" + name + \"]\" + \"Failed to connect to local Rserve. Unable to initialize Rsession.\";\n+            logger.error(message2);\n+            throw new IllegalArgumentException(message2);\n+        } else {\n+            logger.info(\"[\" + name + \"]\" + \"Connected to Local Rserve. (Version \" + connection.getServerVersion() + \")\");\n+        }\n+    }\n+\n+    /**\n+     * correctly (depending on execution platform) shutdown Rsession.\n+     */\n+    public void end() {\n+        if (connection == null) {","path":"pa-rserve/src/main/java/org/ow2/parserve/util/rsession/Rsession.java","position":108,"original_position":108,"commit_id":"734e66a6b63456135b711796a316c42acb1ee16a","original_commit_id":"734e66a6b63456135b711796a316c42acb1ee16a","user":{"login":"fviale","id":3063713,"avatar_url":"https://avatars.githubusercontent.com/u/3063713?v=3","gravatar_id":"","url":"https://api.github.com/users/fviale","html_url":"https://github.com/fviale","followers_url":"https://api.github.com/users/fviale/followers","following_url":"https://api.github.com/users/fviale/following{/other_user}","gists_url":"https://api.github.com/users/fviale/gists{/gist_id}","starred_url":"https://api.github.com/users/fviale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fviale/subscriptions","organizations_url":"https://api.github.com/users/fviale/orgs","repos_url":"https://api.github.com/users/fviale/repos","events_url":"https://api.github.com/users/fviale/events{/privacy}","received_events_url":"https://api.github.com/users/fviale/received_events","type":"User","site_admin":false},"body":"This method is called only inside the Rsession constructor. Accordingly, as connection is an instance variable, I don't see how two threads could compete here.","created_at":"2015-11-04T13:14:05Z","updated_at":"2015-11-04T13:14:05Z","html_url":"https://github.com/ow2-proactive/connector-r/pull/76#discussion_r43878294","pull_request_url":"https://api.github.com/repos/ow2-proactive/connector-r/pulls/76","_links":{"self":{"href":"https://api.github.com/repos/ow2-proactive/connector-r/pulls/comments/43878294"},"html":{"href":"https://github.com/ow2-proactive/connector-r/pull/76#discussion_r43878294"},"pull_request":{"href":"https://api.github.com/repos/ow2-proactive/connector-r/pulls/76"}}},"pull_request":{"url":"https://api.github.com/repos/ow2-proactive/connector-r/pulls/76","id":49461231,"html_url":"https://github.com/ow2-proactive/connector-r/pull/76","diff_url":"https://github.com/ow2-proactive/connector-r/pull/76.diff","patch_url":"https://github.com/ow2-proactive/connector-r/pull/76.patch","issue_url":"https://api.github.com/repos/ow2-proactive/connector-r/issues/76","number":76,"state":"open","locked":false,"title":"Add Rserve support in connector-r project","user":{"login":"fviale","id":3063713,"avatar_url":"https://avatars.githubusercontent.com/u/3063713?v=3","gravatar_id":"","url":"https://api.github.com/users/fviale","html_url":"https://github.com/fviale","followers_url":"https://api.github.com/users/fviale/followers","following_url":"https://api.github.com/users/fviale/following{/other_user}","gists_url":"https://api.github.com/users/fviale/gists{/gist_id}","starred_url":"https://api.github.com/users/fviale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fviale/subscriptions","organizations_url":"https://api.github.com/users/fviale/orgs","repos_url":"https://api.github.com/users/fviale/repos","events_url":"https://api.github.com/users/fviale/events{/privacy}","received_events_url":"https://api.github.com/users/fviale/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-11-02T17:34:41Z","updated_at":"2015-11-04T13:14:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"66d4b20fd7857ec7ef4152609edf7ae834149f94","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ow2-proactive/connector-r/pulls/76/commits","review_comments_url":"https://api.github.com/repos/ow2-proactive/connector-r/pulls/76/comments","review_comment_url":"https://api.github.com/repos/ow2-proactive/connector-r/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ow2-proactive/connector-r/issues/76/comments","statuses_url":"https://api.github.com/repos/ow2-proactive/connector-r/statuses/734e66a6b63456135b711796a316c42acb1ee16a","head":{"label":"fviale:master","ref":"master","sha":"734e66a6b63456135b711796a316c42acb1ee16a","user":{"login":"fviale","id":3063713,"avatar_url":"https://avatars.githubusercontent.com/u/3063713?v=3","gravatar_id":"","url":"https://api.github.com/users/fviale","html_url":"https://github.com/fviale","followers_url":"https://api.github.com/users/fviale/followers","following_url":"https://api.github.com/users/fviale/following{/other_user}","gists_url":"https://api.github.com/users/fviale/gists{/gist_id}","starred_url":"https://api.github.com/users/fviale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fviale/subscriptions","organizations_url":"https://api.github.com/users/fviale/orgs","repos_url":"https://api.github.com/users/fviale/repos","events_url":"https://api.github.com/users/fviale/events{/privacy}","received_events_url":"https://api.github.com/users/fviale/received_events","type":"User","site_admin":false},"repo":{"id":42522186,"name":"connector-r","full_name":"fviale/connector-r","owner":{"login":"fviale","id":3063713,"avatar_url":"https://avatars.githubusercontent.com/u/3063713?v=3","gravatar_id":"","url":"https://api.github.com/users/fviale","html_url":"https://github.com/fviale","followers_url":"https://api.github.com/users/fviale/followers","following_url":"https://api.github.com/users/fviale/following{/other_user}","gists_url":"https://api.github.com/users/fviale/gists{/gist_id}","starred_url":"https://api.github.com/users/fviale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fviale/subscriptions","organizations_url":"https://api.github.com/users/fviale/orgs","repos_url":"https://api.github.com/users/fviale/repos","events_url":"https://api.github.com/users/fviale/events{/privacy}","received_events_url":"https://api.github.com/users/fviale/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/fviale/connector-r","description":"ProActive connector for R","fork":true,"url":"https://api.github.com/repos/fviale/connector-r","forks_url":"https://api.github.com/repos/fviale/connector-r/forks","keys_url":"https://api.github.com/repos/fviale/connector-r/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fviale/connector-r/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fviale/connector-r/teams","hooks_url":"https://api.github.com/repos/fviale/connector-r/hooks","issue_events_url":"https://api.github.com/repos/fviale/connector-r/issues/events{/number}","events_url":"https://api.github.com/repos/fviale/connector-r/events","assignees_url":"https://api.github.com/repos/fviale/connector-r/assignees{/user}","branches_url":"https://api.github.com/repos/fviale/connector-r/branches{/branch}","tags_url":"https://api.github.com/repos/fviale/connector-r/tags","blobs_url":"https://api.github.com/repos/fviale/connector-r/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fviale/connector-r/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fviale/connector-r/git/refs{/sha}","trees_url":"https://api.github.com/repos/fviale/connector-r/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fviale/connector-r/statuses/{sha}","languages_url":"https://api.github.com/repos/fviale/connector-r/languages","stargazers_url":"https://api.github.com/repos/fviale/connector-r/stargazers","contributors_url":"https://api.github.com/repos/fviale/connector-r/contributors","subscribers_url":"https://api.github.com/repos/fviale/connector-r/subscribers","subscription_url":"https://api.github.com/repos/fviale/connector-r/subscription","commits_url":"https://api.github.com/repos/fviale/connector-r/commits{/sha}","git_commits_url":"https://api.github.com/repos/fviale/connector-r/git/commits{/sha}","comments_url":"https://api.github.com/repos/fviale/connector-r/comments{/number}","issue_comment_url":"https://api.github.com/repos/fviale/connector-r/issues/comments{/number}","contents_url":"https://api.github.com/repos/fviale/connector-r/contents/{+path}","compare_url":"https://api.github.com/repos/fviale/connector-r/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fviale/connector-r/merges","archive_url":"https://api.github.com/repos/fviale/connector-r/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fviale/connector-r/downloads","issues_url":"https://api.github.com/repos/fviale/connector-r/issues{/number}","pulls_url":"https://api.github.com/repos/fviale/connector-r/pulls{/number}","milestones_url":"https://api.github.com/repos/fviale/connector-r/milestones{/number}","notifications_url":"https://api.github.com/repos/fviale/connector-r/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fviale/connector-r/labels{/name}","releases_url":"https://api.github.com/repos/fviale/connector-r/releases{/id}","created_at":"2015-09-15T13:47:45Z","updated_at":"2015-11-02T17:32:17Z","pushed_at":"2015-11-02T17:36:40Z","git_url":"git://github.com/fviale/connector-r.git","ssh_url":"git@github.com:fviale/connector-r.git","clone_url":"https://github.com/fviale/connector-r.git","svn_url":"https://github.com/fviale/connector-r","homepage":"http://proactive.activeeon.com/","size":14092,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ow2-proactive:master","ref":"master","sha":"1e0a21221e24955f70b58ee766fc9d7f15e999de","user":{"login":"ow2-proactive","id":11553998,"avatar_url":"https://avatars.githubusercontent.com/u/11553998?v=3","gravatar_id":"","url":"https://api.github.com/users/ow2-proactive","html_url":"https://github.com/ow2-proactive","followers_url":"https://api.github.com/users/ow2-proactive/followers","following_url":"https://api.github.com/users/ow2-proactive/following{/other_user}","gists_url":"https://api.github.com/users/ow2-proactive/gists{/gist_id}","starred_url":"https://api.github.com/users/ow2-proactive/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ow2-proactive/subscriptions","organizations_url":"https://api.github.com/users/ow2-proactive/orgs","repos_url":"https://api.github.com/users/ow2-proactive/repos","events_url":"https://api.github.com/users/ow2-proactive/events{/privacy}","received_events_url":"https://api.github.com/users/ow2-proactive/received_events","type":"Organization","site_admin":false},"repo":{"id":35725082,"name":"connector-r","full_name":"ow2-proactive/connector-r","owner":{"login":"ow2-proactive","id":11553998,"avatar_url":"https://avatars.githubusercontent.com/u/11553998?v=3","gravatar_id":"","url":"https://api.github.com/users/ow2-proactive","html_url":"https://github.com/ow2-proactive","followers_url":"https://api.github.com/users/ow2-proactive/followers","following_url":"https://api.github.com/users/ow2-proactive/following{/other_user}","gists_url":"https://api.github.com/users/ow2-proactive/gists{/gist_id}","starred_url":"https://api.github.com/users/ow2-proactive/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ow2-proactive/subscriptions","organizations_url":"https://api.github.com/users/ow2-proactive/orgs","repos_url":"https://api.github.com/users/ow2-proactive/repos","events_url":"https://api.github.com/users/ow2-proactive/events{/privacy}","received_events_url":"https://api.github.com/users/ow2-proactive/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ow2-proactive/connector-r","description":"ProActive connector for R","fork":false,"url":"https://api.github.com/repos/ow2-proactive/connector-r","forks_url":"https://api.github.com/repos/ow2-proactive/connector-r/forks","keys_url":"https://api.github.com/repos/ow2-proactive/connector-r/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ow2-proactive/connector-r/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ow2-proactive/connector-r/teams","hooks_url":"https://api.github.com/repos/ow2-proactive/connector-r/hooks","issue_events_url":"https://api.github.com/repos/ow2-proactive/connector-r/issues/events{/number}","events_url":"https://api.github.com/repos/ow2-proactive/connector-r/events","assignees_url":"https://api.github.com/repos/ow2-proactive/connector-r/assignees{/user}","branches_url":"https://api.github.com/repos/ow2-proactive/connector-r/branches{/branch}","tags_url":"https://api.github.com/repos/ow2-proactive/connector-r/tags","blobs_url":"https://api.github.com/repos/ow2-proactive/connector-r/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ow2-proactive/connector-r/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ow2-proactive/connector-r/git/refs{/sha}","trees_url":"https://api.github.com/repos/ow2-proactive/connector-r/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ow2-proactive/connector-r/statuses/{sha}","languages_url":"https://api.github.com/repos/ow2-proactive/connector-r/languages","stargazers_url":"https://api.github.com/repos/ow2-proactive/connector-r/stargazers","contributors_url":"https://api.github.com/repos/ow2-proactive/connector-r/contributors","subscribers_url":"https://api.github.com/repos/ow2-proactive/connector-r/subscribers","subscription_url":"https://api.github.com/repos/ow2-proactive/connector-r/subscription","commits_url":"https://api.github.com/repos/ow2-proactive/connector-r/commits{/sha}","git_commits_url":"https://api.github.com/repos/ow2-proactive/connector-r/git/commits{/sha}","comments_url":"https://api.github.com/repos/ow2-proactive/connector-r/comments{/number}","issue_comment_url":"https://api.github.com/repos/ow2-proactive/connector-r/issues/comments{/number}","contents_url":"https://api.github.com/repos/ow2-proactive/connector-r/contents/{+path}","compare_url":"https://api.github.com/repos/ow2-proactive/connector-r/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ow2-proactive/connector-r/merges","archive_url":"https://api.github.com/repos/ow2-proactive/connector-r/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ow2-proactive/connector-r/downloads","issues_url":"https://api.github.com/repos/ow2-proactive/connector-r/issues{/number}","pulls_url":"https://api.github.com/repos/ow2-proactive/connector-r/pulls{/number}","milestones_url":"https://api.github.com/repos/ow2-proactive/connector-r/milestones{/number}","notifications_url":"https://api.github.com/repos/ow2-proactive/connector-r/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ow2-proactive/connector-r/labels{/name}","releases_url":"https://api.github.com/repos/ow2-proactive/connector-r/releases{/id}","created_at":"2015-05-16T13:38:56Z","updated_at":"2015-06-12T14:54:57Z","pushed_at":"2015-11-02T17:36:41Z","git_url":"git://github.com/ow2-proactive/connector-r.git","ssh_url":"git@github.com:ow2-proactive/connector-r.git","clone_url":"https://github.com/ow2-proactive/connector-r.git","svn_url":"https://github.com/ow2-proactive/connector-r","homepage":"http://proactive.activeeon.com/","size":14105,"stargazers_count":0,"watchers_count":0,"language":"R","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":32,"forks":3,"open_issues":32,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ow2-proactive/connector-r/pulls/76"},"html":{"href":"https://github.com/ow2-proactive/connector-r/pull/76"},"issue":{"href":"https://api.github.com/repos/ow2-proactive/connector-r/issues/76"},"comments":{"href":"https://api.github.com/repos/ow2-proactive/connector-r/issues/76/comments"},"review_comments":{"href":"https://api.github.com/repos/ow2-proactive/connector-r/pulls/76/comments"},"review_comment":{"href":"https://api.github.com/repos/ow2-proactive/connector-r/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ow2-proactive/connector-r/pulls/76/commits"},"statuses":{"href":"https://api.github.com/repos/ow2-proactive/connector-r/statuses/734e66a6b63456135b711796a316c42acb1ee16a"}}}}