Ignore:
Timestamp:
2013-10-10T17:21:30+13:00 (11 years ago)
Author:
davidb
Message:

Elimination of the 'this.doc' field from the Action baseclass and the subclasses that rely on it. For Greenstone3 purposes it is unsafe to create this object in the constructor to the action and then store it for other methods to access. This is because the Greenstone 3 (and in particular calls to 'process' operate in a multi-threaded context, that is managed by the Servlet server (e.g. Tomcat by default). Calls to DOM methods are not guaranteed to be thread safe, this became apparent when we started looking in to an exception that was being thrown, and centred around use of the DOM method 'item(i)'. The change this commit makes is to remove 'this.doc' being stored as a field. A document is now created in the top level of a call to 'process()' and when a DOM reference is needed in a subsequent method an Element variable (typically passed in as a parameter to the method) is used (through 'Document doc = element.getOwnerDocument()') to gain access to the DOM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/ProcessAction.java

    r25635 r28382  
    2121    public Node process(Node message_node)
    2222    {
    23 
    2423        Element message = this.converter.nodeToElement(message_node);
    25 
     24        Document doc = message.getOwnerDocument();
     25       
    2626        // the result
    27         Element result = this.doc.createElement(GSXML.MESSAGE_ELEM);
    28         Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM);
     27        Element result = doc.createElement(GSXML.MESSAGE_ELEM);
     28        Element page_response = doc.createElement(GSXML.RESPONSE_ELEM);
    2929        result.appendChild(page_response);
    3030
     
    7070            // if rt=s or rt=r, do the request
    7171
    72             Element mr_query_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
     72            Element mr_query_message = doc.createElement(GSXML.MESSAGE_ELEM);
    7373            String request_type_att;
    7474            Element param_list = null;
     
    7676            { // status
    7777                request_type_att = GSXML.REQUEST_TYPE_STATUS;
    78                 param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
    79                 Element param = this.doc.createElement(GSXML.PARAM_ELEM);
     78                param_list = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     79                Element param = doc.createElement(GSXML.PARAM_ELEM);
    8080                param.setAttribute(GSXML.NAME_ATT, GSParams.PROCESS_ID);
    8181                param.setAttribute(GSXML.VALUE_ATT, (String) params.get(GSParams.PROCESS_ID));
     
    8989                if (service_params != null)
    9090                {
    91                     param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
    92                     GSXML.addParametersToList(this.doc, param_list, service_params);
     91                    param_list = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     92                    GSXML.addParametersToList(doc, param_list, service_params);
    9393                }
    9494
    9595            }
    96             Element mr_query_request = GSXML.createBasicRequest(this.doc, request_type_att, to, userContext);
     96            Element mr_query_request = GSXML.createBasicRequest(doc, request_type_att, to, userContext);
    9797            if (param_list != null)
    9898            {
     
    112112            // else append the contents of the response to the page - just the status elem for now
    113113            Element status = (Element) GSXML.getChildByTagName(result_response, GSXML.STATUS_ELEM);
    114             page_response.appendChild(this.doc.importNode(status, true));
     114            page_response.appendChild(doc.importNode(status, true));
    115115        }
    116116
     
    118118
    119119        // request the service info for the selected service - should be cached
    120         Element mr_info_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    121         Element mr_info_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, to, userContext);
     120        Element mr_info_message = doc.createElement(GSXML.MESSAGE_ELEM);
     121        Element mr_info_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, to, userContext);
    122122        mr_info_message.appendChild(mr_info_request);
    123123        Element mr_info_response = (Element) this.mr.process(mr_info_message);
     
    125125        String path = GSXML.RESPONSE_ELEM;
    126126        path = GSPath.appendLink(path, GSXML.SERVICE_ELEM);
    127         Element description = (Element) this.doc.importNode(GSXML.getNodeByPath(mr_info_response, path), true);
     127        Element description = (Element) doc.importNode(GSXML.getNodeByPath(mr_info_response, path), true);
    128128
    129129        page_response.appendChild(description);
     
    134134    protected Element getServiceParamList(Element cgi_param_list)
    135135    {
    136 
    137         Element new_param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     136        Document doc = cgi_param_list.getOwnerDocument();
     137       
     138        Element new_param_list = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
    138139        Element param;
    139140        NodeList cgi_params = cgi_param_list.getChildNodes();
     
    147148            }
    148149            // else add it in to the list
    149             new_param_list.appendChild(this.doc.importNode(p, true));
     150            new_param_list.appendChild(doc.importNode(p, true));
    150151        }
    151152        return new_param_list;
Note: See TracChangeset for help on using the changeset viewer.