Can I run any script while starting server?

50 views
Skip to first unread message

Eugeny Kozhanov

unread,
Oct 15, 2012, 3:48:21 AM10/15/12
to ne...@googlegroups.com
Can I run any script while starting server? or immediately after the started server?
TIA.
Eugeny.

Peter Neubauer

unread,
Oct 16, 2012, 9:40:04 AM10/16/12
to ne...@googlegroups.com
Mmh,
that depends on what your architecture is? What are you trying to do?

Cheers,

/peter neubauer

G: neubauer.peter
S: peter.neubauer
P: +46 704 106975
L: http://www.linkedin.com/in/neubauer
T: @peterneubauer

Neo4j 1.8 GA - http://www.dzone.com/links/neo4j_18_release_fluent_graph_literacy.html
> --
>
>

Eugeny Kozhanov

unread,
Oct 17, 2012, 12:19:07 AM10/17/12
to ne...@googlegroups.com
I want to start my warmup script while starting server (for example, in my plugin).

Peter Neubauer

unread,
Oct 17, 2012, 5:38:43 AM10/17/12
to ne...@googlegroups.com
Mmh,
I don't think there is any explicit lifecycle detection, I think the
easiest way is to expose the endpoint, and call it from outside after
server startup and before you do the regular workload?

Cheers,

/peter neubauer

G: neubauer.peter
S: peter.neubauer
P: +46 704 106975
L: http://www.linkedin.com/in/neubauer
T: @peterneubauer

Neo4j 1.8 GA - http://www.dzone.com/links/neo4j_18_release_fluent_graph_literacy.html


> --
>
>

Michael Hunger

unread,
Oct 20, 2012, 8:57:13 PM10/20/12
to ne...@googlegroups.com
If it is for Neo4j server, look into the PluginInitializer SPI that we discussed here:

Perhaps with a plugin lifecycle.

Michael
> --
>
>

Eugeny Kozhanov

unread,
Oct 22, 2012, 3:40:20 AM10/22/12
to ne...@googlegroups.com
Can you send me small example? TIA.

Michael Hunger

unread,
Oct 22, 2012, 4:42:42 AM10/22/12
to ne...@googlegroups.com
--
 
 

Eugeny Kozhanov

unread,
Nov 8, 2012, 1:04:44 AM11/8/12
to ne...@googlegroups.com
 in neo4j-server.properties I wrote:

org.neo4j.server.thirdparty_jaxrs_classes=ru.myCompany.neo4j.auto=/auto_warmup/warmup

And my class like as:

package ru.myCompany.neo4j.auto;

import org.neo4j.graphdb.*;
import org.neo4j.tooling.GlobalGraphOperations;

import java.util.Iterator;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.Produces;

@Path( "/auto_warmup" )
public class autoWarmUp {
   private final GraphDatabaseService graphDb;

   public autoWarmUp(final GraphDatabaseService gdb) {
    graphDb = gdb;
   }

   @GET
   @Produces( MediaType.TEXT_PLAIN )
   @Path( "/warmup" )
   public Response warmup()
   {
GlobalGraphOperations gg = GlobalGraphOperations.at(graphDb);
Iterator<Node> iter = gg.getAllNodes().iterator();
Node node;
int relCount = 0;
int nCount = 0;
while ( iter.hasNext() ) {
node = iter.next();
nCount++;
for ( Relationship rel: node.getRelationships() ) {
if ( rel.hasProperty("type") ) {
relCount++;
}
}
}
       return Response.status( Status.OK ).entity(
        ( "WARM UP: " + nCount + " nodes and " + relCount + " relationships." ).getBytes() ).build();
   }
}

Can I run this script automatically on starting server?
Reply all
Reply to author
Forward
0 new messages