1 6 7 package SOFA.SOFAnet.Admin.RMI; 8 9 import java.rmi.server.UnicastRemoteObject ; 10 import java.rmi.server.ServerNotActiveException ; 11 import java.rmi.RemoteException ; 12 import SOFA.SOFAnet.Core.*; 13 import SOFA.SOFAnet.Repository.*; 14 import SOFA.SOFAnet.Search.*; 15 import SOFA.SOFAnet.TR.TRInterface; 16 import SOFA.SOFAnet.Search.RMI.RMISearchCenter; 17 import SOFA.SOFAnet.Search.RMI.RMISearchConfiguration; 18 import SOFA.SOFAnode.TR.ComponentInfo; 19 import SOFA.SOFAnode.TR.TRException; 20 import java.util.*; 21 22 27 public class RMIAdminServer extends UnicastRemoteObject implements RMIAdminInterface 28 { 29 private TRInterface tr; 30 private Repository rep; 31 private LocalOps localOps; 32 private NetOps netOps; 33 private ShareOps shareOps; 34 private SearchOps searchOps; 35 private RMISearchCenter rmiSearchCenter; 36 37 38 public RMIAdminServer(TRInterface tr, Repository rep, LocalOps localOps, NetOps netOps, ShareOps shareOps, SearchOps searchOps, RMISearchCenter rmiSearchCenter) throws RemoteException 39 { 40 this.tr = tr; 41 this.rep = rep; 42 this.localOps = localOps; 43 this.netOps = netOps; 44 this.shareOps = shareOps; 45 this.searchOps = searchOps; 46 this.rmiSearchCenter = rmiSearchCenter; 47 } 48 49 public String [] binBundlesList() throws RemoteException 50 { 51 BinBundles binBundles = rep.getBinBundles(); 52 synchronized (binBundles) 53 { 54 return (String [])binBundles.map.keySet().toArray(new String [binBundles.map.size()]); 55 } } 57 58 public String [] licencesList() throws RemoteException 59 { 60 Licences licences = rep.getLicences(); 61 synchronized (licences) 62 { 63 return (String [])licences.map.keySet().toArray(new String [licences.map.size()]); 64 } } 66 67 public String [] localInfosList() throws RemoteException 68 { 69 LocalInfos localInfos = rep.getLocalInfos(); 70 synchronized (localInfos) 71 { 72 return (String [])localInfos.map.keySet().toArray(new String [localInfos.map.size()]); 73 } } 75 76 public LocalInfoDesc[] localInfoDescsList() throws RemoteException 77 { 78 LocalInfos localInfos = rep.getLocalInfos(); 79 synchronized (localInfos) 80 { 81 LocalInfoDesc[] localInfoDescs = new LocalInfoDesc[localInfos.map.size()]; 82 Iterator it = localInfos.map.values().iterator(); 83 84 for (int i = 0; i < localInfoDescs.length; i++) 85 { 86 localInfoDescs[i] = new LocalInfoDesc((LocalInfo)it.next()); 87 } 88 89 return localInfoDescs; 90 } } 92 93 public ComponentInfo[] componentsInTRList() throws RemoteException 94 { 95 return tr.list().getComponents(); 96 } 97 98 public String [] bundleOffersList() throws RemoteException 99 { 100 BundleOffers bundleOffers = rep.getBundleOffers(); 101 synchronized (bundleOffers) 102 { 103 return (String [])bundleOffers.map.keySet().toArray(new String [bundleOffers.map.size()]); 104 } } 106 107 public String [] inputTriggersList() throws RemoteException 108 { 109 InputTriggers inputTriggers = rep.getInputTriggers(); 110 synchronized (inputTriggers) 111 { 112 return (String [])inputTriggers.map.keySet().toArray(new String [inputTriggers.map.size()]); 113 } } 115 116 public InputTriggerDesc[] inputTriggerDescsList() throws RemoteException 117 { 118 InputTriggers inputTriggers = rep.getInputTriggers(); 119 synchronized (inputTriggers) 120 { 121 InputTriggerDesc[] inputTriggerDescs = new InputTriggerDesc[inputTriggers.map.size()]; 122 Iterator it = inputTriggers.map.values().iterator(); 123 124 for (int i = 0; i < inputTriggerDescs.length; i++) 125 { 126 inputTriggerDescs[i] = new InputTriggerDesc((InputTrigger)it.next()); 127 } 128 129 return inputTriggerDescs; 130 } } 132 133 public String [] outputTriggersList() throws RemoteException 134 { 135 OutputTriggers outputTriggers = rep.getOutputTriggers(); 136 synchronized (outputTriggers) 137 { 138 return (String [])outputTriggers.map.keySet().toArray(new String [outputTriggers.map.size()]); 139 } } 141 142 public OutputTriggerDesc[] outputTriggerDescsList() throws RemoteException 143 { 144 OutputTriggers outputTriggers = rep.getOutputTriggers(); 145 synchronized (outputTriggers) 146 { 147 OutputTriggerDesc[] outputTriggerDescs = new OutputTriggerDesc[outputTriggers.map.size()]; 148 Iterator it = outputTriggers.map.values().iterator(); 149 150 for (int i = 0; i < outputTriggerDescs.length; i++) 151 { 152 outputTriggerDescs[i] = new OutputTriggerDesc((OutputTrigger)it.next()); 153 } 154 155 return outputTriggerDescs; 156 } } 158 159 public String [] contractsList() throws RemoteException 160 { 161 Contracts contracts = rep.getContracts(); 162 synchronized (contracts) 163 { 164 return (String [])contracts.map.keySet().toArray(new String [contracts.map.size()]); 165 } } 167 168 public ContractDesc[] contractDescsList() throws RemoteException 169 { 170 Contracts contracts = rep.getContracts(); 171 synchronized (contracts) 172 { 173 ContractDesc[] contractDescs = new ContractDesc[contracts.map.size()]; 174 Iterator it = contracts.map.values().iterator(); 175 176 for (int i = 0; i < contractDescs.length; i++) 177 { 178 contractDescs[i] = new ContractDesc((Contract)it.next()); 179 } 180 181 return contractDescs; 182 } } 184 185 public Licence getLicence(String bundleName) throws RemoteException 186 { 187 Licences licences = rep.getLicences(); 188 return licences.getLicence(bundleName); 189 } 190 191 public void updateLicence(String bundleName, Licence licence) throws RMIAdminException, RemoteException 192 { 193 Licences licences = rep.getLicences(); 194 195 if (licence == null) 196 { 197 licences.deleteLicence(bundleName); 198 return; 199 } 200 201 synchronized (licences) 202 { 203 Licence lic = licences.getLicence(bundleName); 204 if (lic != null) 205 { 206 lic.setType(licence.getType()); 207 lic.setValidFrom(licence.getValidFrom()); 208 lic.setValidTo(licence.getValidTo()); 209 lic.setNumberOfCopies(licence.getNumberOfCopies()); 210 lic.setText(licence.getText()); 211 lic.saveToStorage(); 212 } 213 else 214 { 215 lic = licences.addLicence(bundleName, licence.getType(), licence.getNumberOfCopies(), licence.getValidFrom(), licence.getValidTo(), licence.getText()); 216 if (lic == null) throw new RMIAdminException("Cannot add Licence File for bundle '" + bundleName + "'"); 217 } 218 } } 220 221 public BundleOffer getBundleOffer(String bundleName) throws RemoteException 222 { 223 BundleOffers bundleOffers = rep.getBundleOffers(); 224 return bundleOffers.getBundleOffer(bundleName); 225 } 226 227 public void deleteBundleOffer(String bundleName) throws RemoteException 228 { 229 BundleOffers bundleOffers = rep.getBundleOffers(); 230 bundleOffers.deleteBundleOffer(bundleName); 231 } 232 233 public LocalInfo getLocalInfo(String bundleName) throws RemoteException 234 { 235 LocalInfos localInfos = rep.getLocalInfos(); 236 return localInfos.getLocalInfo(bundleName); 237 } 238 239 public BundleContent getInstalledBundleContent(String bundleName) throws RemoteException 240 { 241 BundleContents installedBundleContents = rep.getInstalledBundleContents(); 242 return installedBundleContents.getBundleContent(bundleName); 243 } 244 245 public BundleContent getSharedBundleContent(String bundleName) throws RemoteException 246 { 247 BundleContents sharedBundleContents = rep.getSharedBundleContents(); 248 return sharedBundleContents.getBundleContent(bundleName); 249 } 250 251 public void deleteComponentsFromTR(ComponentInfo[] components, boolean interfaces, boolean inferiors) throws RMIAdminException, RemoteException 252 { 253 try 254 { 255 tr.deleteComponents(components, interfaces, inferiors); 256 } 257 catch (TRException e) 258 { 259 throw new RMIAdminException(e.getMessage(), e); 260 } 261 } 262 263 public InputTrigger getInputTrigger(String name) throws RemoteException 264 { 265 InputTriggers inputTriggers = rep.getInputTriggers(); 266 return inputTriggers.getInputTrigger(name); 267 } 268 269 public void updateInputTrigger(String name, InputTrigger inputTrigger) throws RMIAdminException, RemoteException 270 { 271 InputTriggers inputTriggers = rep.getInputTriggers(); 272 273 if (inputTrigger == null) 274 { 275 inputTriggers.deleteInputTrigger(name); 276 return; 277 } 278 279 synchronized (inputTriggers) 280 { 281 InputTrigger iTrigger = inputTriggers.getInputTrigger(name); 282 if (iTrigger != null) 283 { 284 iTrigger.setSource(inputTrigger.getSource()); 285 iTrigger.setBundleType(inputTrigger.getBundleType()); 286 iTrigger.setDescription(inputTrigger.getDescription()); 287 iTrigger.setAutoDelete(inputTrigger.getAutoDelete()); 288 iTrigger.setBundleFilter(inputTrigger.getBundleFilter()); 289 iTrigger.setNodeFilter(inputTrigger.getNodeFilter()); 290 iTrigger.setValidFrom(inputTrigger.getValidFrom()); 291 iTrigger.setValidTo(inputTrigger.getValidTo()); 292 if (inputTrigger.isContract()) iTrigger.setContract(inputTrigger.getContractID(), inputTrigger.getContractRule()); 293 else iTrigger.setContract(null, null); 294 iTrigger.setActions(inputTrigger.getActions()); 295 iTrigger.setAsNoLicences(inputTrigger.getAsNoLicences()); 296 iTrigger.setAsShareGroups(inputTrigger.getAsShareGroups()); 297 iTrigger.setAsNodeFilter(inputTrigger.getAsNodeFilter()); 298 iTrigger.setAsEquality(inputTrigger.getAsEquality()); 299 iTrigger.setAlpOutputTrigger(inputTrigger.getAlpOutputTrigger()); 300 iTrigger.setApNodeNameLicList(inputTrigger.getApNodeNameLicList()); 301 iTrigger.setApoNodeNameList(inputTrigger.getApoNodeNameList()); 302 iTrigger.saveToStorage(); 303 } 304 else 305 { 306 iTrigger = inputTriggers.addInputTrigger( 307 name, 308 true, 309 inputTrigger.getSource(), 310 inputTrigger.getBundleType(), 311 inputTrigger.getDescription(), 312 inputTrigger.getAutoDelete(), 313 inputTrigger.getBundleFilter(), 314 inputTrigger.getNodeFilter(), 315 inputTrigger.getValidFrom(), 316 inputTrigger.getValidTo(), 317 inputTrigger.isContract() ? inputTrigger.getContractID() : null, 318 inputTrigger.isContract() ? inputTrigger.getContractRule() : null, 319 inputTrigger.getActions(), 320 inputTrigger.getAsNoLicences(), 321 inputTrigger.getAsShareGroups(), 322 inputTrigger.getAsNodeFilter(), 323 inputTrigger.getAsEquality(), 324 inputTrigger.getAlpOutputTrigger(), 325 inputTrigger.getApNodeNameLicList(), 326 inputTrigger.getApoNodeNameList()); 327 328 if (iTrigger == null) throw new RMIAdminException("Cannot add Input Trigger '" + name + "'"); 329 } 330 } } 332 333 public OutputTrigger getOutputTrigger(String name) throws RemoteException 334 { 335 OutputTriggers outputTriggers = rep.getOutputTriggers(); 336 return outputTriggers.getOutputTrigger(name); 337 } 338 339 public void updateOutputTrigger(String name, OutputTrigger outputTrigger) throws RMIAdminException, RemoteException 340 { 341 OutputTriggers outputTriggers = rep.getOutputTriggers(); 342 343 if (outputTrigger == null) 344 { 345 outputTriggers.deleteOutputTrigger(name); 346 return; 347 } 348 349 synchronized (outputTriggers) 350 { 351 OutputTrigger oTrigger = outputTriggers.getOutputTrigger(name); 352 if (oTrigger != null) 353 { 354 oTrigger.setDescription(outputTrigger.getDescription()); 355 oTrigger.setAutoDelete(outputTrigger.getAutoDelete()); 356 oTrigger.setBundleFilter(outputTrigger.getBundleFilter()); 357 oTrigger.setNodeFilter(outputTrigger.getNodeFilter()); 358 oTrigger.setValidFrom(outputTrigger.getValidFrom()); 359 oTrigger.setValidTo(outputTrigger.getValidTo()); 360 if (outputTrigger.isContract()) oTrigger.setContract(outputTrigger.getContractID(), outputTrigger.getContractRule()); 361 else oTrigger.setContract(null, null); 362 oTrigger.saveToStorage(); 363 } 364 else 365 { 366 oTrigger = outputTriggers.addOutputTrigger( 367 name, 368 true, 369 outputTrigger.getDescription(), 370 outputTrigger.getAutoDelete(), 371 outputTrigger.getBundleFilter(), 372 outputTrigger.getNodeFilter(), 373 outputTrigger.getValidFrom(), 374 outputTrigger.getValidTo(), 375 outputTrigger.getContractID(), 376 outputTrigger.getContractRule()); 377 378 if (oTrigger == null) throw new RMIAdminException("Cannot add Output Trigger '" + name + "'"); 379 } 380 } } 382 383 public Contract getContract(String name) throws RemoteException 384 { 385 Contracts contracts = rep.getContracts(); 386 return contracts.getContract(name); 387 } 388 389 public void updateContract(String name, Contract contract) throws RMIAdminException, RemoteException 390 { 391 Contracts contracts = rep.getContracts(); 392 393 if (contract == null) 394 { 395 contracts.deleteContract(name); 396 return; 397 } 398 399 synchronized (contracts) 400 { 401 Contract myContract = contracts.getContract(name); 402 if (myContract != null) 403 { 404 myContract.setContractID(contract.getContractID()); 405 myContract.setDescription(contract.getDescription()); 406 myContract.setAutoDelete(contract.getAutoDelete()); 407 myContract.setValidFrom(contract.getValidFrom()); 408 myContract.setValidTo(contract.getValidTo()); 409 myContract.setDefaultPushDestinationNodes(contract.getDefaultPushDestinationNodes()); 410 myContract.setDefaultPushNodeFilter(contract.getDefaultPushNodeFilter()); 411 myContract.setDefaultPullNodeFilter(contract.getDefaultPullNodeFilter()); 412 myContract.setDefaultLicenceText(contract.getDefaultLicenceText()); 413 myContract.getRules().clear(); 414 myContract.getRules().putAll(contract.getRules()); 415 myContract.saveToStorage(); 416 } 417 else 418 { 419 myContract = contracts.addContract( 420 name, 421 true, 422 contract.getDescription(), 423 contract.getAutoDelete(), 424 contract.getValidFrom(), 425 contract.getValidTo(), 426 contract.getDefaultPushDestinationNodes(), 427 contract.getDefaultPushNodeFilter(), 428 contract.getDefaultPullNodeFilter(), 429 contract.getDefaultLicenceText(), 430 contract.getRules().values()); 431 432 if (myContract == null) throw new RMIAdminException("Cannot add Contract '" + name + "'"); 433 } 434 } } 436 437 public RMISearchConfiguration getRMISearchConfiguration() throws RemoteException 438 { 439 return rmiSearchCenter.getConfiguration(); 440 } 441 public void setRMISearchConfiguration(RMISearchConfiguration configuration) throws RemoteException 442 { 443 rmiSearchCenter.setConfiguration(configuration); 444 } 445 446 public void applyRMISearchConfiguration() throws RemoteException 447 { 448 rmiSearchCenter.applyConfiguration(); 449 } 450 451 public void installBundle(String bundleName, boolean reinstall) throws RMIAdminException, RemoteException 452 { 453 try 454 { 455 localOps.installBundle(bundleName, reinstall); 456 } 457 catch (CoreException e) 458 { 459 throw new RMIAdminException(e.getMessage(), e); 460 } 461 } 462 463 public void uninstallBundle(String bundleName, boolean deleteComponents, boolean includingInterfaces, boolean force) throws RMIAdminException, RemoteException 464 { 465 try 466 { 467 localOps.uninstallBundle(bundleName, deleteComponents, includingInterfaces, force); 468 } 469 catch (CoreException e) 470 { 471 throw new RMIAdminException(e.getMessage(), e); 472 } 473 } 474 475 public void createBinaryBundle(String bundleName, boolean overwrite) throws RMIAdminException, RemoteException 476 { 477 try 478 { 479 localOps.createBinaryBundle(bundleName, overwrite); 480 } 481 catch (CoreException e) 482 { 483 throw new RMIAdminException(e.getMessage(), e); 484 } 485 } 486 487 public void deleteBinaryBundle(String bundleName) throws RMIAdminException, RemoteException 488 { 489 try 490 { 491 localOps.deleteBinaryBundle(bundleName); 492 } 493 catch (CoreException e) 494 { 495 throw new RMIAdminException(e.getMessage(), e); 496 } 497 } 498 499 public void deleteBundle(String bundleName) throws RMIAdminException, RemoteException 500 { 501 try 502 { 503 localOps.deleteBundle(bundleName); 504 } 505 catch (CoreException e) 506 { 507 throw new RMIAdminException(e.getMessage(), e); 508 } 509 } 510 511 public void createUserBundle(String bundleName, ComponentInfo[] components, boolean subcomponents) throws RMIAdminException, RemoteException 512 { 513 try 514 { 515 localOps.createUserBundle(bundleName, components, subcomponents); 516 } 517 catch (CoreException e) 518 { 519 throw new RMIAdminException(e.getMessage(), e); 520 } 521 } 522 523 public String createComponentBundle(ComponentInfo component, boolean subcomponents) throws RMIAdminException, RemoteException 524 { 525 try 526 { 527 if (subcomponents) return localOps.createCompleteComponentBundle(component); 528 else return localOps.createSingleComponentBundle(component); 529 } 530 catch (CoreException e) 531 { 532 throw new RMIAdminException(e.getMessage(), e); 533 } 534 } 535 536 public boolean testPush(String bundleName, String nodeName, boolean offer) throws RMIAdminException, RemoteException 537 { 538 try 539 { 540 return netOps.testPush(bundleName, nodeName, offer); 541 } 542 catch (CoreException e) 543 { 544 throw new RMIAdminException(e.getMessage(), e); 545 } 546 } 547 548 public boolean testPull(String bundleName, String nodeName, String contractID) throws RMIAdminException, RemoteException 549 { 550 try 551 { 552 return netOps.testPull(bundleName, nodeName, contractID); 553 } 554 catch (CoreException e) 555 { 556 throw new RMIAdminException(e.getMessage(), e); 557 } 558 } 559 560 public void pushBundle(String bundleName, String nodeName, int numberOfLicences) throws RMIAdminException, RemoteException 561 { 562 try 563 { 564 netOps.pushBundle(bundleName, nodeName, numberOfLicences); 565 } 566 catch (CoreException e) 567 { 568 throw new RMIAdminException(e.getMessage(), e); 569 } 570 } 571 572 public void pullBundle(String bundleName, String nodeName, String contractID, boolean synchro) throws RMIAdminException, RemoteException 573 { 574 try 575 { 576 if (synchro) netOps.synchroPullBundle(bundleName, nodeName, contractID); 577 else netOps.pullBundle(bundleName, nodeName, contractID); 578 } 579 catch (CoreException e) 580 { 581 throw new RMIAdminException(e.getMessage(), e); 582 } 583 } 584 585 public void pushBundleOffer(String bundleName, String nodeName) throws RMIAdminException, RemoteException 586 { 587 try 588 { 589 netOps.pushBundleOffer(bundleName, nodeName); 590 } 591 catch (CoreException e) 592 { 593 throw new RMIAdminException(e.getMessage(), e); 594 } 595 } 596 597 public void createBundleOfferFromBinBundle(String bundleName, boolean overwrite) throws RMIAdminException, RemoteException 598 { 599 try 600 { 601 netOps.createBundleOfferFromBinBundle(bundleName, overwrite); 602 } 603 catch (CoreException e) 604 { 605 throw new RMIAdminException(e.getMessage(), e); 606 } 607 } 608 609 public void generateTriggersOfContract(String contractID, boolean firstDelete) throws RMIAdminException, RemoteException 610 { 611 try 612 { 613 netOps.generateTriggersOfContract(contractID, firstDelete); 614 } 615 catch (CoreException e) 616 { 617 throw new RMIAdminException(e.getMessage(), e); 618 } 619 } 620 621 public void deleteTriggersOfContract(String contractID) throws RMIAdminException, RemoteException 622 { 623 try 624 { 625 netOps.deleteTriggersOfContract(contractID); 626 } 627 catch (CoreException e) 628 { 629 throw new RMIAdminException(e.getMessage(), e); 630 } 631 } 632 633 public void shareBundle(String bundleName, int numberOfLicences, ShareGroups shareGroups, NodeNameFilter nodeFilter, boolean equality, boolean reshare) throws RMIAdminException, RemoteException 634 { 635 try 636 { 637 shareOps.shareBundle(bundleName, numberOfLicences, shareGroups, nodeFilter, equality, reshare); 638 } 639 catch (CoreException e) 640 { 641 throw new RMIAdminException(e.getMessage(), e); 642 } 643 } 644 645 public void unshareBundle(String bundleName, boolean recoverLicences, boolean force) throws RMIAdminException, RemoteException 646 { 647 try 648 { 649 shareOps.stopSharingBundle(bundleName, recoverLicences, force); 650 } 651 catch (CoreException e) 652 { 653 throw new RMIAdminException(e.getMessage(), e); 654 } 655 } 656 657 public void acquireSharedBundle(String bundleName, String nodeName, boolean tryNoShareClient) throws RMIAdminException, RemoteException 658 { 659 try 660 { 661 shareOps.acquireSharedBundle(bundleName, nodeName, tryNoShareClient); 662 } 663 catch (CoreException e) 664 { 665 throw new RMIAdminException(e.getMessage(), e); 666 } 667 } 668 669 public void stopShareClientOfBundle(String bundleName, boolean returnLicence, boolean force) throws RMIAdminException, RemoteException 670 { 671 try 672 { 673 shareOps.stopShareClientOfBundle(bundleName, returnLicence, force); 674 } 675 catch (CoreException e) 676 { 677 throw new RMIAdminException(e.getMessage(), e); 678 } 679 } 680 681 public void makeShareClientsReturnBundle(String bundleName) throws RMIAdminException, RemoteException 682 { 683 try 684 { 685 shareOps.makeShareClientsReturnBundle(bundleName); 686 } 687 catch (CoreException e) 688 { 689 throw new RMIAdminException(e.getMessage(), e); 690 } 691 } 692 693 public SearchReplyItem[] search(SearchPattern searchPattern, boolean firstOnly, String shareGroup, int timeout) throws RMIAdminException, RemoteException 694 { 695 try 696 { 697 List replies = searchOps.search(searchPattern, firstOnly, shareGroup, timeout); 698 if (replies != null && replies.size() > 0) 699 { 700 return (SearchReplyItem[])replies.toArray(new SearchReplyItem[replies.size()]); 701 } 702 else return null; 703 } 704 catch (CoreException e) 705 { 706 throw new RMIAdminException(e.getMessage(), e); 707 } 708 } 709 710 } 711 | Popular Tags |