Reputation: 5
In my current Tomcat Project, I integrated JackRabbit. Its functionality works well. However, the start of the repository is very slow. It took around 5 seconds. I think this is not bearable. Anyone has some ideas about how to integrate the Jackrabbit to the web project?
Currently, I have my own Session factory in the web project. Code is as following:
public class TMPSessionFactory {
public static Session getSession() throws RepositoryException, NamingException {
String configFile = "C:\\workspaces\\repository.xml";
String repHomeDir = "C:\\JackRabbitDemo\\repository";
Hashtable<String, Object> hashTable = new Hashtable<String, Object>();
hashTable.put(Context.INITIAL_CONTEXT_FACTORY, DummyInitialContextFactory.class.getName());
hashTable.put(Context.PROVIDER_URL, "127.0.0.1");
InitialContext ctx = new InitialContext(hashTable);
RegistryHelper.registerRepository(ctx, "repo", configFile, repHomeDir, true);
Repository r = (Repository) ctx.lookup("repo");
SimpleCredentials cred = new SimpleCredentials("admin", "admin".toCharArray());
Session session = r.login(cred, null);
return session;}}
Each time if I need a jackrabbit session, I will call this static function.
I don't know whether my way is appropriate or not since it works but not well enough (each time, the start of the repository is slow).
Upvotes: 0
Views: 404
Reputation: 3517
Do you mean you create a new repository and bind it to JNDI before doing a look up each time you want to access your repository ? All this code:
String configFile = "C:\\workspaces\\repository.xml";
String repHomeDir = "C:\\JackRabbitDemo\\repository";
Hashtable<String, Object> hashTable = new Hashtable<String, Object>();
hashTable.put(Context.INITIAL_CONTEXT_FACTORY, DummyInitialContextFactory.class.getName());
hashTable.put(Context.PROVIDER_URL, "127.0.0.1");
InitialContext ctx = new InitialContext(hashTable);
RegistryHelper.registerRepository(ctx, "repo", configFile, repHomeDir, true);
should be only called once. Maybe you should declared your jackrabbit repository as a Tomcat resource as it is documented here : https://jackrabbit.apache.org/shared-j2ee-resource-howto.html
Upvotes: 0