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.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.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,12 +19,12 @@ 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 + "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseTrans execute (RequestTrans req, String reqPath) throws Exception {
|
public void destroy () {
|
||||||
String appID = getAppID (reqPath);
|
if (apps != null) {
|
||||||
IRemoteApp app = getApp (appID);
|
apps.clear ();
|
||||||
req.path = getRequestPath (reqPath);
|
apps = null;
|
||||||
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) {
|
ResponseTrans execute (RequestTrans req, String reqPath) throws Exception {
|
||||||
apps.remove (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 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) {
|
||||||
|
|
|
@ -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);
|
||||||
return app.execute (req);
|
if (app == null)
|
||||||
|
initApp ();
|
||||||
|
try {
|
||||||
|
return app.execute (req);
|
||||||
|
} catch (Exception x) {
|
||||||
|
initApp ();
|
||||||
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue