X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=server%2Fruntime%2Forg.argeo.server.jackrabbit%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fjackrabbit%2FJackrabbitContainer.java;h=a708aadd1d67a6eada7401b8bcf94d3cf95ff8ad;hb=a171094436482fa16e8da47d5501df59ec06e595;hp=d9cf424e63e7155f433b034e2c10d2d5352ad25c;hpb=231507d4e7c8aa9676fd65bcd13d4558f78ff86f;p=lgpl%2Fargeo-commons.git diff --git a/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/JackrabbitContainer.java b/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/JackrabbitContainer.java index d9cf424e6..a708aadd1 100644 --- a/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/JackrabbitContainer.java +++ b/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/JackrabbitContainer.java @@ -30,6 +30,7 @@ import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.TreeSet; +import java.util.UUID; import java.util.concurrent.Executor; import javax.jcr.Credentials; @@ -115,6 +116,7 @@ public class JackrabbitContainer implements Repository, ResourceLoaderAware { /** Actually creates a new repository. */ protected void createJackrabbitRepository() { + long begin = System.currentTimeMillis(); try { // remote repository if (uri != null && !uri.trim().equals("")) { @@ -122,7 +124,7 @@ public class JackrabbitContainer implements Repository, ResourceLoaderAware { params.put( org.apache.jackrabbit.commons.JcrUtils.REPOSITORY_URI, uri); - repository = (JackrabbitRepository) new Jcr2davRepositoryFactory() + repository = new Jcr2davRepositoryFactory() .getRepository(params); if (repository == null) throw new ArgeoException("Remote Davex repository " + uri @@ -161,8 +163,10 @@ public class JackrabbitContainer implements Repository, ResourceLoaderAware { else repository = RepositoryImpl.create(repositoryConfig); - log.info("Initialized Jackrabbit repository " + repository + " in " - + getHomeDirectory() + " with config " + configuration); + double duration = ((double) (System.currentTimeMillis() - begin)) / 1000; + log.info("Initialized Jackrabbit repository in " + duration + + " s, home: " + getHomeDirectory() + ", config: " + + configuration); } catch (Exception e) { throw new ArgeoException("Cannot create Jackrabbit repository " + getHomeDirectory(), e); @@ -232,31 +236,30 @@ public class JackrabbitContainer implements Repository, ResourceLoaderAware { /** Lazy init. */ protected File getHomeDirectory() { - return homeDirectory; - // if (home != null) - // return home; - // - // try { - // String osgiData = System.getProperty("osgi.instance.area"); - // if (osgiData != null) - // osgiData = osgiData.substring("file:".length()); - // String path; - // if (homeDirectory == null) - // path = "./jackrabbit"; - // else - // path = homeDirectory; - // if (path.startsWith(".") && osgiData != null) { - // home = new File(osgiData + '/' + path).getCanonicalFile(); - // } else - // home = new File(path).getCanonicalFile(); - // return home; - // } catch (Exception e) { - // throw new ArgeoException("Cannot define Jackrabbit home based on " - // + homeDirectory, e); - // } + try { + if (homeDirectory == null) { + if (inMemory) { + homeDirectory = new File( + System.getProperty("java.io.tmpdir") + + File.separator + + System.getProperty("user.name") + + File.separator + "jackrabbit-" + + UUID.randomUUID()); + homeDirectory.mkdirs(); + // will it work if directory is not empty? + homeDirectory.deleteOnExit(); + } + } + + return homeDirectory.getCanonicalFile(); + } catch (IOException e) { + throw new ArgeoException("Cannot get canonical file for " + + homeDirectory, e); + } } public void dispose() throws Exception { + long begin = System.currentTimeMillis(); if (repository != null) { if (repository instanceof JackrabbitRepository) ((JackrabbitRepository) repository).shutdown(); @@ -274,11 +277,13 @@ public class JackrabbitContainer implements Repository, ResourceLoaderAware { + getHomeDirectory()); } + double duration = ((double) (System.currentTimeMillis() - begin)) / 1000; if (uri != null && !uri.trim().equals("")) log.info("Destroyed Jackrabbit repository with uri " + uri); else - log.info("Destroyed Jackrabbit repository " + repository + " in " - + getHomeDirectory() + " with config " + configuration); + log.info("Destroyed Jackrabbit repository in " + duration + + " s, home: " + getHomeDirectory() + ", config " + + configuration); } /**