Skip to content

Commit

Permalink
Use a static FramedGraphFactory, which prevents a PermGen leak
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesname committed Nov 2, 2013
1 parent 28f1e80 commit d4239c1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public abstract class AbstractRestResource implements TxCheckedResource {
private static final ObjectMapper mapper = new ObjectMapper();

private static final Logger logger = LoggerFactory.getLogger(TxCheckedResource.class);
private static final FramedGraphFactory graphFactory = new FramedGraphFactory(new JavaHandlerModule());

/**
* Query arguments.
Expand Down Expand Up @@ -101,8 +102,7 @@ protected MediaType checkMediaType() {

public AbstractRestResource(@Context GraphDatabaseService database) {
this.database = database;
graph = new FramedGraphFactory(
new JavaHandlerModule()).create(new TxCheckedNeo4jGraph(database));
graph = graphFactory.create(new TxCheckedNeo4jGraph(database));
manager = GraphManagerFactory.getInstance(graph);
serializer = new Serializer.Builder(graph).build();
}
Expand Down Expand Up @@ -451,4 +451,4 @@ protected String getRepresentation(Frame frame) throws SerializationError {
? serializer.vertexFrameToXmlString(frame)
: serializer.vertexFrameToJson(frame);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@
*/
public class ServerRunner extends WrappingNeoServerBootstrapper {

private static final FramedGraphFactory graphFactory = new FramedGraphFactory(new JavaHandlerModule());

protected final FixtureLoader loader;
protected final GraphCleaner cleaner;
private FramedGraph<Neo4jGraph> framedGraph;
private boolean isRunning = false;

public ServerRunner(GraphDatabaseAPI graphDatabase, ServerConfigurator config) {
super(graphDatabase, config);
framedGraph = new FramedGraphFactory(
new JavaHandlerModule()).create((new Neo4jGraph(graphDatabase)));
framedGraph = graphFactory.create((new Neo4jGraph(graphDatabase)));
loader = FixtureLoaderFactory.getInstance(framedGraph);
cleaner = new GraphCleaner(framedGraph);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class YamlFixtureLoader implements FixtureLoader {

public static final String GENERATE_ID_PLACEHOLDER = "?";

private static final FramedGraphFactory graphFactory = new FramedGraphFactory(new JavaHandlerModule());
private final FramedGraph<? extends TransactionalGraph> graph;
private final GraphManager manager;
private static final Logger logger = LoggerFactory
Expand Down Expand Up @@ -331,8 +332,7 @@ public static void main(String[] args) {
.newEmbeddedDatabase(args[0]);
registerShutdownHook(db);
try {
FramedGraph<? extends TransactionalGraph> graph = new FramedGraphFactory(
new JavaHandlerModule()).create(
FramedGraph<? extends TransactionalGraph> graph = graphFactory.create(
new Neo4jGraph(db));
YamlFixtureLoader loader = new YamlFixtureLoader(graph);
loader.loadTestData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
*/
public abstract class GraphTestBase {

private static final FramedGraphFactory graphFactory = new FramedGraphFactory(new JavaHandlerModule());

protected FramedGraph<? extends TransactionalGraph> graph;
protected GraphManager manager;

@Before
public void setUp() throws Exception {

graph = new FramedGraphFactory(
new JavaHandlerModule()).create(new Neo4jGraph(
graph = graphFactory.create(new Neo4jGraph(
new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder()
.newGraphDatabase()));
manager = GraphManagerFactory.getInstance(graph);
Expand Down

0 comments on commit d4239c1

Please sign in to comment.