Hi Ernest,

On 5/7/07, Ernest Friedman-Hill <[EMAIL PROTECTED]> wrote:

...That's why the return value is Writer -- precisely because you're not
supposed to know what you'll get back.


Hmmmm :-|

OK, hypothetically let's say that I have a web-app -- MVC2 with a servlet or
two doing the heavy lifting and dispatching results to various JSP views.
There is a Rete instance in session scope that needs to pipe its output to
the views, but under the control of the logic in the controller servlets
proper and not due to any logic in the JSPs.  The typical workflow is
something like this:

1. Receive a request object and process via doPost().
2. Extract request parameter(s) and assert as fact(s).
3  Run engine. (Rules fire and store results in engine hashmap).
4  When engine halts, fetch the results from the engine.
5. Wrap results as new response and dispatch JSP view to client.

OK, let's say that during the initial request, I create the following
Writers ...

StringWriter swConsole = new StringWriter();
StringWriter swTrace = new StringWriter();

... and I stick them in the session...

session.setAttribute("swConsole", swConsole);
session.setAttribute("swTrace", swTrace);

... then I let the session Rete instance know that it's supposed to use
these routers

engine.addOutputRouter("console", (StringWriter
)(session.getAttribute("swConsole
")));
engine.addOutputRouter("trace", (StringWriter )(session.getAttribute("swTrace
")));
engine.setWatchRouter("trace");

Q1.  Is this an incorrect approach?

At this point, assume also that all Jess script (printout) statements are
coded to use the "console" router.  I expect all WSTDOUT to go to "trace".

I feed the engine some facts, and I run the engine (which has one or more
rules that will explicitly call (halt)).  All good.  Now, I want to recover
the output from the various printout statements and the WSTDOUT stream
sitting the two StringWriters.

Since the Writers are in session scope, the hack that I have been using is
to place <%=expression%> tags inside various HTML tags in the JSP views (i.e.,
<td><%=expression%></td>)  where the expression is extracting the
StringWriters and dumping their buffers.  This seems terribly inelegant, but
it works.

I looked at JIA Ch.19, but since 'm using JSPs strictly for presentation, I
didn't see a clear extrapolation from the TekMart examples.  So...

Q2.  In such an asynchronous application, what is the cleanest way to fetch
re-routed engine output and buffer it to JSP views?

Cheers,
Jason

-----------------------------------------------------------
Jason C. Morris
Worcester Polytechnic Institute     Phone: (508) 831-5006
Department of Computer Science      FAX:   (508) 831-5776
Fuller Laboratories - Room 312      [EMAIL PROTECTED]
Artificial Intelligence Lab (AIRG)
100 Institute Road
Worcester, MA 01609-2280
-----------------------------------------------------------

Reply via email to