Fixed bugs 131: "No retry code in ServletClient and MultiServletClient"

and 132:  "helma.serlvet.ServletClient stops working after *some* time"
And also did some cleanup work.
This commit is contained in:
hns 2002-10-16 15:28:12 +00:00
parent 558c5a5660
commit 0db8fd2bbd
2 changed files with 50 additions and 28 deletions

View file

@ -9,7 +9,7 @@ import javax.servlet.http.*;
import java.io.*; import java.io.*;
import java.rmi.Naming; import java.rmi.Naming;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.util.HashMap; import java.util.Hashtable;
import helma.framework.*; import helma.framework.*;
/** /**
@ -20,11 +20,11 @@ import helma.framework.*;
public class MultiServletClient extends AbstractServletClient { public class MultiServletClient extends AbstractServletClient {
private HashMap apps = null; private Hashtable apps;
public void init (ServletConfig init) throws ServletException { public void init (ServletConfig init) throws ServletException {
super.init (init); super.init (init);
apps = new HashMap (); apps = new Hashtable ();
host = init.getInitParameter ("host"); host = init.getInitParameter ("host");
if (host == null) if (host == null)
host = "localhost"; host = "localhost";
@ -33,25 +33,37 @@ public class MultiServletClient extends AbstractServletClient {
hopUrl = "//" + host + ":" + port + "/"; hopUrl = "//" + host + ":" + port + "/";
} }
public void destroy () {
if (apps != null) {
apps.clear ();
apps = null;
}
}
ResponseTrans execute (RequestTrans req, String reqPath) throws Exception { ResponseTrans execute (RequestTrans req, String reqPath) throws Exception {
String appID = getAppID (reqPath); String appId = getAppID (reqPath);
IRemoteApp app = getApp (appID); IRemoteApp app = getApp (appId);
req.path = getRequestPath (reqPath); req.path = getRequestPath (reqPath);
try {
return app.execute (req);
} catch (Exception x) {
invalidateApp (appId);
app = getApp (appId);
return app.execute (req); return app.execute (req);
} }
IRemoteApp getApp (String appID) throws Exception {
IRemoteApp retval = (IRemoteApp) apps.get (appID);
if (retval != null) {
return retval;
}
retval = (IRemoteApp) Naming.lookup (hopUrl + appID);
apps.put (appID, retval);
return retval;
} }
void invalidateApp (String appID) { IRemoteApp getApp (String appId) throws Exception {
apps.remove (appID); IRemoteApp app = (IRemoteApp) apps.get (appId);
if (app != null)
return app;
app = (IRemoteApp) Naming.lookup (hopUrl + appId);
apps.put (appId, app);
return app;
}
void invalidateApp (String appId) {
apps.remove (appId);
} }
String getAppID (String path) { String getAppID (String path) {

View file

@ -30,21 +30,31 @@ public class ServletClient extends AbstractServletClient {
String portstr = init.getInitParameter ("port"); String portstr = init.getInitParameter ("port");
port = portstr == null ? 5055 : Integer.parseInt (portstr); port = portstr == null ? 5055 : Integer.parseInt (portstr);
hopUrl = "//" + host + ":" + port + "/"; hopUrl = "//" + host + ":" + port + "/";
if (appName == null)
throw new ServletException ("Application name not specified for helma.servlet.ServletClient");
} }
public void destroy () {
if (app != null) {
app = null;
}
}
ResponseTrans execute (RequestTrans req, String reqPath) throws Exception { ResponseTrans execute (RequestTrans req, String reqPath) throws Exception {
IRemoteApp app = getApp ();
req.path = getRequestPath (reqPath); req.path = getRequestPath (reqPath);
if (app == null)
initApp ();
try {
return app.execute (req);
} catch (Exception x) {
initApp ();
return app.execute (req); return app.execute (req);
} }
}
IRemoteApp getApp () throws Exception { synchronized void initApp () throws Exception {
if (app != null)
return app;
if (appName == null)
throw new ServletException ("Helma application name not specified for helma.servlet.ServletClient");
app = (IRemoteApp) Naming.lookup (hopUrl + appName); app = (IRemoteApp) Naming.lookup (hopUrl + appName);
return app;
} }