users@glassfish.java.net

Re: Interrupting a running Servlet

From: <glassfish_at_javadesktop.org>
Date: Tue, 01 Apr 2008 09:19:58 PST

writtmeyer is right, this isn't a simple problem.

You need a layer between your servlet are you C server.

Effectively you should be making requests to this C-Server service layer from your servlet, and those requests should not block your servlet (at least not for any meaningful amount of time).

The C-Server service layer can have a very simple API:

[code]
public interface CServerService {
    /* returns a process id token */
    public String startService(ServerArgs args);
    public void stopService(String processId);
    public ServerStatusResult getServiceStatus(String processId);
    public ServerResult getServiceResults(String processId);
}
[/code]

Then in one servlet call, you can invoke the CServerService.startService method, and IT does whatever is necessary to invoke the C Server, including creating any threads for it to maintain the connection with the C Server, marshalling the data, creating any listeners that may be needed, etc.. It returns an ID (a string in my case, could be anything) that can be used later to identify the specific invocation of the service, and, as you can see, can be used to stop the service, get it's status (running, stopped, X% complete, whatever you may be tracking), and the results of the service call.

This removes the burden of managing the C Server connection from your servlet container (and puts it in your hands, where it belongs).
[Message sent by forum member 'whartung' (whartung)]

http://forums.java.net/jive/thread.jspa?messageID=267102