Fixed bugs and performance problems in StandaloneServletClient.

The Hop embedded into the servlet container is now the
most performant way to run a Hop app.
This commit is contained in:
hns 2001-11-20 15:02:35 +00:00
parent af93d7b66a
commit 96393ea5eb
2 changed files with 49 additions and 38 deletions

View file

@ -168,7 +168,7 @@ public abstract class AbstractServletClient extends HttpServlet {
invalidateApp (appID);
app = getApp (appID);
app.ping ();
restrans = app.execute (reqtrans);
restrans = app.execute (reqtrans);
}
writeResponse (response, restrans, cookies, protocol);
@ -187,7 +187,7 @@ public abstract class AbstractServletClient extends HttpServlet {
}
private void writeResponse (HttpServletResponse res, ResponseTrans trans, Cookie[] cookies, String protocol) {
void writeResponse (HttpServletResponse res, ResponseTrans trans, Cookie[] cookies, String protocol) {
for (int i = 0; i < trans.countCookies(); i++) try {
Cookie c = new Cookie(trans.getKeyAt(i), trans.getValueAt(i));

View file

@ -16,34 +16,60 @@ import helma.util.*;
* This is a standalone Hop servlet client, running a Hop application by itself.
*/
public class StandaloneServletClient extends AbstractServletClient {
public final class StandaloneServletClient extends AbstractServletClient {
private Application app = null;
private String appName;
private String serverProps;
public void init (ServletConfig init) throws ServletException {
super.init (init);
appName = init.getInitParameter ("application");
serverProps = init.getInitParameter ("serverprops");
super.init (init);
}
synchronized IRemoteApp getApp (String appID) throws Exception {
IRemoteApp getApp (String appID) {
if (app == null)
createApp ();
return app;
}
/**
* Create the application. Since we are synchronized only here, we
* do another check if the app already exists and immediately return if it does.
*/
synchronized void createApp () {
if (app != null)
return app;
return;
try {
File propfile = new File (serverProps);
File hopHome = new File (propfile.getParent());
SystemProperties sysProps = new SystemProperties (propfile.getAbsolutePath());
app = new Application (appName, hopHome, sysProps, null);
app.init ();
app.start ();
} catch (Exception x) {
System.err.println ("Error starting Application "+appName+": "+x);
x.printStackTrace ();
}
return app;
}
/**
* The servlet is being destroyed. Close and release the application if
* it does exist.
*/
public void destroy () {
if (app != null) {
try {
app.stop ();
} catch (Exception x) {
System.err.println ("Error shutting down app "+app.getName()+": ");
x.printStackTrace ();
}
}
app = null;
}
void invalidateApp (String appID) {
@ -85,23 +111,8 @@ public class StandaloneServletClient extends AbstractServletClient {
}
}