Adam Heath wrote:
Adrian Crum wrote:
Adam Heath wrote:
Adam Heath wrote:
T result = Controller.runWith(data, new Callable<T>() {
    public T call() throws Exception {
        // code
        return null;
    }
});
I've actually attempted this, and while I think the implementation of
this pattern is simple, actually *using* it in higher-level code ends
up making things rather verbose.
I just added your idea to the branch, and it *is* simple. Let's say we
want to make incoming requests a security-aware artifact:

org.ofbiz.webapp.control.ControlServlet

public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
    try {
        ThreadContext.runExecutionArtifact(new RequestArtifact(request,
response));
    } catch (Throwable t) {
        // Do something with t
    }
}

If you were *really* hot stuff, you'd use APT, annotations, and
directly modify the code at compile time.

@ThreadContext(RequestArtifact.class)
public void doGet(HttpServletRequest request, HttpServletResponse
response) {
    if (request.getAttribute()) {
        // ...
    }
}

Alas, I'm only semi-hot stuff.

Reply via email to