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/GeneralAction.java

    r28202 r28382  
    3131    {
    3232        Element message = this.converter.nodeToElement(message_node);
    33 
     33        Document doc = message.getOwnerDocument();
     34       
    3435        // the result
    35         Element result = this.doc.createElement(GSXML.MESSAGE_ELEM);
    36         Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM);
     36        Element result = doc.createElement(GSXML.MESSAGE_ELEM);
     37        Element page_response = doc.createElement(GSXML.RESPONSE_ELEM);
    3738        result.appendChild(page_response);
    3839
     
    8788        {
    8889            //do the request
    89             Element mr_query_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    90             Element mr_query_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
     90            Element mr_query_message = doc.createElement(GSXML.MESSAGE_ELEM);
     91            Element mr_query_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
    9192
    9293            if (request_type.equals("s"))
     
    102103            if (service_params != null)
    103104            {
    104                 param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
    105                 GSXML.addParametersToList(this.doc, param_list, service_params);
     105                param_list = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     106                GSXML.addParametersToList(doc, param_list, service_params);
    106107                mr_query_request.appendChild(param_list);
    107108            }
     
    110111            if (userInformation != null)
    111112            {
    112                 mr_query_request.appendChild(this.doc.importNode(userInformation, true));
     113                mr_query_request.appendChild(doc.importNode(userInformation, true));
    113114            }
    114115            mr_query_request.setAttribute("remoteAddress", request.getAttribute("remoteAddress"));
     
    134135
    135136        // request the service info for the selected service - should be cached
    136         Element mr_info_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    137         Element mr_info_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, to, userContext);
     137        Element mr_info_message = doc.createElement(GSXML.MESSAGE_ELEM);
     138        Element mr_info_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, to, userContext);
    138139        mr_info_message.appendChild(mr_info_request);
    139140        Element mr_info_response = (Element) this.mr.process(mr_info_message);
     
    145146        if (desNode != null)
    146147        {
    147             page_response.appendChild((Element) this.doc.importNode(desNode, true));
     148            page_response.appendChild((Element) doc.importNode(desNode, true));
    148149        }
    149150
Note: See TracChangeset for help on using the changeset viewer.