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;
import org.argeo.ArgeoException;
/** Proxy JCR sessions and attach them to calling threads. */
-public class ThreadBoundJcrSessionFactory {
+public abstract class ThreadBoundJcrSessionFactory {
private final static Log log = LogFactory
.getLog(ThreadBoundJcrSessionFactory.class);
}
/** 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");
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
}
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();
/** 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()) {