Changeset 3485
- Timestamp:
- 2002-10-25T16:25:41+13:00 (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/core/MessageRouter.java
r3470 r3485 53 53 * @see ModuleInterface 54 54 * @see Collection 55 * @see Service Module55 * @see ServicesImpl 56 56 * @see Communicator 57 57 * … … 140 140 } 141 141 142 // read thru the collect directory and create all thecollections142 // read thru the collect directory and activate all the valid collections 143 143 File collectDir = new File(GSFile.collectDir(site_home_)); 144 144 if (collectDir.exists()) { … … 150 150 String colName = contents[i].getName(); 151 151 if (!colName.startsWith("CVS")) { 152 createCollection(colName);152 activateCollection(colName); 153 153 } 154 154 } … … 293 293 System.out.println("..."+name); 294 294 ServiceCluster sc = new ServiceCluster(); 295 sc.setSiteHome(site_ name_);295 sc.setSiteHome(site_home_); 296 296 sc.setClusterName(name); 297 sc.setMessageRouter(this); 297 298 sc.configure(cluster); 298 299 module_map_.put(name, sc); … … 312 313 313 314 Node module_list = GSXML.getChildByTagName(config, 314 "service ModuleList");315 "servicesImplList"); 315 316 if (module_list == null) { 316 317 System.out.println("... none to be loaded"); 317 318 } 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) { 320 321 System.out.println("... none to be loaded"); 321 322 } else { … … 325 326 service_request.setAttribute("info", "serviceList"); 326 327 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); 330 331 String service_name = n.getAttribute("name"); 331 332 System.out.println("..."+service_name); 332 333 try { 333 Service Module s = (ServiceModule)Class.forName("org.greenstone.gsdl3.service."+service_name).newInstance();334 ServicesImpl s = (ServicesImpl)Class.forName("org.greenstone.gsdl3.service."+service_name).newInstance(); 334 335 s.setSiteHome(site_home_); 335 336 s.setMessageRouter(this); … … 342 343 NodeList services = service_response.getElementsByTagName("service"); 343 344 if (services.getLength()==0) { 344 System.err.println("MessageRouter configure error: service Module"+service_name+" has no services!");345 System.err.println("MessageRouter configure error: servicesImpl "+service_name+" has no services!"); 345 346 } else { 346 347 for (int j=0; j<services.getLength();j++) { … … 353 354 } 354 355 } catch (Exception e ) { 355 System.err.println("MessageRouter configure exception: in Service Moduleclass specification: "+ e.getMessage());356 System.err.println("MessageRouter configure exception: in ServicesImpl class specification: "+ e.getMessage()); 356 357 357 358 } … … 471 472 *@return true if collection created ok 472 473 */ 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+"."); 476 477 477 478 Collection c = new Collection(); … … 479 480 c.setSiteHome(site_home_); 480 481 if (c.configure()) { 482 // this could be a reactivation, so delete the old version 483 deactivate("collection", col_name); 481 484 // add to list of collections 482 485 module_map_.put(col_name, c); … … 494 497 } 495 498 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 496 508 //***************************************************************** 497 509 // auxiliary process methods … … 505 517 protected Element processMessage(Element req) { 506 518 507 // message for self, should be type=describe at this stage519 // message for self, should be type=describe/configure at this stage 508 520 String type = req.getAttribute("type"); 521 Element response = doc_.createElement("response"); 509 522 510 523 if (type.equals("describe")) { … … 514 527 return description_; 515 528 } 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 518 530 response.setAttribute("type", "describe"); 519 531 … … 531 543 return response; 532 544 } 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; 533 576 534 577 } … … 540 583 } 541 584 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 } 542 615 } 616 617
Note:
See TracChangeset
for help on using the changeset viewer.