Changeset 3485


Ignore:
Timestamp:
2002-10-25T16:25:41+13:00 (22 years ago)
Author:
kjdon
Message:

ServiceModules changed to ServicesImpl, activate and deactivate module methods added

File:
1 edited

Legend:

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

    r3470 r3485  
    5353 * @see ModuleInterface
    5454 * @see Collection
    55  * @see ServiceModule
     55 * @see ServicesImpl
    5656 * @see Communicator
    5757 *
     
    140140    }
    141141
    142     // read thru the collect directory and create all the collections
     142    // read thru the collect directory and activate all the valid collections
    143143    File collectDir = new File(GSFile.collectDir(site_home_));
    144144    if (collectDir.exists()) {
     
    150150            String colName = contents[i].getName();
    151151            if (!colName.startsWith("CVS")) {
    152             createCollection(colName);
     152            activateCollection(colName);
    153153            }
    154154        }
     
    293293            System.out.println("..."+name);
    294294            ServiceCluster sc = new ServiceCluster();
    295             sc.setSiteHome(site_name_);
     295            sc.setSiteHome(site_home_);
    296296            sc.setClusterName(name);
     297            sc.setMessageRouter(this);
    297298            sc.configure(cluster);
    298299            module_map_.put(name, sc);
     
    312313   
    313314    Node module_list = GSXML.getChildByTagName(config,
    314                            "serviceModuleList");
     315                           "servicesImplList");
    315316    if (module_list == null) {
    316317        System.out.println("... none to be loaded");
    317318    } else {
    318         NodeList service_modules = module_list.getChildNodes();
    319         if (service_modules.getLength()==0) {
     319        NodeList service_impls = module_list.getChildNodes();
     320        if (service_impls.getLength()==0) {
    320321        System.out.println("... none to be loaded");
    321322        } else {
     
    325326        service_request.setAttribute("info", "serviceList");
    326327       
    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);
     328        for(int i=0; i<service_impls.getLength(); i++) {
     329            if (service_impls.item(i).getNodeName().equals("servicesImpl")) {
     330            Element n = (Element)service_impls.item(i);
    330331            String service_name = n.getAttribute("name");
    331332            System.out.println("..."+service_name);
    332333            try {
    333                 ServiceModule s = (ServiceModule)Class.forName("org.greenstone.gsdl3.service."+service_name).newInstance();
     334                ServicesImpl s = (ServicesImpl)Class.forName("org.greenstone.gsdl3.service."+service_name).newInstance();
    334335                s.setSiteHome(site_home_);
    335336                s.setMessageRouter(this);
     
    342343                NodeList services = service_response.getElementsByTagName("service");
    343344                if (services.getLength()==0) {
    344                 System.err.println("MessageRouter configure error: serviceModule "+service_name+" has no services!");
     345                System.err.println("MessageRouter configure error: servicesImpl "+service_name+" has no services!");
    345346                } else {
    346347                for (int j=0; j<services.getLength();j++) {
     
    353354                }
    354355            } catch (Exception e ) {
    355                 System.err.println("MessageRouter configure exception:  in ServiceModule class specification:  "+ e.getMessage());
     356                System.err.println("MessageRouter configure exception:  in ServicesImpl class specification:  "+ e.getMessage());
    356357               
    357358            }
     
    471472     *@return true if collection created ok
    472473     */
    473     protected boolean createCollection(String col_name) {
    474 
    475     System.out.println("MessageRouter:Creating and configuring collection: "+col_name+".");
     474    protected boolean activateCollection(String col_name) {
     475
     476    System.out.println("MessageRouter:Activating collection: "+col_name+".");
    476477             
    477478    Collection c = new Collection();
     
    479480    c.setSiteHome(site_home_);
    480481    if (c.configure()) {
     482        // this could be a reactivation, so delete the old version
     483        deactivate("collection", col_name);
    481484        // add to list of collections
    482485        module_map_.put(col_name, c);
     
    494497    }
    495498
     499    protected boolean activateServiceCluster(String cluster_name) {
     500    return false;
     501
     502    }
     503
     504    protected boolean activateServicesImpl(String module_name) {
     505    return false;
     506    }
     507
    496508    //*****************************************************************
    497509    // auxiliary process methods
     
    505517    protected Element processMessage(Element req) {
    506518
    507     // message for self, should be type=describe at this stage
     519    // message for self, should be type=describe/configure at this stage
    508520    String type = req.getAttribute("type");
     521    Element response = doc_.createElement("response");
    509522   
    510523    if (type.equals("describe")) {
     
    514527        return description_;
    515528        }
    516         // else create a new response with the appropriate info
    517         Element response = doc_.createElement("response");
     529        // use the new response with the appropriate info
    518530        response.setAttribute("type", "describe");
    519531       
     
    531543        return response;
    532544        }
     545
     546    } else if (type.equals("configure")) {
     547       
     548        // a list of configure requests - should put any error messages
     549        // or success messages into response
     550        NodeList commands = req.getChildNodes();
     551        for (int i=0; i<commands.getLength(); i++) {
     552        // all the commands should be Elements
     553        if (commands.item(i).getNodeType() == Node.ELEMENT_NODE) {
     554            Element elem = (Element)commands.item(i);
     555            String name = elem.getNodeName();
     556            String module_name = elem.getAttribute("name");
     557            String module_type = elem.getAttribute("type");
     558            if (name.equals("activate")) {
     559            if (module_type.equals("collection")) {
     560                activateCollection(module_name);
     561            } else if (module_type.equals("servicesImpl")) {
     562                activateServicesImpl(module_name);
     563            } else if (module_type.equals("serviceCluster")) {
     564                activateServiceCluster(module_name);
     565            } else {
     566                // cant process the activation
     567                // send an error
     568            }
     569            } else if (name.equals("deactivate")) {
     570            deactivate(module_type, module_name);
     571           
     572            }
     573        }
     574        }
     575        return response;
    533576       
    534577    }
     
    540583    }
    541584
     585    protected boolean deactivate(String type, String name) {
     586   
     587    if (module_map_.containsKey(name)) {
     588
     589        System.out.println("MessageRouter: deactivating thing, name="+name);
     590        module_map_.remove(name);
     591
     592        // also remove the xml bit from description list
     593        if (type.equals("collection")) {
     594        Element this_col = GSXML.getNamedElement(collection_list_, "collection", "name", name);
     595        collection_list_.removeChild(this_col);
     596        return true;
     597        } else if (type.equals("service")) {
     598        Element this_service = GSXML.getNamedElement(service_list_, "service", "name", name);
     599        service_list_.removeChild(this_service);
     600        return true;
     601        } else if (type.equals("serviceCluster")) {
     602        Element this_cluster = GSXML.getNamedElement(cluster_list_, "serviceCluster", "name", name);
     603        cluster_list_.removeChild(this_cluster);
     604        return true;
     605        } else {
     606        System.out.println("couldn't deactivate coll");
     607        // couldn't do it
     608        return false;
     609        }
     610    }
     611    // else not activated
     612    return false;
     613
     614    }
    542615}
     616
     617
Note: See TracChangeset for help on using the changeset viewer.