X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.server.jcr%2Fsrc%2Forg%2Fargeo%2Fjcr%2FThreadBoundJcrSessionFactory.java;h=281bd015c4d7f5fad90878695def317ee0173a98;hb=0d843d64df3f588ad1429905cf5f6e29c65becd3;hp=56caab0a399ac3c9e0fe769493c8b49b8bb77197;hpb=b4c772a263e0f19f6c283dbbb87d04794072b284;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.server.jcr/src/org/argeo/jcr/ThreadBoundJcrSessionFactory.java b/org.argeo.server.jcr/src/org/argeo/jcr/ThreadBoundJcrSessionFactory.java index 56caab0a3..281bd015c 100644 --- a/org.argeo.server.jcr/src/org/argeo/jcr/ThreadBoundJcrSessionFactory.java +++ b/org.argeo.server.jcr/src/org/argeo/jcr/ThreadBoundJcrSessionFactory.java @@ -34,13 +34,11 @@ import javax.jcr.SimpleCredentials; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; /** Proxy JCR sessions and attach them to calling threads. */ @Deprecated public abstract class ThreadBoundJcrSessionFactory { - private final static Log log = LogFactory - .getLog(ThreadBoundJcrSessionFactory.class); + private final static Log log = LogFactory.getLog(ThreadBoundJcrSessionFactory.class); private Repository repository; /** can be injected as list, only used if repository is null */ @@ -58,23 +56,20 @@ public abstract class ThreadBoundJcrSessionFactory { private boolean active = true; // monitoring - private final List threads = Collections - .synchronizedList(new ArrayList()); - private final Map activeSessions = Collections - .synchronizedMap(new HashMap()); + private final List threads = Collections.synchronizedList(new ArrayList()); + private final Map activeSessions = Collections.synchronizedMap(new HashMap()); private MonitoringThread monitoringThread; public ThreadBoundJcrSessionFactory() { Class[] interfaces = { Session.class }; - proxiedSession = (Session) Proxy.newProxyInstance( - ThreadBoundJcrSessionFactory.class.getClassLoader(), + proxiedSession = (Session) Proxy.newProxyInstance(ThreadBoundJcrSessionFactory.class.getClassLoader(), interfaces, new JcrSessionInvocationHandler()); } /** Logs in to the repository using various strategies. */ protected synchronized Session login() { if (!isActive()) - throw new ArgeoException("Thread bound session factory inactive"); + throw new ArgeoJcrException("Thread bound session factory inactive"); // discard session previously attached to this thread Thread thread = Thread.currentThread(); @@ -96,24 +91,22 @@ public abstract class ThreadBoundJcrSessionFactory { // invalid credentials, go to the next step } catch (RepositoryException e1) { // other kind of exception, fail - throw new ArgeoException("Cannot log in to repository", e1); + throw new ArgeoJcrException("Cannot log in to repository", e1); } // log using default username / password (useful for testing purposes) if (newSession == null) try { - SimpleCredentials sc = new SimpleCredentials(defaultUsername, - defaultPassword.toCharArray()); + SimpleCredentials sc = new SimpleCredentials(defaultUsername, defaultPassword.toCharArray()); newSession = repository().login(sc, workspace); } catch (RepositoryException e) { - throw new ArgeoException("Cannot log in to repository", e); + throw new ArgeoJcrException("Cannot log in to repository", e); } session.set(newSession); // Log and monitor new session if (log.isTraceEnabled()) - log.trace("Logged in to JCR session " + newSession + "; userId=" - + newSession.getUserID()); + log.trace("Logged in to JCR session " + newSession + "; userId=" + newSession.getUserID()); // monitoring activeSessions.put(thread.getId(), newSession); @@ -126,7 +119,7 @@ public abstract class ThreadBoundJcrSessionFactory { } public void init() throws Exception { - log.error("SHOULD NOT BE USED ANYMORE"); + // log.error("SHOULD NOT BE USED ANYMORE"); monitoringThread = new MonitoringThread(); monitoringThread.start(); } @@ -136,8 +129,7 @@ public abstract class ThreadBoundJcrSessionFactory { // return; if (log.isTraceEnabled()) - log.trace("Cleaning up " + activeSessions.size() - + " active JCR sessions..."); + log.trace("Cleaning up " + activeSessions.size() + " active JCR sessions..."); deactivate(); for (Session sess : activeSessions.values()) { @@ -174,8 +166,7 @@ public abstract class ThreadBoundJcrSessionFactory { activeSessions.remove(thread.getId()); session.logout(); if (log.isTraceEnabled()) - log.trace("Cleaned up JCR session (userID=" - + session.getUserID() + ") from dead thread " + log.trace("Cleaned up JCR session (userID=" + session.getUserID() + ") from dead thread " + thread.getId()); } it.remove(); @@ -214,7 +205,7 @@ public abstract class ThreadBoundJcrSessionFactory { if (it.hasNext()) return it.next(); } - throw new ArgeoException("No repository injected"); + throw new ArgeoJcrException("No repository injected"); } // /** Useful for declarative registration of OSGi services (blueprint) */ @@ -253,8 +244,7 @@ public abstract class ThreadBoundJcrSessionFactory { protected class JcrSessionInvocationHandler implements InvocationHandler { - public Object invoke(Object proxy, Method method, Object[] args) - throws Throwable, RepositoryException { + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable, RepositoryException { Session threadSession = session.get(); if (threadSession == null) { if ("logout".equals(method.getName()))// no need to login @@ -280,8 +270,7 @@ public abstract class ThreadBoundJcrSessionFactory { Thread thread = Thread.currentThread(); removeSession(thread); if (log.isTraceEnabled()) - log.trace("Logged out JCR session (userId=" - + threadSession.getUserID() + ") on thread " + log.trace("Logged out JCR session (userId=" + threadSession.getUserID() + ") on thread " + thread.getId()); } return ret;