Changeset View
Changeset View
Standalone View
Standalone View
java/src/main/java/org/softwareheritage/graph/server/App.java
package org.softwareheritage.graph.server; | package org.softwareheritage.graph.server; | ||||
import com.fasterxml.jackson.databind.ObjectMapper; | import com.fasterxml.jackson.databind.ObjectMapper; | ||||
import com.fasterxml.jackson.databind.PropertyNamingStrategy; | import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||||
import com.martiansoftware.jsap.*; | import com.martiansoftware.jsap.*; | ||||
import io.javalin.Javalin; | import io.javalin.Javalin; | ||||
import io.javalin.http.Context; | import io.javalin.http.Context; | ||||
import io.javalin.plugin.json.JavalinJackson; | import io.javalin.plugin.json.JavalinJackson; | ||||
import org.softwareheritage.graph.Graph; | import org.softwareheritage.graph.SwhBidirectionalGraph; | ||||
import org.softwareheritage.graph.Stats; | import org.softwareheritage.graph.Stats; | ||||
import org.softwareheritage.graph.SWHID; | import org.softwareheritage.graph.SWHID; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | import java.util.Map; | ||||
/** | /** | ||||
Show All 33 Lines | public class App { | ||||
/** | /** | ||||
* Loads compressed graph and starts the web server to query it. | * Loads compressed graph and starts the web server to query it. | ||||
* | * | ||||
* @param graphPath basename of the compressed graph | * @param graphPath basename of the compressed graph | ||||
* @param port binding port of the server | * @param port binding port of the server | ||||
* @param showTimings true if timings should be in results metadata, false otherwise | * @param showTimings true if timings should be in results metadata, false otherwise | ||||
*/ | */ | ||||
private static void startServer(String graphPath, int port, boolean showTimings) throws IOException { | private static void startServer(String graphPath, int port, boolean showTimings) throws IOException { | ||||
Graph graph = Graph.loadMapped(graphPath); | SwhBidirectionalGraph graph = SwhBidirectionalGraph.loadMapped(graphPath); | ||||
Stats stats = new Stats(graphPath); | Stats stats = new Stats(graphPath); | ||||
// Clean up on exit | // Clean up on exit | ||||
Runtime.getRuntime().addShutdownHook(new Thread() { | Runtime.getRuntime().addShutdownHook(new Thread() { | ||||
public void run() { | public void run() { | ||||
try { | try { | ||||
graph.cleanUp(); | graph.close(); | ||||
} catch (IOException e) { | } catch (IOException e) { | ||||
System.out.println("Could not clean up graph on exit: " + e); | System.out.println("Could not clean up graph on exit: " + e); | ||||
} | } | ||||
} | } | ||||
}); | }); | ||||
// Configure Jackson JSON to use snake case naming style | // Configure Jackson JSON to use snake case naming style | ||||
ObjectMapper objectMapper = JavalinJackson.getObjectMapper(); | ObjectMapper objectMapper = JavalinJackson.getObjectMapper(); | ||||
▲ Show 20 Lines • Show All 122 Lines • Show Last 20 Lines |