protected <T> Callable<T> cleanup(final Callable<T> callable) {
return new Callable<T>() {
@Override
public T call() throws Exception {
RequestCleanup cleanup = scope.scope(
Key.get(RequestCleanup.class),
new Provider<RequestCleanup>() {
@Override
public RequestCleanup get() {
return new RequestCleanup();
}
}).get();
try {
return callable.call();
} finally {
cleanup.run();
}
}
};
}