Search in sources :

Example 1 with RmiLocation

use of org.neo4j.shell.impl.RmiLocation in project neo4j by neo4j.

the class LegacyDatabaseImpl method start.

public static Future<LegacyDatabase> start(String classpath, File storeDir, Map<String, String> config) throws Exception {
    List<String> args = new ArrayList<String>();
    args.add(storeDir.getAbsolutePath());
    int rmiPort = 7000 + parseInt(config.get("ha.server_id"));
    args.add("" + rmiPort);
    args.addAll(asList(new Args(config).asArgs()));
    final Process process = execJava(appendNecessaryTestClasses(classpath), LegacyDatabaseImpl.class.getName(), args.toArray(new String[0]));
    new ProcessStreamHandler(process, false).launch();
    final RmiLocation rmiLocation = rmiLocation(rmiPort);
    ExecutorService executor = newSingleThreadExecutor();
    Future<LegacyDatabase> future = executor.submit(new Callable<LegacyDatabase>() {

        @Override
        public LegacyDatabase call() throws Exception {
            long endTime = currentTimeMillis() + SECONDS.toMillis(10000);
            while (currentTimeMillis() < endTime) {
                try {
                    return (LegacyDatabase) rmiLocation.getBoundObject();
                } catch (RemoteException e) {
                    // OK
                    sleep(100);
                }
            }
            process.destroy();
            throw new IllegalStateException("Couldn't get remote to legacy database");
        }
    });
    executor.shutdown();
    return future;
}
Also used : Args(org.neo4j.helpers.Args) RmiLocation(org.neo4j.shell.impl.RmiLocation) ArrayList(java.util.ArrayList) Exceptions.launderedException(org.neo4j.helpers.Exceptions.launderedException) RemoteException(java.rmi.RemoteException) ExecutorService(java.util.concurrent.ExecutorService) ProcessStreamHandler(org.neo4j.test.ProcessStreamHandler) RemoteException(java.rmi.RemoteException)

Aggregations

RemoteException (java.rmi.RemoteException)1 ArrayList (java.util.ArrayList)1 ExecutorService (java.util.concurrent.ExecutorService)1 Args (org.neo4j.helpers.Args)1 Exceptions.launderedException (org.neo4j.helpers.Exceptions.launderedException)1 RmiLocation (org.neo4j.shell.impl.RmiLocation)1 ProcessStreamHandler (org.neo4j.test.ProcessStreamHandler)1