At 07:38 AM 10/20/98 -0700, Ernest Friedman-Hill wrote:
>I think Beth Zhang wrote:
>>
>> Thanks for the help and I can get the error message from the browser. Now
the problem
>> is that I can't get the .clp result to the browser by writing
>>
>> " toClient.println(nd.stdout());"
>> or
>> " toClient.println(nd.stderr());"
>>
>> It prints out "java.io.PrintStream", but not the content I wanted
>> Shall I re-route the PrintStream in NullDisplay?
>>
>
>You should write a class which implements ReteDisplay and returns a
>PrintStream wrapped around the "toClient" object from the stderr() and
>stdout() methods. THen construct your Rete object with an instance of
>this class.
>
I've appended a simple implementation that works for me in servlets, called
JessServletDisplay.java
An additional complication is that I re-use a Jess Rete instance across
multiple connections to the servlet. Keep in mind that a single servlet
instance is shared by many client threads. I've created a simple "resource
pool" that holds several pre-loaded Rete instances, and allocates them to
incoming threads in the servlet. In this situation, you also have to
re-assign the routers since (according to the Jess docs) the standard Rete
routers are only assigned once when the ReteDisplay is first set.
I put this 'setOutput' method in my servlet (actually in a session class),
where display points to an instance of JessServletDisplay, and rete is the
reused Rete object. The 'out' stream is provided by the servlet, what you
called 'toClient'. After the client thread is finished, I reassign the rete
engine output to stdout/stderr.
I hope this helps.
public void setOutput( PrintStream out ) {
if( out == null ) {
display.setOutputStream(null);
display.setErrorStream(null);
rete.addOutputRouter("t", System.out);
rete.addOutputRouter("WSTDOUT", System.out);
rete.addOutputRouter("WSTDERR", System.err);
}
else {
display.setOutputStream(out);
display.setErrorStream(out);
rete.addOutputRouter("t", out);
rete.addOutputRouter("WSTDOUT", out);
rete.addOutputRouter("WSTDERR", out);
}
}
//////////////////////////////////////////////////////////////////////
// JessServletDisplay.java
// Redirects Jess output to the servlet.
// It extends observable so that it can send messages to the
// network viewer tool
//
//////////////////////////////////////////////////////////////////////
package eligibility;
import jess.*;
import java.util.*;
import java.io.*;
/**
* Redirects Jess output to the servlet. This is an implementation of
* the ReteDisplay interface. See the Jess documentation for
* a complete description of how a ReteDisplay works.
*
*/
public class JessServletDisplay extends Observable implements ReteDisplay {
private InputStream in;
private PrintStream out;
private PrintStream err;
public void setInputStream( InputStream in ) {
this.in = in;
}
public void setOutputStream( PrintStream out ) {
this.out = out;
}
public void setErrorStream( PrintStream err ) {
this.err = err;
}
public void assertFact(ValueVector fact) {}
public void retractFact(ValueVector fact) {}
public void addDeffacts(Deffacts df) {}
public void addDeftemplate(Deftemplate dt) {}
public void addDefrule(Defrule rule)
{
// The network has changed. Notify anyone who cares..
setChanged();
notifyObservers();
}
public void activateRule(Defrule rule) {}
public void deactivateRule(Defrule rule) {}
public void fireRule(Defrule rule) {System.gc();}
public java.io.PrintStream stdout() {
return (out != null) ? out : System.out;
}
public java.io.InputStream stdin() {
return (in != null) ? in : System.in;
}
public java.io.PrintStream stderr() {
return (err != null) ? err : System.err;
}
public java.applet.Applet applet() { return null; }
}
---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list. List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------