Re: [Neo4j] Multiple users on a embedded graphdb

2011-05-11 Thread Michael Hunger
No problem at all. As tx are bound to the executing thread. And the singleton 
graph-db instance is the way to go.

Good Luck with your efforts

Michael


Am 11.05.2011 um 17:04 schrieb John Doran:

> Thanks Micheal,
> Good points, I have 3 weeks to finish up(along with a mountain of other
> things to do so I can't see the server as and option, I'm really looking for
> a quick work around because of time limitations. I actually helped Rene get
> stated with combining the two, I have the two working well together. Apart
> from the problem I have now of distributions. Could a workaround be to have
> a singleton instance of the db when clients are performing queries run from
> this instance, or would there be transactional problems?
> Regards, John.
> ___
> Neo4j mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user

___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Multiple users on a embedded graphdb

2011-05-11 Thread John Doran
Thanks Micheal,
Good points, I have 3 weeks to finish up(along with a mountain of other
things to do so I can't see the server as and option, I'm really looking for
a quick work around because of time limitations. I actually helped Rene get
stated with combining the two, I have the two working well together. Apart
from the problem I have now of distributions. Could a workaround be to have
a singleton instance of the db when clients are performing queries run from
this instance, or would there be transactional problems?
Regards, John.
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Multiple users on a embedded graphdb

2011-05-11 Thread Michael Hunger
John,

as the exception says and Marko said before you can only have one embedded 
graph db instance.

Accessing the db from the outside needs a protocol that allows the client to 
talk to the db.

Either you go with the Neo4j-Server and use the provided graph-algorithms or 
write your own Server Plugin that does that. Then your GWT clients can access 
that remotely.

But it is perhaps more sensible to rely on GWT's remoting protocol and just 
expose a Service in the Server that allows clients to call the graph algo 
methods. The Service should then instantiated (guice?) as a singleton keeping 
the single graph db.

There is a recent screencast by René Pickhardt on how to integrate neo4j and gwt
http://www.rene-pickhardt.de/how-to-combine-neo4j-with-gwt-and-eclipse

Perhaps this helps you to solve your problems.

P.S. Even with custom thread handling you should create the Graph-Database 
upfront and pass it by reference to the threads which can then access it 
concurrently. For remote clients you would do ServerSocket.listen and ~.accept 
and spawn (or re-use and even better a ThreadPool) a new thread for handling 
the client request. But writing your own socket layer is definitively overkill.

Cheers

Michael

Am 11.05.2011 um 15:36 schrieb John Doran:

> Hi all,
> Thanks for the help with the multiple user on the embedded problem, I'm
> still getting the exception(I am a little rusty at working with threads). So
> I run the tread when wanting to work with the db and then in a do/while
> statement check if complete(if so yield). But when a second user tries to
> access from another browser/computer I get the dreaded exception(see below).
> Any suggestions/workarounds would be great! Or an example of where people
> have used threads in interacting with neo4j.
> Regards,
> John.
> 
> RPC server side code:
> processAStar = new ProcessAStarAlgorithm(latitude1, longitude1, latitude2,
> longitude2, desiredDistance);
> boolean processing = true;
> Thread runner = new Thread(){
> public void run(){
> processAStar.configureSearch();//create the graph db and process
> calculations
> System.out.println("Running thread");
> }
> };
> runner.start();
> do {
> try {
> Thread.sleep(1000);
> System.out.println("Sleeping thread");
> if(processAStar.calculationComplete==true){
> System.out.println("Calculation complete in thread");
> sp = processAStar.getShortestPathRepresentation();
> processing = false;
> Thread.yield();
> }
> } catch (InterruptedException exc) {
> }
> } while (processing);
> return sp;
> 
> Exception:
> Exception in thread "Thread-21"
> org.neo4j.graphdb.TransactionFailureException: Could not create data source
> [nioneodb], see nested exception for cause of error
> at
> org.neo4j.kernel.impl.transaction.TxModule.registerDataSource(TxModule.java:154)
> at org.neo4j.kernel.GraphDbInstance.start(GraphDbInstance.java:107)
> at org.neo4j.kernel.EmbeddedGraphDbImpl.(EmbeddedGraphDbImpl.java:168)
> at
> org.neo4j.kernel.EmbeddedGraphDatabase.(EmbeddedGraphDatabase.java:81)
> at
> org.neo4j.kernel.EmbeddedGraphDatabase.(EmbeddedGraphDatabase.java:65)
> at
> com.routeplanner.fyp.pathfinder.ProcessAStarAlgorithm.getWaypointsClose(ProcessAStarAlgorithm.java:72)
> at
> com.routeplanner.fyp.pathfinder.ProcessAStarAlgorithm.configureSearch(ProcessAStarAlgorithm.java:307)
> at
> com.routeplanner.fyp.server.PlanRouteServiceImpl$1.run(PlanRouteServiceImpl.java:22)
> Caused by: java.lang.reflect.InvocationTargetException
> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
> at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
> at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
> at java.lang.reflect.Constructor.newInstance(Unknown Source)
> at
> org.neo4j.kernel.impl.transaction.XaDataSourceManager.create(XaDataSourceManager.java:74)
> at
> org.neo4j.kernel.impl.transaction.TxModule.registerDataSource(TxModule.java:148)
> ... 7 more
> Caused by: java.lang.IllegalStateException: Unable to lock store
> [C:\fyp_2.011\neo4j-db\neostore], this is usually caused by another Neo4j
> kernel already running in this JVM for this particular store
> at
> org.neo4j.kernel.impl.nioneo.store.CommonAbstractStore.checkStorage(CommonAbstractStore.java:266)
> at
> org.neo4j.kernel.impl.nioneo.store.CommonAbstractStore.(CommonAbstractStore.java:163)
> at
> org.neo4j.kernel.impl.nioneo.store.AbstractStore.(AbstractStore.java:120)
> at org.neo4j.kernel.impl.nioneo.store.NeoStore.(NeoStore.java:64)
> at
> org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource.(NeoStoreXaDataSource.java:128)
> ___
> Neo4j mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user

___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Multiple users on a embedded graphdb

2011-05-11 Thread John Doran
Hi all,
Thanks for the help with the multiple user on the embedded problem, I'm
still getting the exception(I am a little rusty at working with threads). So
I run the tread when wanting to work with the db and then in a do/while
statement check if complete(if so yield). But when a second user tries to
access from another browser/computer I get the dreaded exception(see below).
Any suggestions/workarounds would be great! Or an example of where people
have used threads in interacting with neo4j.
Regards,
John.

RPC server side code:
processAStar = new ProcessAStarAlgorithm(latitude1, longitude1, latitude2,
longitude2, desiredDistance);
boolean processing = true;
Thread runner = new Thread(){
public void run(){
processAStar.configureSearch();//create the graph db and process
calculations
System.out.println("Running thread");
}
};
runner.start();
do {
try {
Thread.sleep(1000);
System.out.println("Sleeping thread");
if(processAStar.calculationComplete==true){
System.out.println("Calculation complete in thread");
sp = processAStar.getShortestPathRepresentation();
processing = false;
Thread.yield();
}
} catch (InterruptedException exc) {
}
} while (processing);
return sp;

Exception:
Exception in thread "Thread-21"
org.neo4j.graphdb.TransactionFailureException: Could not create data source
[nioneodb], see nested exception for cause of error
at
org.neo4j.kernel.impl.transaction.TxModule.registerDataSource(TxModule.java:154)
at org.neo4j.kernel.GraphDbInstance.start(GraphDbInstance.java:107)
at org.neo4j.kernel.EmbeddedGraphDbImpl.(EmbeddedGraphDbImpl.java:168)
at
org.neo4j.kernel.EmbeddedGraphDatabase.(EmbeddedGraphDatabase.java:81)
at
org.neo4j.kernel.EmbeddedGraphDatabase.(EmbeddedGraphDatabase.java:65)
at
com.routeplanner.fyp.pathfinder.ProcessAStarAlgorithm.getWaypointsClose(ProcessAStarAlgorithm.java:72)
at
com.routeplanner.fyp.pathfinder.ProcessAStarAlgorithm.configureSearch(ProcessAStarAlgorithm.java:307)
at
com.routeplanner.fyp.server.PlanRouteServiceImpl$1.run(PlanRouteServiceImpl.java:22)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at
org.neo4j.kernel.impl.transaction.XaDataSourceManager.create(XaDataSourceManager.java:74)
at
org.neo4j.kernel.impl.transaction.TxModule.registerDataSource(TxModule.java:148)
... 7 more
Caused by: java.lang.IllegalStateException: Unable to lock store
[C:\fyp_2.011\neo4j-db\neostore], this is usually caused by another Neo4j
kernel already running in this JVM for this particular store
at
org.neo4j.kernel.impl.nioneo.store.CommonAbstractStore.checkStorage(CommonAbstractStore.java:266)
at
org.neo4j.kernel.impl.nioneo.store.CommonAbstractStore.(CommonAbstractStore.java:163)
at
org.neo4j.kernel.impl.nioneo.store.AbstractStore.(AbstractStore.java:120)
at org.neo4j.kernel.impl.nioneo.store.NeoStore.(NeoStore.java:64)
at
org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource.(NeoStoreXaDataSource.java:128)
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Multiple users on a embedded graphdb

2011-05-09 Thread Thomas Baum
hi john, 
imho the gwt is just a webapp. so i'm a bit confused why talking about threads 
in a j2ee env? 

if i understand you right you want to share one neo4j instance between 
different gwt apps(services).  i would propose creating a context-listener, on 
application startup the embedded-graph-db is placed in the servlet context.
(see the code-snippets)


a other approach would be accessing the neo4j-server direct from the gwt 
(javascript) code through the rest-api. this assumes a driver written in 
gwt-java/javascript.
@jim i hope to find the time this friday creating a lab-project this friday for 
this  :)


cheers
/thomas




// register in web.xml 
public class NeoContextListner implements ServletContextListener {
  private static final String CONTEXT_KEY = "neo4j-instance";

  public static EmbeddedGraphDatabase getNeo4JInstance(ServletContext 
servletContext) {
  return (EmbeddedGraphDatabase) servletContext.getAttribute(CONTEXT_KEY);
  }

  public void contextInitialized(ServletContextEvent servletContextEvent) {
  EmbeddedGraphDatabase db = new EmbeddedGraphDatabase("/tmp/db");
  ServletContext servletContext = servletContextEvent.getServletContext();
  servletContext.setAttribute(CONTEXT_KEY, db);
  }

  public void contextDestroyed(ServletContextEvent servletContextEvent) {
  ServletContext servletContext = servletContextEvent.getServletContext();
  EmbeddedGraphDatabase db = getNeo4JInstance(servletContext);
  db.shutdown();
  }
}

usage:

public class TestServiceImpl extends RemoteServiceServlet implements 
TestService {
 public AnyResult doIt(String argument) {
  EmbeddedGraphDatabase db = 
NeoContextListner.getNeo4JInstance(getServletContext());
 use it
  }

}


Am 09.05.2011 um 23:11 schrieb Christoph K.:

> Hi John,
> 
> if i unterstand Jim right, he means that you should fire up threads on the
> serverside implementation which handle client requests and deal with a
> single instance of the embeddedgraphdatabase.
> 
> greetings
> Chris
> 
> On Mon, May 9, 2011 at 11:06 PM, John Doran  wrote:
> 
>> Hi Jim,
>> Thanks for the reply, I haven't delved into the server aspect of neo4j(I'll
>> leave that until I finish up college). I'll have to refresh my threading
>> knowledge, you reckon each time users want to interact with the db to
>> create
>> a thread and this would stop any exceptions relating to not being able to
>> connect to the database(because it's in use).
>> Regards,
>> John.


___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Multiple users on a embedded graphdb

2011-05-09 Thread Christoph K.
Hi John,

if i unterstand Jim right, he means that you should fire up threads on the
serverside implementation which handle client requests and deal with a
single instance of the embeddedgraphdatabase.

greetings
Chris

On Mon, May 9, 2011 at 11:06 PM, John Doran  wrote:

> Hi Jim,
> Thanks for the reply, I haven't delved into the server aspect of neo4j(I'll
> leave that until I finish up college). I'll have to refresh my threading
> knowledge, you reckon each time users want to interact with the db to
> create
> a thread and this would stop any exceptions relating to not being able to
> connect to the database(because it's in use).
> Regards,
> John.
> ___
> Neo4j mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
>
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Multiple users on a embedded graphdb

2011-05-09 Thread Marko Rodriguez
Hey,

You can have multiple threads talking to the same DB reference. You can not 
create multiple graph database services over the same directory. Thus,

final graph = new GraphDatabaseService('/tmp/test')
for(int i=0;i<10;i++) {
new Thread {
public void run() {
   // do something to graph
}
  }.start()
}

But not:

graph = new GraphDatabaseSerice('/tmp/test');
graph = new GraphDatabaseService('/tmp/test');

Hope that helps,
Marko.

http://markorodriguez.com

On May 9, 2011, at 3:06 PM, John Doran wrote:

> Hi Jim,
> Thanks for the reply, I haven't delved into the server aspect of neo4j(I'll
> leave that until I finish up college). I'll have to refresh my threading
> knowledge, you reckon each time users want to interact with the db to create
> a thread and this would stop any exceptions relating to not being able to
> connect to the database(because it's in use).
> Regards,
> John.
> ___
> Neo4j mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user

___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Multiple users on a embedded graphdb

2011-05-09 Thread John Doran
Hi Jim,
Thanks for the reply, I haven't delved into the server aspect of neo4j(I'll
leave that until I finish up college). I'll have to refresh my threading
knowledge, you reckon each time users want to interact with the db to create
a thread and this would stop any exceptions relating to not being able to
connect to the database(because it's in use).
Regards,
John.
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] Multiple users on a embedded graphdb

2011-05-09 Thread Jim Webber
Hi John,

I think threads are your friend. Or you could use our REST API (depending on 
your requirements) where threads are our friends inside the Neo4j server.

Jim
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


[Neo4j] Multiple users on a embedded graphdb

2011-05-09 Thread John Doran
Hi all,
Have been using my project in test mode(by myself) and have just came up
with a problem. My app through GWT is client server, so if a second client
wants to calculate a shortest path(using the embedded graphdb) they cannot
connect to my db because its in use by another client, any suggestions? I
was thinking some kind of threading solution?
Regards,
John.
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user