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:
parent
558c5a5660
commit
0db8fd2bbd
2 changed files with 50 additions and 28 deletions
|
@ -9,7 +9,7 @@ import javax.servlet.http.*;
|
|||
import java.io.*;
|
||||
import java.rmi.Naming;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import helma.framework.*;
|
||||
|
||||
/**
|
||||
|
@ -20,11 +20,11 @@ import helma.framework.*;
|
|||
|
||||
public class MultiServletClient extends AbstractServletClient {
|
||||
|
||||
private HashMap apps = null;
|
||||
private Hashtable apps;
|
||||
|
||||
public void init (ServletConfig init) throws ServletException {
|
||||
super.init (init);
|
||||
apps = new HashMap ();
|
||||
apps = new Hashtable ();
|
||||
host = init.getInitParameter ("host");
|
||||
if (host == null)
|
||||
host = "localhost";
|
||||
|
@ -33,25 +33,37 @@ public class MultiServletClient extends AbstractServletClient {
|
|||
hopUrl = "//" + host + ":" + port + "/";
|
||||
}
|
||||
|
||||
public void destroy () {
|
||||
if (apps != null) {
|
||||
apps.clear ();
|
||||
apps = null;
|
||||
}
|
||||
}
|
||||
|
||||
ResponseTrans execute (RequestTrans req, String reqPath) throws Exception {
|
||||
String appID = getAppID (reqPath);
|
||||
IRemoteApp app = getApp (appID);
|
||||
String appId = getAppID (reqPath);
|
||||
IRemoteApp app = getApp (appId);
|
||||
req.path = getRequestPath (reqPath);
|
||||
try {
|
||||
return app.execute (req);
|
||||
} catch (Exception x) {
|
||||
invalidateApp (appId);
|
||||
app = getApp (appId);
|
||||
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) {
|
||||
apps.remove (appID);
|
||||
IRemoteApp getApp (String appId) throws Exception {
|
||||
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) {
|
||||
|
|
|
@ -30,21 +30,31 @@ public class ServletClient extends AbstractServletClient {
|
|||
String portstr = init.getInitParameter ("port");
|
||||
port = portstr == null ? 5055 : Integer.parseInt (portstr);
|
||||
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 {
|
||||
IRemoteApp app = getApp ();
|
||||
req.path = getRequestPath (reqPath);
|
||||
if (app == null)
|
||||
initApp ();
|
||||
try {
|
||||
return app.execute (req);
|
||||
} catch (Exception x) {
|
||||
initApp ();
|
||||
return app.execute (req);
|
||||
}
|
||||
}
|
||||
|
||||
IRemoteApp getApp () throws Exception {
|
||||
if (app != null)
|
||||
return app;
|
||||
if (appName == null)
|
||||
throw new ServletException ("Helma application name not specified for helma.servlet.ServletClient");
|
||||
synchronized void initApp () throws Exception {
|
||||
app = (IRemoteApp) Naming.lookup (hopUrl + appName);
|
||||
return app;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue