1 31 package org.objectweb.proactive.core.group; 32 33 34 import java.util.Iterator ; 35 36 import org.apache.log4j.Logger; 37 import org.objectweb.proactive.ActiveObjectCreationException; 38 import org.objectweb.proactive.ProActive; 39 import org.objectweb.proactive.core.body.future.FutureProxy; 40 import org.objectweb.proactive.core.descriptor.data.VirtualNode; 41 import org.objectweb.proactive.core.mop.ClassNotReifiableException; 42 import org.objectweb.proactive.core.mop.ConstructionOfProxyObjectFailedException; 43 import org.objectweb.proactive.core.mop.ConstructionOfReifiedObjectFailedException; 44 import org.objectweb.proactive.core.mop.InvalidProxyClassException; 45 import org.objectweb.proactive.core.mop.MOP; 46 import org.objectweb.proactive.core.mop.Proxy; 47 import org.objectweb.proactive.core.mop.StubObject; 48 import org.objectweb.proactive.core.node.Node; 49 import org.objectweb.proactive.core.node.NodeException; 50 import org.objectweb.proactive.core.node.NodeFactory; 51 52 53 54 73 public class ProActiveGroup { 74 75 76 protected static Logger logger = Logger.getLogger(ProActiveGroup.class.getName()); 77 78 79 80 public static final Class DEFAULT_PROXYFORGROUP_CLASS = org.objectweb.proactive.core.group.ProxyForGroup.class; 81 82 83 public static final String DEFAULT_PROXYFORGROUP_CLASS_NAME = "org.objectweb.proactive.core.group.ProxyForGroup"; 84 85 86 87 private ProActiveGroup () {} 88 89 90 91 96 public static Group getGroup(Object o) { 97 return ProActiveGroup.findProxyForGroup(o); 98 } 99 100 106 public static String getType (Object o) { 107 ProxyForGroup tmp = ProActiveGroup.findProxyForGroup(o); 108 if (tmp != null) 109 return tmp.getTypeName(); 110 else 111 return o.getClass().getName(); 112 } 113 114 115 122 public static Object newGroup(String className) throws ClassNotFoundException , ClassNotReifiableException { 123 124 MOP.checkClassIsReifiable(MOP.forName(className)); 125 126 Object result = null; 127 128 try { 129 result = MOP.newInstance (className, null, DEFAULT_PROXYFORGROUP_CLASS_NAME, null); 130 131 ProxyForGroup proxy = (org.objectweb.proactive.core.group.ProxyForGroup)((StubObject)result).getProxy(); 132 proxy.className = className; 133 proxy.stub = (StubObject)result; 134 } 135 catch (ClassNotReifiableException e) { 136 logger.error("**** ClassNotReifiableException ****"); } 137 catch (InvalidProxyClassException e) { 138 logger.error("**** InvalidProxyClassException ****"); } 139 catch (ConstructionOfProxyObjectFailedException e) { 140 logger.error("**** ConstructionOfProxyObjectFailedException ****"); } 141 catch (ConstructionOfReifiedObjectFailedException e) { 142 logger.error("**** ConstructionOfReifiedObjectFailedException ****"); } 143 144 return result; 145 } 146 147 148 149 160 public static Object newGroup(String className, Object [][] params) 161 throws ClassNotFoundException , ClassNotReifiableException, ActiveObjectCreationException, NodeException { 162 163 Node[] nodeList = new Node[1]; 164 nodeList[0] = NodeFactory.getDefaultNode(); 165 166 return ProActiveGroup.newGroup(className, params, nodeList); 167 } 168 169 170 181 public static Object newGroup(String className, Object [][] params, String nodeName) 182 throws ClassNotFoundException , ClassNotReifiableException, ActiveObjectCreationException, NodeException { 183 Node[] nodeList = new Node[1]; 184 nodeList[0] = NodeFactory.getNode(nodeName); 185 return ProActiveGroup.newGroup(className, params, nodeList); 186 } 187 188 189 190 201 public static Object newGroup(String className, Object [][] params, String [] nodeListString) 202 throws ClassNotFoundException , ClassNotReifiableException, ActiveObjectCreationException, NodeException { 203 Node[] nodeList = new Node[nodeListString.length]; 204 for (int i = 0 ; i < nodeListString.length ; i++) 205 nodeList[i] = NodeFactory.getNode(nodeListString[i]); 206 return ProActiveGroup.newGroup(className, params, nodeList); 207 } 208 209 220 public static Object newGroup(String className, Object [][] params, Node node) 221 throws ClassNotFoundException , ClassNotReifiableException, ActiveObjectCreationException, NodeException { 222 Node[] nodeList = new Node[1]; 223 nodeList[0] = node; 224 return ProActiveGroup.newGroup(className, params, nodeList); 225 } 226 227 228 240 public static Object newGroup(String className, Object [][] params, Node[] nodeList) 241 throws ClassNotFoundException , ClassNotReifiableException, ActiveObjectCreationException, NodeException { 242 243 Object result = ProActiveGroup.newGroup(className); 244 Group g = ProActiveGroup.getGroup(result); 245 246 if (params != null) { 247 for (int i=0 ; i < params.length ; i++) { 248 g.add(ProActive.newActive(className, params[i], nodeList[i % nodeList.length])); 249 } 250 } 251 252 return result; 253 254 255 } 256 268 public static Object newGroup(String className, Object [][] params, VirtualNode virtualNode) 269 throws ClassNotFoundException , ClassNotReifiableException, ActiveObjectCreationException, NodeException { 270 return ProActiveGroup.newGroup(className,params,virtualNode.getNodes()); 271 } 272 273 274 284 public static Object turnActiveGroup(Object ogroup) 285 throws ClassNotFoundException , ClassNotReifiableException, ActiveObjectCreationException, NodeException { 286 return ProActive.turnActive(ogroup, ProActiveGroup.getType(ogroup), (Node) null, null, null); 287 } 288 289 290 301 public static Object turnActiveGroup(Object ogroup, Node node) 302 throws ClassNotFoundException , ClassNotReifiableException, ActiveObjectCreationException, NodeException { 303 return ProActive.turnActive(ogroup, ProActiveGroup.getType(ogroup), node, null, null); 304 } 305 306 307 317 public static Object turnActiveGroup(Object ogroup, String nodeName) 318 throws ClassNotFoundException , ClassNotReifiableException, ActiveObjectCreationException, NodeException { 319 return ProActive.turnActive(ogroup, ProActiveGroup.getType(ogroup), NodeFactory.getNode(nodeName), null, null); 320 } 321 322 333 public static Object newGroupBuildWithMultithreading(String className, Object [][] params) 334 throws ClassNotFoundException , ClassNotReifiableException, ActiveObjectCreationException, NodeException { 335 336 Node[] nodeList = new Node[1]; 337 nodeList[0] = NodeFactory.getDefaultNode(); 338 339 return ProActiveGroup.newGroupBuildWithMultithreading(className, params, nodeList); 340 } 341 342 343 355 public static Object newGroupBuildWithMultithreading(String className, Object [][] params, Node[] nodeList) 356 throws ClassNotFoundException , ClassNotReifiableException, ActiveObjectCreationException, NodeException { 357 String [] nodeListString = new String [nodeList.length]; 358 for (int i = 0 ; i < nodeList.length ; i++) 359 nodeListString[i] = nodeList[i].getNodeInformation().getURL(); 360 return ProActiveGroup.newGroupBuildWithMultithreading(className, params, nodeListString); 361 } 362 363 364 377 public static Object newGroupBuildWithMultithreading(String className, Object [][] params, String [] nodeList) 378 throws ClassNotFoundException , ClassNotReifiableException, ActiveObjectCreationException, NodeException { 379 380 Object result = ProActiveGroup.newGroup(className); 381 ProxyForGroup proxy = (org.objectweb.proactive.core.group.ProxyForGroup) ProActiveGroup.getGroup(result); 382 383 proxy.createMemberWithMultithread(className, params, nodeList); 384 385 return result; 386 387 388 } 389 402 public static Object newGroupBuildWithMultithreading(String className, Object [][] params, VirtualNode virtualNode) 403 throws ClassNotFoundException , ClassNotReifiableException, ActiveObjectCreationException, NodeException { 404 return ProActiveGroup.newGroupBuildWithMultithreading(className, params, virtualNode.getNodes()); 405 } 406 407 408 413 public static Object captureView (Object ogroup) { 414 Object result = null; 415 416 try { 417 result = ProActiveGroup.newGroup(ProActiveGroup.getType(ogroup)); 418 } catch (ClassNotReifiableException e) { 419 logger.error("**** ClassNotReifiableException ****"); 420 e.printStackTrace(); 421 } catch (ClassNotFoundException e) { 422 logger.error("**** ClassNotFoundException ****"); 423 e.printStackTrace(); 424 } 425 426 Group go = ProActiveGroup.getGroup(ogroup); 427 Group gr = ProActiveGroup.getGroup(result); 428 429 Iterator it = go.iterator(); 430 while (it.hasNext()) { 431 gr.add(it.next()); 432 } 433 434 return result; 435 } 436 437 441 public static void waitAll(Object o) { 442 if (MOP.isReifiedObject (o)) { 443 org.objectweb.proactive.core.mop.Proxy theProxy = ProActiveGroup.findProxyForGroup(o); 444 if (theProxy != null) 446 ((org.objectweb.proactive.core.group.ProxyForGroup)theProxy).waitAll(); 447 } 449 } 450 451 452 453 457 public static void waitOne(Object o) { 458 if (MOP.isReifiedObject (o)) { 459 org.objectweb.proactive.core.mop.Proxy theProxy = ProActiveGroup.findProxyForGroup(o); 460 if (theProxy != null) 462 ((org.objectweb.proactive.core.group.ProxyForGroup)theProxy).waitOne(); 463 } 465 } 466 467 468 469 474 public static void waitN(Object o, int n) { 475 if (MOP.isReifiedObject (o)) { 476 org.objectweb.proactive.core.mop.Proxy theProxy = ProActiveGroup.findProxyForGroup(o); 477 if (theProxy != null) 479 ((org.objectweb.proactive.core.group.ProxyForGroup)theProxy).waitN(n); 480 } 482 } 483 484 485 486 492 public static boolean allAwaited (Object o) { 493 if (!(MOP.isReifiedObject (o))) 495 return false; 496 else { 497 org.objectweb.proactive.core.mop.Proxy theProxy = ProActiveGroup.findProxyForGroup(o); 498 if (theProxy != null) 500 return ((org.objectweb.proactive.core.group.ProxyForGroup)theProxy).allAwaited(); 501 else 503 return false; 504 } 505 } 506 507 508 514 public static boolean allArrived (Object o) { 515 if (!(MOP.isReifiedObject (o))) 517 return true; 518 else { 519 org.objectweb.proactive.core.mop.Proxy theProxy = ProActiveGroup.findProxyForGroup(o); 520 if (theProxy != null) 522 return ((org.objectweb.proactive.core.group.ProxyForGroup)theProxy).allArrived(); 523 else 525 return true; 526 } 527 } 528 529 530 535 public static Object waitAndGetOne (Object o) { 536 if (MOP.isReifiedObject (o)) { 537 org.objectweb.proactive.core.mop.Proxy theProxy = ProActiveGroup.findProxyForGroup(o); 538 if (theProxy != null) 540 return ((org.objectweb.proactive.core.group.ProxyForGroup)theProxy).waitAndGetOne(); 541 else 543 return o; 544 } 545 else 547 return o; 548 } 549 550 551 555 public static void waitTheNth (Object o, int n) { 556 if (MOP.isReifiedObject (o)) { 557 org.objectweb.proactive.core.mop.Proxy theProxy = ProActiveGroup.findProxyForGroup(o); 558 if (theProxy != null) 560 ((org.objectweb.proactive.core.group.ProxyForGroup)theProxy).waitTheNth(n); 561 } 563 } 564 565 566 572 public static Object waitAndGetTheNth (Object o, int n) { 573 if (MOP.isReifiedObject (o)) { 574 org.objectweb.proactive.core.mop.Proxy theProxy = ProActiveGroup.findProxyForGroup(o); 575 if (theProxy != null) 577 return ((org.objectweb.proactive.core.group.ProxyForGroup)theProxy).waitAndGetTheNth(n); 578 else 580 return o; 581 } 582 else 584 return o; 585 } 586 587 592 public int waitOneAndGetIndex(Object o) { 593 if (MOP.isReifiedObject (o)) { 594 org.objectweb.proactive.core.mop.Proxy theProxy = ProActiveGroup.findProxyForGroup(o); 595 if (theProxy != null) 597 return ((org.objectweb.proactive.core.group.ProxyForGroup)theProxy).waitOneAndGetIndex(); 598 else 600 return 0; 601 } 602 else 604 return -1; 605 } 606 607 608 614 public static int size (Object o) { 615 org.objectweb.proactive.core.mop.Proxy theProxy = ProActiveGroup.findProxyForGroup(o); 616 if (theProxy == null) 617 throw new java.lang.IllegalArgumentException ("Parameter doesn't represent a group"); 618 else 619 return ((org.objectweb.proactive.core.group.ProxyForGroup)theProxy).size(); 620 } 621 622 623 630 public static Object get (Object o, int n) { 631 org.objectweb.proactive.core.mop.Proxy theProxy = ProActiveGroup.findProxyForGroup(o); 632 if (theProxy == null) { 633 return null; 634 } 635 else { 636 return ((org.objectweb.proactive.core.group.ProxyForGroup)theProxy).get(n); 637 } 638 } 639 640 641 646 public static boolean isGroup (Object o) { 647 return (ProActiveGroup.findProxyForGroup(o) != null); 648 } 649 650 654 public static void setScatterGroup(Object ogroup) { 655 Proxy proxytmp = ProActiveGroup.findProxyForGroup(ogroup); 656 if (proxytmp != null) 657 ((ProxyForGroup)proxytmp).setDispatchingOn(); 658 } 659 660 664 public static void unsetScatterGroup(Object ogroup) { 665 Proxy proxytmp = ProActiveGroup.findProxyForGroup(ogroup); 666 if (proxytmp != null) 667 ((ProxyForGroup)proxytmp).setDispatchingOff(); 668 } 669 670 674 public static void setUniqueSerialization(Object ogroup) { 675 Proxy proxytmp = ProActiveGroup.findProxyForGroup(ogroup); 676 if (proxytmp != null) 677 ((ProxyForGroup)proxytmp).setUniqueSerializationOn(); 678 } 679 680 684 public static void unsetUniqueSerialization(Object ogroup) { 685 Proxy proxytmp = ProActiveGroup.findProxyForGroup(ogroup); 686 if (proxytmp != null) 687 ((ProxyForGroup)proxytmp).setUniqueSerializationOff(); 688 } 689 690 691 696 public static boolean isScatterGroupOn (Object ogroup) { 697 Proxy proxytmp = ProActiveGroup.findProxyForGroup(ogroup); 698 if (proxytmp != null) 699 return ((ProxyForGroup)proxytmp).isDispatchingOn(); 700 else return false; 701 } 702 703 709 private static ProxyForGroup findProxyForGroup(Object ogroup) { 710 if (!(MOP.isReifiedObject(ogroup))) 711 return null; 712 else { 713 Proxy tmp = ((StubObject)ogroup).getProxy(); 714 715 if (tmp instanceof org.objectweb.proactive.core.group.ProxyForGroup) 717 return (org.objectweb.proactive.core.group.ProxyForGroup) tmp; 718 719 while (tmp instanceof org.objectweb.proactive.core.body.future.FutureProxy) 721 if (MOP.isReifiedObject(((FutureProxy)tmp).getResult())) 723 tmp = ((StubObject)((FutureProxy)tmp).getResult()).getProxy(); 724 else 726 return null; 727 728 if (tmp instanceof org.objectweb.proactive.core.group.ProxyForGroup) 730 return (org.objectweb.proactive.core.group.ProxyForGroup) tmp; 731 else 733 return null; 734 } 735 } 736 737 738 } 739 | Popular Tags |