Changeset 28856 for main


Ignore:
Timestamp:
2014-02-27T13:53:11+13:00 (10 years ago)
Author:
kjdon
Message:

removed this.doc, as DOM is not thread safe. Use a new DOM each time we create a response

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/MessageRouter.java

    r28853 r28856  
    5555 *
    5656 *
    57  * @author Katherine Don
    58  * @version $Revision$
    59  * @see ModuleInterface
    60  * @see Collection
    61  * @see ServiceRack
    62  * @see Communicator
    63  *
    6457 *      Since some service classes are moved into a separate directory in order
    6558 *      for them to be checked out from a different repository, we modify the
     
    8477    protected HashMap<String, ModuleInterface> module_map = null;
    8578
    86     /** container Document to create XML Nodes */
    87     protected Document doc = null;
    8879    /** the full description of this site */
    8980
     
    121112    {
    122113        this.converter = new XMLConverter();
    123         this.doc = this.converter.newDOM();
    124114    }
    125115
     
    245235    {
    246236
     237      Document doc = this.converter.newDOM();
    247238        Element message = this.converter.nodeToElement(message_node);
    248239
     
    256247        NodeList requests = message.getElementsByTagName(GSXML.REQUEST_ELEM);
    257248
    258         Element mainResult = this.doc.createElement(GSXML.MESSAGE_ELEM);
     249        Element mainResult = doc.createElement(GSXML.MESSAGE_ELEM);
    259250
    260251        // empty request
     
    264255            return mainResult;
    265256        }
    266 
    267         Document message_doc = message.getOwnerDocument();
    268257
    269258        // for now, just process each request one by one, and append the results to mainResult
     
    298287                if (result != null)
    299288                {
    300                     mainResult.appendChild(this.doc.importNode(result, true));
     289                    mainResult.appendChild(doc.importNode(result, true));
    301290                }
    302291            }
     
    311300                {
    312301                    // why can't we do this outside the loop??
    313                     Element mess = this.doc.createElement(GSXML.MESSAGE_ELEM);
    314                     Element copied_request = (Element) this.doc.importNode(req, true);
     302                    Element mess = doc.createElement(GSXML.MESSAGE_ELEM);
     303                    Element copied_request = (Element) doc.importNode(req, true);
    315304                    mess.appendChild(copied_request);
    316305
     
    330319                            if (res != null)
    331320                            {
    332                                 mainResult.appendChild(this.doc.importNode(res, true));
     321                                mainResult.appendChild(doc.importNode(res, true));
    333322                            }
    334323                        }
     
    336325                        {
    337326                            // add in a place holder response
    338                             Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
     327                            Element response = doc.createElement(GSXML.RESPONSE_ELEM);
    339328                            response.setAttribute(GSXML.FROM_ATT, this_mod);
    340329                            mainResult.appendChild(response);
     
    475464
    476465        // load up the services: serviceRackList
    477         this.service_list = this.doc.createElement(GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER);
     466        Document doc = this.converter.newDOM();
     467        this.service_list = doc.createElement(GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER);
    478468        Element service_rack_list_elem = (Element) GSXML.getChildByTagName(config_info, GSXML.SERVICE_CLASS_ELEM + GSXML.LIST_MODIFIER);
    479469        configureServices(service_rack_list_elem);
    480470
    481471        // load up the service clusters
    482         this.cluster_list = this.doc.createElement(GSXML.CLUSTER_ELEM + GSXML.LIST_MODIFIER);
     472        this.cluster_list = doc.createElement(GSXML.CLUSTER_ELEM + GSXML.LIST_MODIFIER);
    483473        Element cluster_list_elem = (Element) GSXML.getChildByTagName(config_info, GSXML.CLUSTER_ELEM + GSXML.LIST_MODIFIER);
    484474        configureClusters(cluster_list_elem);
    485475
    486476        // load up the collections
    487         this.collection_list = this.doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
    488         this.private_collection_list = this.doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
    489         this.oai_collection_list = this.doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
     477        this.collection_list = doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
     478        this.private_collection_list = doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
     479        this.oai_collection_list = doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
    490480        configureCollections();
    491481
    492482        // load up the external sites - this also adds their services/clusters/collections to the other lists - so must be done last
    493         this.site_list = this.doc.createElement(GSXML.SITE_ELEM + GSXML.LIST_MODIFIER);
     483        this.site_list = doc.createElement(GSXML.SITE_ELEM + GSXML.LIST_MODIFIER);
    494484        Element site_list_elem = (Element) GSXML.getChildByTagName(config_info, GSXML.SITE_ELEM + GSXML.LIST_MODIFIER);
    495485        configureExternalSites(site_list_elem);
    496486
    497487        // load up the site metadata
    498         this.metadata_list = this.doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
     488        this.metadata_list = doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
    499489        Element metadata_list_elem = (Element) GSXML.getChildByTagName(config_info, GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
    500490        loadMetadata(metadata_list_elem);
     
    522512            return true;
    523513        }
    524 
    525         Element service_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    526         Element service_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, "", new UserContext());
     514        Document doc = this.converter.newDOM();
     515        Element service_message = doc.createElement(GSXML.MESSAGE_ELEM);
     516        Element service_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, "", new UserContext());
    527517        service_message.appendChild(service_request);
    528518
     
    573563                else
    574564                {
     565                  Document service_list_doc = this.service_list.getOwnerDocument();
    575566                    for (int j = 0; j < services.getLength(); j++)
    576567                    {
     
    580571
    581572                        // add short info to service_list_ XML
    582                         this.service_list.appendChild(this.doc.importNode(services.item(j), true));
     573                        this.service_list.appendChild(service_list_doc.importNode(services.item(j), true));
    583574                    }
    584575                }
     
    610601        }
    611602
     603        Document doc = this.cluster_list.getOwnerDocument();
    612604        for (int i = 0; i < service_clusters.getLength(); i++)
    613605        {
     
    628620            this.module_map.put(name, sc); // this replaces the old one if there was one already present
    629621            //add short info to cluster list
    630             Element e = this.doc.createElement(GSXML.CLUSTER_ELEM);
     622            Element e = doc.createElement(GSXML.CLUSTER_ELEM);
    631623            e.setAttribute(GSXML.NAME_ATT, name);
    632624            this.cluster_list.appendChild(e);
     
    688680
    689681        logger.info("Activating collection: " + col_name + ".");
    690 
     682        Document doc = this.collection_list.getOwnerDocument();
    691683        // Look for the etc/collectionInit.xml file, and see what sort of Collection to load
    692684        Collection c = null;
     
    730722            // add to list of collections
    731723            this.module_map.put(col_name, c);
    732             Element e = this.doc.createElement(GSXML.COLLECTION_ELEM);
     724            Element e = doc.createElement(GSXML.COLLECTION_ELEM);
    733725            e.setAttribute(GSXML.NAME_ATT, col_name);
    734726
     
    741733                if (c.hasOAI())
    742734                {
    743                     Element ane = this.doc.createElement(GSXML.COLLECTION_ELEM);
     735                    Element ane = doc.createElement(GSXML.COLLECTION_ELEM);
    744736                    ane.setAttribute(GSXML.NAME_ATT, col_name);
    745737                    ane.setAttribute(OAIXML.LASTMODIFIED, "" + c.getLastmodified());
     
    859851                // add to map of modules
    860852                this.module_map.put(name, comm);
    861                 this.site_list.appendChild(this.doc.importNode(site_elem, true));
     853                this.site_list.appendChild(this.site_list.getOwnerDocument().importNode(site_elem, true));
    862854                // need to get collection list and service
    863855                // list from here- if the site isn't up yet, the site will
     
    886878    protected boolean loadMetadata(Element config_metadata_list)
    887879    {
    888 
     880     
    889881        // load up the sites
    890882        logger.info("loading site metadata...");
     
    902894        }
    903895
     896        Document doc = this.metadata_list.getOwnerDocument();
    904897        for (int i = 0; i < metadata.getLength(); i++)
    905898        {
    906899            Element s = (Element) metadata.item(i);
    907             this.metadata_list.appendChild(this.doc.importNode(s, true));
     900            this.metadata_list.appendChild(doc.importNode(s, true));
    908901        }
    909902        return true;
     
    923916
    924917        logger.info(" getting info from site:" + site_name);
    925 
    926         Element info_request = this.doc.createElement(GSXML.MESSAGE_ELEM);
    927         Element req = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, "", new UserContext());
     918        Document doc = this.converter.newDOM();
     919        Element info_request = doc.createElement(GSXML.MESSAGE_ELEM);
     920        Element req = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, "", new UserContext());
    928921        info_request.appendChild(req);
    929922
     
    948941                // other collections ??
    949942                e.setAttribute(GSXML.NAME_ATT, GSPath.prependLink(col_name, site_name));
    950                 this.collection_list.appendChild(this.doc.importNode(e, true));
     943                this.collection_list.appendChild(doc.importNode(e, true));
    951944            }
    952945        }
     
    961954                String serv_name = e.getAttribute(GSXML.NAME_ATT);
    962955                e.setAttribute(GSXML.NAME_ATT, GSPath.prependLink(serv_name, site_name));
    963                 this.service_list.appendChild(this.doc.importNode(e, true));
     956                this.service_list.appendChild(doc.importNode(e, true));
    964957            }
    965958        }
     
    974967                String clus_name = e.getAttribute(GSXML.NAME_ATT);
    975968                e.setAttribute(GSXML.NAME_ATT, GSPath.prependLink(clus_name, site_name));
    976                 this.cluster_list.appendChild(this.doc.importNode(e, true));
     969                this.cluster_list.appendChild(doc.importNode(e, true));
    977970            }
    978971        }
     
    10901083
    10911084        // message for self, should be type=describe/configure at this stage
     1085            Document doc = this.converter.newDOM();
    10921086        String type = req.getAttribute(GSXML.TYPE_ATT);
    1093         Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
     1087        Element response = doc.createElement(GSXML.RESPONSE_ELEM);
    10941088        response.setAttribute(GSXML.FROM_ATT, "");
    10951089        if (type.equals(GSXML.REQUEST_TYPE_DESCRIBE))
     
    11001094            if (param_list == null)
    11011095            {
    1102                 response.appendChild(this.collection_list);
    1103                 response.appendChild(this.cluster_list);
    1104                 response.appendChild(this.site_list);
    1105                 response.appendChild(this.service_list);
    1106                 response.appendChild(this.metadata_list);
     1096              response.appendChild(doc.importNode(this.collection_list, true));
     1097                response.appendChild(doc.importNode(this.cluster_list, true));
     1098                response.appendChild(doc.importNode(this.site_list, true));
     1099                response.appendChild(doc.importNode(this.service_list, true));
     1100                response.appendChild(doc.importNode(this.metadata_list, true));
    11071101                return response;
    11081102            }
     
    11211115                    if (info.equals(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER))
    11221116                    {
    1123                         response.appendChild(this.collection_list);
     1117                        response.appendChild(doc.importNode(this.collection_list, true));
    11241118                    }
    11251119                    else if (info.equals(GSXML.CLUSTER_ELEM + GSXML.LIST_MODIFIER))
    11261120                    {
    1127                         response.appendChild(this.cluster_list);
     1121                        response.appendChild(doc.importNode(this.cluster_list, true));
    11281122                    }
    11291123                    else if (info.equals(GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER))
    11301124                    {
    1131                         response.appendChild(this.service_list);
     1125                        response.appendChild(doc.importNode(this.service_list, true));
    11321126                    }
    11331127                    else if (info.equals(GSXML.SITE_ELEM + GSXML.LIST_MODIFIER))
    11341128                    {
    1135                         response.appendChild(this.site_list);
     1129                        response.appendChild(doc.importNode(this.site_list, true));
    11361130                    }
    11371131                    else if (info.equals(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER))
    11381132                    {
    1139                         response.appendChild(this.metadata_list);
     1133                        response.appendChild(doc.importNode(this.metadata_list, true));
    11401134                    }
    11411135                }
     
    11501144            //this is the oai receptionist asking for a list of oai-support collections
    11511145            response.setAttribute(GSXML.TYPE_ATT, OAIXML.OAI_SET_LIST);
    1152             response.appendChild(this.oai_collection_list);
     1146            response.appendChild(doc.importNode(this.oai_collection_list, true));
    11531147            return response;
    11541148        }
     
    11911185                        }
    11921186                    }
    1193                     Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, message);
     1187                    Element s = GSXML.createTextElement(doc, GSXML.STATUS_ELEM, message);
    11941188                    response.appendChild(s);
    11951189                }
    11961190                //else if (action.equals(GSXML.SYSTEM_TYPE_ISPERSISTENT)) {
    1197                 //  Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM,  "Persistent: true.");
     1191                //  Element s = GSXML.createTextElement(doc, GSXML.STATUS_ELEM,  "Persistent: true.");
    11981192                //  response.appendChild(s);
    11991193                //}
     
    12051199                        // need to reconfigure the MR
    12061200                        this.configureLocalSite();
    1207                         Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, "MessageRouter reconfigured successfully");
     1201                        Element s = GSXML.createTextElement(doc, GSXML.STATUS_ELEM, "MessageRouter reconfigured successfully");
    12081202                        response.appendChild(s);
    12091203
     
    12681262                            message = "Error in reconfiguring " + subset;
    12691263                        }
    1270                         Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, message);
     1264                        Element s = GSXML.createTextElement(doc, GSXML.STATUS_ELEM, message);
    12711265                        response.appendChild(s);
    12721266                    }
     
    12831277                        if (success)
    12841278                        {
    1285                             Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, module_type + ": " + module_name + " deactivated", GSXML.SYSTEM_TYPE_DEACTIVATE, GSXML.SUCCESS);
     1279                            Element s = GSXML.createTextElement(doc, GSXML.STATUS_ELEM, module_type + ": " + module_name + " deactivated", GSXML.SYSTEM_TYPE_DEACTIVATE, GSXML.SUCCESS);
    12861280                            response.appendChild(s);
    12871281                        }
    12881282                        else
    12891283                        {
    1290                             Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, module_type + ": " + module_name + " could not be deactivated", GSXML.SYSTEM_TYPE_DEACTIVATE, GSXML.ERROR);
     1284                            Element s = GSXML.createTextElement(doc, GSXML.STATUS_ELEM, module_type + ": " + module_name + " could not be deactivated", GSXML.SYSTEM_TYPE_DEACTIVATE, GSXML.ERROR);
    12911285                            response.appendChild(s);
    12921286                        }
     
    13121306                        if (success)
    13131307                        {
    1314                             Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, module_type + ": " + module_name + " activated", GSXML.SYSTEM_TYPE_ACTIVATE, GSXML.SUCCESS);
     1308                            Element s = GSXML.createTextElement(doc, GSXML.STATUS_ELEM, module_type + ": " + module_name + " activated", GSXML.SYSTEM_TYPE_ACTIVATE, GSXML.SUCCESS);
    13151309                            response.appendChild(s);
    13161310                        }
    13171311                        else
    13181312                        {
    1319                             Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, module_type + ": " + module_name + " could not be activated", GSXML.SYSTEM_TYPE_ACTIVATE, GSXML.ERROR);
     1313                            Element s = GSXML.createTextElement(doc, GSXML.STATUS_ELEM, module_type + ": " + module_name + " could not be activated", GSXML.SYSTEM_TYPE_ACTIVATE, GSXML.ERROR);
    13201314                            response.appendChild(s);
    13211315                        }
     
    13401334    protected Element modifyMessages(Element request, Element message, Element result)
    13411335    {
    1342         Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
     1336      Document doc = this.converter.newDOM();
     1337        Element response = doc.createElement(GSXML.RESPONSE_ELEM);
    13431338        response.setAttribute(GSXML.FROM_ATT, "");
    13441339        response.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_MESSAGING);
Note: See TracChangeset for help on using the changeset viewer.