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

    r25635 r28382  
    2828    public Node process(Node message_node)
    2929    {
    30 
    3130        Element message = this.converter.nodeToElement(message_node);
    32 
     31        Document doc = message.getOwnerDocument();
     32       
    3333        // get the request - assume there is only one
    3434        Element request = (Element) GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
    3535
    3636        // create the return message
    37         Element result = this.doc.createElement(GSXML.MESSAGE_ELEM);
    38         Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM);
     37        Element result = doc.createElement(GSXML.MESSAGE_ELEM);
     38        Element page_response = doc.createElement(GSXML.RESPONSE_ELEM);
    3939        result.appendChild(page_response);
    4040
     
    7575
    7676        // make the request to the collection
    77         Element mr_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
     77        Element mr_message = doc.createElement(GSXML.MESSAGE_ELEM);
    7878
    79         Element ret_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
     79        Element ret_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
    8080        mr_message.appendChild(ret_request);
    8181
    82         Element doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
     82        Element doc_list = doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
    8383        ret_request.appendChild(doc_list);
    84         Element doc = this.doc.createElement(GSXML.DOC_NODE_ELEM);
    85         doc.setAttribute(GSXML.NODE_ID_ATT, doc_name);
    86         doc_list.appendChild(doc);
     84        Element docelem = doc.createElement(GSXML.DOC_NODE_ELEM);
     85        docelem.setAttribute(GSXML.NODE_ID_ATT, doc_name);
     86        doc_list.appendChild(docelem);
    8787
    8888        // also add in a request for the Title metadata
    8989        to = GSPath.appendLink(collection, "DocumentMetadataRetrieve");
    90         Element meta_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
     90        Element meta_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
    9191        // copy the doc list
    9292        meta_request.appendChild(doc_list.cloneNode(true));
    9393        // add in a metadata param
    94         Element param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     94        Element param_list = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
    9595        meta_request.appendChild(param_list);
    96         Element param = GSXML.createParameter(this.doc, "metadata", "root_Title");
     96        Element param = GSXML.createParameter(doc, "metadata", "root_Title");
    9797        param_list.appendChild(param);
    9898
     
    103103        String[] links = { GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER, GSXML.DOC_NODE_ELEM };
    104104        String path = GSPath.createPath(links);
    105         Element doc_node = (Element) this.doc.importNode(GSXML.getNodeByPath(ret_response, path), true);
     105        Element doc_node = (Element) doc.importNode(GSXML.getNodeByPath(ret_response, path), true);
    106106        page_response.appendChild(doc_node);
    107107
     
    114114        if (meta_list != null)
    115115        {
    116             doc_node.appendChild(this.doc.importNode(meta_list, true));
     116            doc_node.appendChild(doc.importNode(meta_list, true));
    117117        }
    118118        return result;
Note: See TracChangeset for help on using the changeset viewer.