X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=server%2Fruntime%2Forg.argeo.server.jcr%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fjcr%2FThreadBoundJcrSessionFactory.java;h=003bcc69b552fd956e5db28b8efd27e72f81237b;hb=2c834078d24857f491d60a4677c4f2f658a2f7fe;hp=1c33a43dec9a6788831fa92a2e8b83326645438c;hpb=8b78007039ccb1f19d498742a64cf62435e8b093;p=lgpl%2Fargeo-commons.git diff --git a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/ThreadBoundJcrSessionFactory.java b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/ThreadBoundJcrSessionFactory.java index 1c33a43de..003bcc69b 100644 --- a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/ThreadBoundJcrSessionFactory.java +++ b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/ThreadBoundJcrSessionFactory.java @@ -17,6 +17,7 @@ package org.argeo.jcr; import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.ArrayList; @@ -35,13 +36,9 @@ import javax.jcr.SimpleCredentials; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.ArgeoException; -import org.springframework.beans.factory.DisposableBean; -import org.springframework.beans.factory.FactoryBean; -import org.springframework.beans.factory.InitializingBean; /** Proxy JCR sessions and attach them to calling threads. */ -public class ThreadBoundJcrSessionFactory implements FactoryBean, - InitializingBean, DisposableBean { +public abstract class ThreadBoundJcrSessionFactory { private final static Log log = LogFactory .getLog(ThreadBoundJcrSessionFactory.class); @@ -73,7 +70,7 @@ public class ThreadBoundJcrSessionFactory implements FactoryBean, } /** Logs in to the repository using various strategies. */ - protected Session login() { + protected synchronized Session login() { if (!isActive()) throw new ArgeoException("Thread bound session factory inactive"); @@ -126,12 +123,12 @@ public class ThreadBoundJcrSessionFactory implements FactoryBean, return proxiedSession; } - public void afterPropertiesSet() throws Exception { + public void init() throws Exception { monitoringThread = new MonitoringThread(); monitoringThread.start(); } - public synchronized void destroy() throws Exception { + public synchronized void dispose() throws Exception { if (activeSessions.size() == 0) return; @@ -228,7 +225,7 @@ public class ThreadBoundJcrSessionFactory implements FactoryBean, protected class JcrSessionInvocationHandler implements InvocationHandler { public Object invoke(Object proxy, Method method, Object[] args) - throws Throwable { + throws Throwable, RepositoryException { Session threadSession = session.get(); if (threadSession == null) { if ("logout".equals(method.getName()))// no need to login @@ -239,7 +236,16 @@ public class ThreadBoundJcrSessionFactory implements FactoryBean, } preCall(threadSession); - Object ret = method.invoke(threadSession, args); + Object ret; + try { + ret = method.invoke(threadSession, args); + } catch (InvocationTargetException e) { + Throwable cause = e.getCause(); + if (cause instanceof RepositoryException) + throw (RepositoryException) cause; + else + throw cause; + } if ("logout".equals(method.getName())) { session.remove(); Thread thread = Thread.currentThread(); @@ -256,6 +262,10 @@ public class ThreadBoundJcrSessionFactory implements FactoryBean, /** Monitors registered thread in order to clean up dead ones. */ private class MonitoringThread extends Thread { + public MonitoringThread() { + super("ThreadBound JCR Session Monitor"); + } + @Override public void run() { while (isActive()) {