Skip to content

Commit

Permalink
Upgrading Apache HttpClient from 4.0.1 to 4.1.1 eliminated the expect…
Browse files Browse the repository at this point in the history
…-continue handshake which was causing script eval requests to take very much longer than they needed to. Jig is much snappier now.
  • Loading branch information
joshsh committed May 14, 2011
1 parent 67c2149 commit 7fd03a7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.0.1</version>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/tinkerpop/jig/JigConsole.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -103,11 +104,16 @@ private boolean tryLine(final String line) throws ScriptException, JSONException
}

private boolean executeScript(final String script) throws ScriptException, JSONException {
//long before = new Date().getTime();

System.out.println("");
Object result = scriptEngine.eval(script.trim());
showResult(result);
System.out.println("");

//long after = new Date().getTime();
//System.out.println("[script took " + (after - before) + "ms]");

// TODO: provide a "quit" command
return true;
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/tinkerpop/jig/JigScriptEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.Writer;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.LinkedList;

/**
Expand Down Expand Up @@ -237,7 +238,10 @@ private Object issueRequest(final String script) throws IOException, JSONExcepti
String auth = new String(Base64.encodeBase64((userName + ":" + password).getBytes()));
request.setHeader("Authorization", "Basic " + auth);

//long before = new Date().getTime();
HttpResponse response = client.execute(request);
long after = new Date().getTime();
//System.out.println("[request took " + (after - before) + "ms]");
int responseCode = response.getStatusLine().getStatusCode();

ByteArrayOutputStream bos = new ByteArrayOutputStream();
Expand Down
36 changes: 36 additions & 0 deletions src/main/javascript/jans.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Name of the triple store
store.name

// Number of triples in the store
store.size

// Look at a few triples
g.triples.limit(10)

// Labels (predicates) only
g.triples.limit(10).label

// Find more labels
g.triples.limit(100000).label.distinct

// Pick out a single label (rdf:type in this case)
type = g.triples.limit(100000).label.distinct[6]

// Find distinct types
g.triples(null, type, null).head.limit(100000).distinct

// Let's look at the "drugs" type
drugs = g.triples(null, type, null).head.limit(100000).distinct[1]

// Here are some instances of "drugs"
d = g.v(drugs).inE(type).limit(10).tail

// Pick a drug at random, find its neighborhood as a ranked list
d0 = g.v(d[0]).nearby(2).aggr

// Do the same for another node
d9 = g.v(d[9]).nearby(2).aggr

// Find the intersection (entry-wise product) of the two neighborhoods.
// These are nodes "nearby" to both nodes in the graph
intersect(d0, d9)

0 comments on commit 7fd03a7

Please sign in to comment.