threadlocal-vars-cleaner/src/main/java/org/gcube/portal/threadlocalexec/SmartGearsPortalExecutor.java

55 lines
2.0 KiB
Java

package org.gcube.portal.threadlocalexec;
import org.apache.catalina.core.StandardThreadExecutor;
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author Massimiliano Assante, CNR ISTI
*
*/
public class SmartGearsPortalExecutor extends StandardThreadExecutor {
private static final Logger _log = LoggerFactory.getLogger(SmartGearsPortalExecutor.class);
public SmartGearsPortalExecutor() {
}
// @Override
// public void execute(Runnable command, long timeout, TimeUnit unit) {
// super.execute(new WrappedRunnable(command), timeout, unit);
// }
@Override
public void execute(Runnable command) {
super.execute(new WrappedRunnable(command));
}
public static class WrappedRunnable implements Runnable{
private Runnable runnable;
protected WrappedRunnable(Runnable runnable){
this.runnable = runnable;
}
public void run() {
try{
this.runnable.run();
_log.debug("execution finished on thread "+Thread.currentThread().getName() + " server.RStudioServiceImpl LOGtoRemove");
System.out.println("execution finished on thread "+Thread.currentThread().getName()+ " server.RStudioServiceImpl LOGtoRemove");
} finally {
SecurityTokenProvider.instance.reset();
ScopeProvider.instance.reset();
AuthorizationProvider.instance.reset();
_log.debug("done reset all the thread locals on thread "+Thread.currentThread().getName()+ " server.RStudioServiceImpl LOGtoRemove");
System.out.println("done reset all the thread locals on thread "+Thread.currentThread().getName()+ " server.RStudioServiceImpl LOGtoRemove");
}
}
}
}