Changeset 3470 for trunk


Ignore:
Timestamp:
2002-10-16T09:32:25+13:00 (22 years ago)
Author:
kjdon
Message:

now looks for service clusters in its config file, and loads them up too.

File:
1 edited

Legend:

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

    r3461 r3470  
    7676    /** list of collections that can be reached */
    7777    protected Element collection_list_ = null;
    78     /** list of services that can be reached */
     78    /** list of service clusters that can be reached */
     79    protected Element cluster_list_ = null;
     80    /** list of single services that can be reached
     81     * can we have single services? or chould all be part of a cluster */
    7982    protected Element service_list_ = null;
    8083    /** list of sites that can be reached */
     
    120123    description_.setAttribute("type", "describe");
    121124    collection_list_ = doc_.createElement("collectionList");
     125    cluster_list_ = doc_.createElement("serviceClusterList");
    122126    service_list_ = doc_.createElement("serviceList");
    123127    site_list_ = doc_.createElement("siteList");
     
    146150            String colName = contents[i].getName();
    147151            if (!colName.startsWith("CVS")) {
    148             // need to ignore CVS
    149152            createCollection(colName);
    150153            }
     
    261264
    262265    System.out.println("MessageRouter:configuring site");
    263     Document config_doc = converter_.getDOM(file);
    264 
    265     NodeList local_site_name = config_doc.getElementsByTagName("localSiteName");
    266     if (local_site_name.getLength()==0) {
     266    Element config = converter_.getDOM(file).getDocumentElement();
     267
     268    Element local_site_name = (Element)GSXML.getChildByTagName(config,
     269                               "localSiteName");
     270    if (local_site_name == null) {
    267271        System.err.println("MessageRouter configure error:no site name in config file");
    268272        return false;
    269273    } else {
    270         Element elem = (Element)local_site_name.item(0);
    271         site_name_ = elem.getAttribute("value");
    272     }
    273 
    274     // load up the services
    275     System.out.println("loading service modules...");
    276 
    277     NodeList service_modules = config_doc.getElementsByTagName("serviceModule");
    278     if (service_modules.getLength()==0) {
     274        site_name_ = local_site_name.getAttribute("value");
     275    }
     276   
     277    // load up the service clusters
     278    System.out.println("loading service clusters ...");
     279    Node cluster_list = GSXML.getChildByTagName(config,
     280                            "serviceClusterList");
     281    if (cluster_list == null) {
    279282        System.out.println("... none to be loaded");
    280283    } else {
    281    
    282         Element service_request = doc_.createElement("request");
    283         service_request.setAttribute("type", "describe");
    284         service_request.setAttribute("info", "serviceList");
     284        NodeList service_clusters = cluster_list.getChildNodes();
     285        if (service_clusters.getLength()==0) {
     286        System.out.println("... none to be loaded");
     287        } else {
     288       
     289        for (int i=0; i<service_clusters.getLength(); i++) {
     290            if (service_clusters.item(i).getNodeName().equals("serviceCluster")) {
     291            Element cluster = (Element)service_clusters.item(i);
     292            String name = cluster.getAttribute("name");
     293            System.out.println("..."+name);
     294            ServiceCluster sc = new ServiceCluster();
     295            sc.setSiteHome(site_name_);
     296            sc.setClusterName(name);
     297            sc.configure(cluster);
     298            module_map_.put(name, sc);
     299            //add short info to
     300            Element e = doc_.createElement("serviceCluster");
     301            e.setAttribute("name", name);
     302            cluster_list_.appendChild(e);
     303
     304            }
     305        }
     306        }
    285307       
    286         for(int i=0; i<service_modules.getLength(); i++) {
    287         Element n = (Element)service_modules.item(i);
    288         String service_name = n.getAttribute("name");
    289         System.out.println("..."+service_name);
    290         try {
    291             ServiceModule s = (ServiceModule)Class.forName("org.greenstone.gsdl3.service."+service_name).newInstance();
    292             s.setSiteHome(site_home_);
    293             s.setMessageRouter(this);
    294            
    295             // pass the XML node to the service for service configuration
    296             s.configure(n);
    297            
    298             // find out the supported services for this service module
    299             Element service_response = (Element) s.process(service_request);
    300             NodeList services = service_response.getElementsByTagName("service");
    301             if (services.getLength()==0) {
    302             System.err.println("MessageRouter configure error: serviceModule "+service_name+" has no services!");
    303             } else {
    304             for (int j=0; j<services.getLength();j++) {
    305                 String service = ((Element)services.item(j)).getAttribute("name");
    306             module_map_.put(service, s);
    307            
    308             // add short info to service_list_ XML
    309             service_list_.appendChild(doc_.importNode(services.item(j), true));
    310             }
    311             }
    312         } catch (Exception e ) {
    313             System.err.println("MessageRouter configure exception:  in ServiceModule class specification:  "+ e.getMessage());
    314            
    315         }
     308    }
     309
     310    // load up the individual services
     311    System.out.println("loading service modules...");
     312   
     313    Node module_list = GSXML.getChildByTagName(config,
     314                           "serviceModuleList");
     315    if (module_list == null) {
     316        System.out.println("... none to be loaded");
     317    } else {
     318        NodeList service_modules = module_list.getChildNodes();
     319        if (service_modules.getLength()==0) {
     320        System.out.println("... none to be loaded");
     321        } else {
    316322       
    317         } // for each service module
     323        Element service_request = doc_.createElement("request");
     324        service_request.setAttribute("type", "describe");
     325        service_request.setAttribute("info", "serviceList");
     326       
     327        for(int i=0; i<service_modules.getLength(); i++) {
     328            if (service_modules.item(i).getNodeName().equals("serviceModule")) {
     329            Element n = (Element)service_modules.item(i);
     330            String service_name = n.getAttribute("name");
     331            System.out.println("..."+service_name);
     332            try {
     333                ServiceModule s = (ServiceModule)Class.forName("org.greenstone.gsdl3.service."+service_name).newInstance();
     334                s.setSiteHome(site_home_);
     335                s.setMessageRouter(this);
     336               
     337                // pass the XML node to the service for service configuration
     338                s.configure(n);
     339               
     340                // find out the supported services for this service module
     341                Element service_response = (Element) s.process(service_request);
     342                NodeList services = service_response.getElementsByTagName("service");
     343                if (services.getLength()==0) {
     344                System.err.println("MessageRouter configure error: serviceModule "+service_name+" has no services!");
     345                } else {
     346                for (int j=0; j<services.getLength();j++) {
     347                    String service = ((Element)services.item(j)).getAttribute("name");
     348                    module_map_.put(service, s);
     349                   
     350                // add short info to service_list_ XML
     351                    service_list_.appendChild(doc_.importNode(services.item(j), true));
     352                }
     353                }
     354            } catch (Exception e ) {
     355                System.err.println("MessageRouter configure exception:  in ServiceModule class specification:  "+ e.getMessage());
     356               
     357            }
     358            } // if
     359        } // for each service module
     360        }
    318361    }
    319362   
    320363    // load up the sites
    321364    System.out.println("loading external sites...");
    322     NodeList sites = config_doc.getElementsByTagName("site");
    323     if (sites.getLength()==0) {
     365    Node site_list = GSXML.getChildByTagName(config, "siteList");
     366    if (site_list ==null ) {
    324367        System.out.println("...none found");
    325368    } else {
    326 
    327         for (int i=0; i<sites.getLength(); i++) {
    328         Element s = (Element)sites.item(i);
    329         Communicator comm=null;
    330         String type = s.getAttribute("type");
    331         String name = s.getAttribute("name");
    332         System.out.println("..."+name+", type="+type);
    333          if (type.equals("soap")) {
    334             comm = new SOAPCommunicator();
    335             comm.setSiteHome(site_home_);
    336             comm.setConnectionName(name);
    337             comm.setConnectionAddress(s.getAttribute("address"));
    338             comm.setSiteName(site_name_);
    339            
    340             // add to map of modules
    341             module_map_.put(name, comm);
    342             site_list_.appendChild(doc_.importNode(s, true));
    343             // need to get collection list and service list from here
    344             // this may introduce a configure problem - leave as
    345             // is for now, but fix up later - kjdon
    346             getRemoteCollectionInfo(comm, name);
    347             getRemoteServiceInfo(comm, name);
    348 
    349         } else {
    350             System.err.print("cant talk to server of type:"+type);
    351             System.err.println(", so not making a connection to "+name);
     369        NodeList sites = site_list.getChildNodes();
     370        if (sites.getLength()==0) {
     371        System.out.println("...none found");
     372        } else {
     373       
     374        for (int i=0; i<sites.getLength(); i++) {
     375            if (sites.item(i).getNodeName().equals("site")) {
     376            Element s = (Element)sites.item(i);
     377            Communicator comm=null;
     378            String type = s.getAttribute("type");
     379            String name = s.getAttribute("name");
     380            System.out.println("..."+name+", type="+type);
     381            if (type.equals("soap")) {
     382                comm = new SOAPCommunicator();
     383                comm.setSiteHome(site_home_);
     384                comm.setConnectionName(name);
     385                comm.setConnectionAddress(s.getAttribute("address"));
     386                comm.setSiteName(site_name_);
     387               
     388                // add to map of modules
     389                module_map_.put(name, comm);
     390                site_list_.appendChild(doc_.importNode(s, true));
     391                // need to get collection list and service list from here
     392                // this may introduce a configure problem - leave as
     393                // is for now, but fix up later - kjdon
     394                getRemoteCollectionInfo(comm, name);
     395                getRemoteServiceInfo(comm, name);
     396               
     397            } else {
     398                System.err.print("cant talk to server of type:"+type);
     399                System.err.println(", so not making a connection to "+name);
     400            }
     401           
     402            }
    352403        }
    353        
    354            
    355404        }
    356405    }
    357406    // add children to description_
     407    description_.appendChild(cluster_list_);
    358408    description_.appendChild(service_list_);
    359409    description_.appendChild(site_list_);
     
    471521        response.appendChild(collection_list_);
    472522        return response;
     523        } else if (info.equals("serviceClusterList")) {
     524        response.appendChild(cluster_list_);
     525        return response;
    473526        } else if (info.equals("serviceList")) {
    474527        response.appendChild(service_list_);
Note: See TracChangeset for help on using the changeset viewer.