1 28 29 package org.objectweb.openccm.Components; 30 31 import org.objectweb.openccm.Containers.MetaInformation.ConsumerPortInstance; 32 import org.objectweb.openccm.Containers.MetaInformation.EmitterPortInstance; 33 import org.objectweb.openccm.Containers.MetaInformation.FacetPortInstance; 34 import org.objectweb.openccm.Containers.MetaInformation.PublisherPortInstance; 35 import org.objectweb.openccm.Containers.MetaInformation.ReceptaclePortInstance; 36 37 46 47 public abstract class CCMObjectImpl 48 extends org.omg.CORBA.LocalObject 49 implements org.omg.Components.CCMObjectOperations, 50 org.omg.Components.SessionContext 51 { 52 58 61 private static final int MAX_CONNECTIONS = java.lang.Integer.MAX_VALUE; 62 63 66 private boolean ready_; 67 68 71 private org.objectweb.ccm.util.Table facets_; 72 73 76 private org.objectweb.ccm.util.Table receptacles_; 77 78 81 private org.objectweb.ccm.util.Table consumers_; 82 private org.objectweb.ccm.util.Table publishers_; 83 private org.objectweb.ccm.util.Table emitters_; 84 85 86 private void trace_debug(String method, String msg) 87 { 88 System.err.println("### debug : in '" + 89 method +"' -> " + msg); 90 } 91 92 98 101 public 102 CCMObjectImpl() 103 { 104 ready_ = false; 105 106 facets_ = new org.objectweb.ccm.util.Table(); 107 receptacles_ = new org.objectweb.ccm.util.Table(); 108 consumers_ = new org.objectweb.ccm.util.Table(); 109 publishers_ = new org.objectweb.ccm.util.Table(); 110 emitters_ = new org.objectweb.ccm.util.Table(); 111 } 112 113 119 130 protected Object 131 _search_key(String key, 132 org.objectweb.ccm.util.Table table) 133 throws org.omg.Components.InvalidName 134 { 135 Object info = table.get(key); 137 138 if(info == null) 140 { 141 throw new org.omg.Components.InvalidName(); 142 } 143 144 return info; 145 } 146 147 157 protected ProvidesInfo 158 _search_facet(String facet_name) 159 throws org.omg.Components.InvalidName 160 { 161 return (ProvidesInfo)_search_key(facet_name, facets_); 163 } 164 165 175 protected UsesInfo 176 _search_receptacle(String receptacle_name) 177 throws org.omg.Components.InvalidName 178 { 179 return (UsesInfo)_search_key(receptacle_name, receptacles_); 181 } 182 183 193 protected ConsumesInfo 194 _search_consumer(String consumer_name) 195 throws org.omg.Components.InvalidName 196 { 197 return (ConsumesInfo)_search_key(consumer_name, consumers_); 199 } 200 201 211 protected PublishesInfo 212 _search_publisher(String publisher_name) 213 throws org.omg.Components.InvalidName 214 { 215 return (PublishesInfo)_search_key(publisher_name, publishers_); 217 } 218 219 229 protected EmitsInfo 230 _search_emitter(String emitter_name) 231 throws org.omg.Components.InvalidName 232 { 233 return (EmitsInfo)_search_key(emitter_name, emitters_); 235 } 236 237 245 protected void 246 _call_push(EventConsumerBaseHolder consumer, 247 java.lang.String value_name, 248 org.omg.CORBA.Any event) 249 { 250 ThreadPushEvent pusher = new ThreadPushEvent(consumer, value_name, event); 252 pusher.start(); 253 } 254 255 258 protected org.omg.Components.CCMHome 259 _home_ref() 260 { 261 return _component_servant().the_home_servant().the_home_ref(); 262 } 263 264 267 protected org.omg.Components.PrimaryKeyBase 268 _primary_key() 269 { 270 return _component_servant().the_registration_info(); 271 } 272 273 276 protected org.objectweb.openccm.Containers.ComponentServant 277 _component_servant() 278 { 279 return _the_component_executor()._component_servant(); 280 } 281 282 285 protected org.objectweb.openccm.Containers.HomeServant 286 _home_servant() 287 { 288 return _component_servant().the_home_servant(); 289 } 290 291 295 protected void 296 _declare_facet(ProvidesInfo facet) 297 { 298 299 300 org.omg.CORBA.Object ref = _component_servant().get_reference(facet.id()); 301 302 facet.facet(ref); 303 304 305 if(_component_servant().the_component_instance() != null) 306 { 307 308 FacetPortInstance _fpi = _component_servant() 309 .the_component_instance() 310 .create_facet_port_instance(facet.name()); 312 if(_fpi.type_reference() != null) 313 { 314 _fpi.object_ref(ref); _component_servant() 316 .the_component_instance() 317 .facet_port_instance_list() 318 .add_facet_port_instance(_fpi); 319 } 320 } 321 facets_.put(facet.name(), facet); 323 } 324 325 329 protected void 330 _declare_receptacle(UsesInfo rec) 331 { 332 333 335 if(_component_servant().the_component_instance() != null) 336 { 337 ReceptaclePortInstance _rpi = _component_servant() 338 .the_component_instance() 339 .create_receptacle_port_instance(rec.name()); 340 if(_rpi.type_reference() != null) 341 { 342 _component_servant() 343 .the_component_instance() 344 .receptacle_port_instance_list() 345 .add_receptacle_port_instance(_rpi); 346 } 347 } 348 349 receptacles_.put(rec.name(), rec); 350 } 351 352 356 protected void 357 _declare_consumer(ConsumesInfo sink) 358 { 359 org.omg.CORBA.Object ref = _component_servant().get_reference(sink.id()); 360 sink.consumer(org.omg.Components.EventConsumerBaseHelper.narrow(ref)); 361 consumers_.put(sink.name(), sink); 363 if (_component_servant().the_component_instance() != null) 364 { 365 ConsumerPortInstance _cpi = 366 _component_servant() 367 .the_component_instance() 368 .create_consumer_port_instance( 369 sink.name()); 370 371 if(_cpi.type_reference() != null) 372 { 373 _cpi.object_ref(ref); 374 _component_servant() 375 .the_component_instance() 376 .consumer_port_instance_list() 377 .add_consumer_port_instance(_cpi); 378 } 379 } 380 } 381 382 386 protected void 387 _declare_publisher(PublishesInfo source) 388 { 389 publishers_.put(source.name(), source); 390 if (_component_servant().the_component_instance() != null) 391 { 392 PublisherPortInstance _ppi = 393 _component_servant() 394 .the_component_instance() 395 .create_publisher_port_instance( 396 source.name()); 397 if(_ppi.type_reference() != null) 399 { 400 _component_servant() 401 .the_component_instance() 402 .publisher_port_instance_list() 403 .add_publisher_port_instance(_ppi); 404 } 405 } 406 } 407 408 412 413 protected void 414 _declare_emitter(EmitsInfo source) 415 { 416 if (_component_servant().the_component_instance() != null) 417 { 418 EmitterPortInstance _epi = 419 _component_servant() 420 .the_component_instance() 421 .create_emitter_port_instance( 422 source.name()); 423 if(_epi.type_reference() != null) 425 { 426 _component_servant() 427 .the_component_instance() 428 .emitter_port_instance_list() 429 .add_emitter_port_instance(_epi); 430 } 431 } 432 emitters_.put(source.name(), source); 433 } 434 435 441 444 public abstract org.objectweb.openccm.Containers.ComponentExecutor 445 _the_component_executor(); 446 447 453 456 public void 457 _declare_port(PortInfo port) 458 { 459 switch(port.kind()) 460 { 461 case PortInfo.pk_provides : 462 _declare_facet((ProvidesInfo)port); 463 break; 464 case PortInfo.pk_uses : 465 _declare_receptacle((UsesInfo)port); 466 break; 467 case PortInfo.pk_consumes : 468 _declare_consumer((ConsumesInfo)port); 469 break; 470 case PortInfo.pk_emits : 471 _declare_emitter((EmitsInfo)port); 472 break; 473 case PortInfo.pk_publishes : 474 _declare_publisher((PublishesInfo)port); 475 break; 476 default : 477 break; 479 } 480 } 481 482 489 public void 490 _push(String publisher_name, 491 String value_name, 492 org.omg.CORBA.Any event) 493 { 494 PublishesInfo info = null; 495 496 try 497 { 498 info = _search_publisher(publisher_name); 500 } 501 catch(org.omg.Components.InvalidName exc) 502 { 503 exc.printStackTrace(System.err); 505 return; 507 } 508 509 for(java.util.Enumeration enumeration=info.consumers().elements(); enumeration.hasMoreElements(); ) 511 { 512 _call_push(((EventConsumerBaseHolder)enumeration.nextElement()), value_name, event); 513 } 514 } 515 516 522 public void 523 _push_emitter(String emitter_name, 524 String value_name, 525 org.omg.CORBA.Any event) 526 throws org.omg.Components.InvalidName 527 { 528 EmitsInfo info = null; 529 info = _search_emitter(emitter_name); 531 532 if(info.getEventConsumerBase() != null) 534 { 535 _call_push((EventConsumerBaseHolder)info, value_name, event); 536 } 537 } 538 539 542 public org.omg.Components.Cookie 543 _connect(String name, 544 org.omg.CORBA.Object connexion) 545 throws org.omg.Components.InvalidName, 546 org.omg.Components.ExceededConnectionLimit 547 { 548 try 549 { 550 return connect(name, connexion); 551 } 552 catch(org.omg.Components.AlreadyConnected ex) 553 { 554 } 556 catch(org.omg.Components.InvalidConnection ex) 557 { 558 } 560 return null; 561 } 562 563 566 public void 567 _connect_simple_receptacle(String name, 568 org.omg.CORBA.Object connexion) 569 throws org.omg.Components.AlreadyConnected, 570 org.omg.Components.InvalidName 571 { 572 try 573 { 574 connect(name, connexion); 575 } 576 catch(org.omg.Components.ExceededConnectionLimit ex) 577 { 578 } 580 catch(org.omg.Components.InvalidConnection ex) 581 { 582 } 584 } 585 586 589 public org.omg.CORBA.Object 590 _disconnect(String receptacle_name, 591 org.omg.Components.Cookie ck) 592 throws org.omg.Components.InvalidName 593 { 594 try 595 { 596 return disconnect(receptacle_name, ck); 597 } 598 catch(org.omg.Components.NoConnection ex) 599 { 600 } 602 catch(org.omg.Components.CookieRequired ex) 603 { 604 } 606 catch(org.omg.Components.InvalidConnection ex) 607 { 608 } 610 return null; 611 } 612 613 616 public org.omg.CORBA.Object 617 _disconnect_simple_receptacle(String receptacle_name) 618 throws org.omg.Components.NoConnection, 619 org.omg.Components.InvalidName 620 { 621 try 622 { 623 return disconnect(receptacle_name, null); 624 } 625 catch(org.omg.Components.InvalidConnection ex) 626 { 627 } 629 catch(org.omg.Components.CookieRequired ex) 630 { 631 } 633 return null; 634 } 635 636 639 public org.omg.CORBA.Object 640 _get_connection_simple_receptacle(String receptacle_name) 641 throws org.omg.Components.InvalidName 642 { 643 UsesInfo info = null; 644 645 info = _search_receptacle(receptacle_name); 647 648 658 659 if(info.connections().size()==0) 661 { 662 return null; 663 } 664 665 return ((org.omg.Components.ConnectionDescription) 667 (info.connections().elements().nextElement())).objref; 668 } 669 670 673 public org.omg.Components.ConnectionDescription[] 674 _get_connections(String receptacle_name) 675 throws org.omg.Components.InvalidName 676 { 677 return get_connections(receptacle_name); 678 } 679 680 683 public org.omg.Components.Cookie 684 _subscribe(String publisher_name, 685 org.omg.Components.EventConsumerBase subscriber) 686 throws org.omg.Components.InvalidName, 687 org.omg.Components.ExceededConnectionLimit 688 { 689 try 690 { 691 return subscribe(publisher_name, subscriber); 692 } 693 catch(org.omg.Components.InvalidConnection ex) 694 { 695 } 697 return null; 698 } 699 700 703 public org.omg.Components.EventConsumerBase 704 _unsubscribe(String publisher_name, 705 org.omg.Components.Cookie ck) 706 throws org.omg.Components.InvalidName, 707 org.omg.Components.InvalidConnection 708 { 709 return unsubscribe(publisher_name, ck); 710 } 711 712 715 public org.omg.Components.EventConsumerBase[] 716 _get_subscribers(String publisher_name) 717 throws org.omg.Components.InvalidName 718 { 719 PublishesInfo info = _search_publisher(publisher_name); 720 org.omg.Components.SubscriberDescription[] connections = null; 721 org.omg.Components.EventConsumerBase[] result = null; 722 723 connections = (org.omg.Components.SubscriberDescription[])info. 724 consumers().values().toArray(new org.omg.Components.SubscriberDescription[0]); 725 result = new org.omg.Components.EventConsumerBase[connections.length]; 726 727 for (int i=0;i<result.length;i++) 728 result[i] = connections[i].consumer; 729 730 return result; 731 } 732 733 736 public void 737 _connect_emitter(String emitter_name, 738 org.omg.Components.EventConsumerBase consumer) 739 throws org.omg.Components.InvalidName, 740 org.omg.Components.AlreadyConnected 741 { 742 try 743 { 744 connect_consumer(emitter_name, consumer); 745 } 746 catch(org.omg.Components.InvalidConnection ex) 747 { 748 } 750 } 751 752 755 public org.omg.Components.EventConsumerBase 756 _disconnect_emitter(String source_name) 757 throws org.omg.Components.InvalidName, 758 org.omg.Components.NoConnection 759 { 760 return disconnect_consumer(source_name); 761 } 762 763 766 public org.omg.Components.EventConsumerBase 767 _get_emitter(String emitter_name) 768 throws org.omg.Components.InvalidName 769 { 770 EmitsInfo info = _search_emitter(emitter_name); 771 return info.consumer(); 772 } 773 774 777 public org.omg.Components.EventConsumerBase 778 _get_consumer(String sink_name) 779 throws org.omg.Components.InvalidName 780 { 781 return get_consumer(sink_name); 782 } 783 784 787 790 public synchronized void 791 wait_until_configuration_complete() 792 { 793 while(ready_ == false) 795 { 796 try 797 { 798 super.wait(); 801 } catch(Exception exc) { 802 System.err.println(exc); 804 } 805 } 806 } 807 808 810 816 829 public org.omg.CORBA.Object 830 provide_facet(String name) 831 throws org.omg.Components.InvalidName 832 { 833 return _search_facet(name).facet(); 836 } 837 838 846 public org.omg.Components.FacetDescription[] 847 get_all_facets() 848 { 849 org.omg.Components.FacetDescription result[] = new org.omg.Components.FacetDescription[facets_.size()]; 851 852 int idx = 0; 854 for(java.util.Enumeration enumeration = facets_.elements(); enumeration.hasMoreElements(); ) 855 { 856 ProvidesInfo info = (ProvidesInfo)enumeration.nextElement(); 857 result[idx++] = new FacetDescriptionImpl(info.name(), 858 info.type_id(), 859 info.facet()); 860 } 861 862 return result; 863 } 864 865 878 public org.omg.Components.FacetDescription[] 879 get_named_facets(String [] names) 880 throws org.omg.Components.InvalidName 881 { 882 org.omg.Components.FacetDescription result[] = 884 new org.omg.Components.FacetDescription[names.length]; 885 886 for(int i=0;i<names.length;i++) 888 { 889 ProvidesInfo info = _search_facet(names[i]); 891 result[i] = new FacetDescriptionImpl(info.name(), 892 info.type_id(), 893 info.facet()); 894 } 895 896 return result; 897 } 898 899 909 public boolean 910 same_component(org.omg.CORBA.Object ref) 911 { 912 int idx = 0; 914 ProvidesInfo info = null; 915 for(java.util.Enumeration enumeration = facets_.elements();enumeration.hasMoreElements(); ) 916 { 917 info = (ProvidesInfo)enumeration.nextElement(); 918 if (info.facet()._is_equivalent(ref)) 919 return true; 920 } 921 922 return false; 923 } 924 925 931 952 public org.omg.Components.Cookie 953 connect(String name, 954 org.omg.CORBA.Object connexion) 955 throws org.omg.Components.InvalidName, 956 org.omg.Components.InvalidConnection, 957 org.omg.Components.AlreadyConnected, 958 org.omg.Components.ExceededConnectionLimit 959 { 960 UsesInfo info = _search_receptacle(name); 962 963 if (!connexion._is_a(info.type_id())) 965 { 966 throw new org.omg.Components.InvalidConnection(); 967 } 968 969 int nb_connections = info.connections().size(); 970 971 if (info.simple() && nb_connections == 1) 973 { 974 throw new org.omg.Components.AlreadyConnected(); 975 } 976 977 if (!info.simple() && nb_connections >= info.limit()) 979 { 980 throw new org.omg.Components.ExceededConnectionLimit(); 981 } 982 983 CookieImpl ck = CookieImpl.generate(); 985 986 990 992 995 998 info.connections().put(ck, new ConnectionDescriptionImpl(ck, connexion)); 1000 1002 return ck; 1004 } 1005 1006 1024 public org.omg.CORBA.Object 1025 disconnect(String name, 1026 org.omg.Components.Cookie ck) 1027 throws org.omg.Components.InvalidName, 1028 org.omg.Components.InvalidConnection, 1029 org.omg.Components.CookieRequired, 1030 org.omg.Components.NoConnection 1031 { 1032 UsesInfo info = _search_receptacle(name); 1034 1035 org.omg.CORBA.Object result = null; 1036 1037 if(info.simple()) 1039 { 1040 if(info.connections().size() == 0) 1042 { 1043 throw new org.omg.Components.NoConnection(); 1044 } 1045 1046 result = ((org.omg.Components.ConnectionDescription) 1048 (info.connections().elements().nextElement())).objref; 1049 1050 info.connections().clear(); 1052 } 1053 else { 1055 if(ck == null) 1057 { 1058 throw new org.omg.Components.CookieRequired(); 1059 } 1060 1061 1062 1070 1071 org.omg.Components.ConnectionDescription cd = 1072 ((org.omg.Components.ConnectionDescription) 1073 info.connections().remove(ck)); 1074 1075 if(cd == null) 1076 { 1077 throw new org.omg.Components.InvalidConnection(); 1078 } 1079 1080 result = cd.objref; 1081 } 1082 1083 return result; 1085 } 1086 1087 1100 public org.omg.Components.ConnectionDescription[] 1101 get_connections(String name) 1102 throws org.omg.Components.InvalidName 1103 { 1104 UsesInfo info = _search_receptacle(name); 1106 1107 org.omg.Components.ConnectionDescription[] result = 1109 new org.omg.Components.ConnectionDescription[info.connections().size()]; 1110 1111 int idx = 0; 1113 for(java.util.Enumeration enumeration = info.connections().elements(); enumeration.hasMoreElements(); ) 1114 result[idx++] = (org.omg.Components.ConnectionDescription)enumeration.nextElement(); 1115 1116 return result; 1117 } 1118 1119 1126 public org.omg.Components.ReceptacleDescription[] 1127 get_all_receptacles() 1128 { 1129 org.objectweb.openccm.Containers.HomeExecutorBase home = _home_servant().the_home_executor(); 1130 1131 org.omg.Components.ReceptacleDescription[] result = 1133 new org.omg.Components.ReceptacleDescription[receptacles_.size()]; 1134 1135 int idx = 0; 1137 for(java.util.Enumeration enumeration = receptacles_.elements(); enumeration.hasMoreElements(); ) 1138 { 1139 UsesInfo info = (UsesInfo)enumeration.nextElement(); 1140 result[idx++] = new ReceptacleDescriptionImpl(info.name(), 1141 info.type_id(), 1142 !info.simple(), 1143 (org.omg.Components.ConnectionDescription[]) 1144 info.connections().values().toArray( 1145 new org.omg.Components.ConnectionDescription[0])); 1146 } 1147 1148 return result; 1149 } 1150 1151 1158 public org.omg.Components.ReceptacleDescription[] 1159 get_named_receptacles(String [] names) 1160 throws org.omg.Components.InvalidName 1161 { 1162 org.omg.Components.ReceptacleDescription result[] = 1164 new org.omg.Components.ReceptacleDescription[names.length]; 1165 1166 for(int i=0;i<names.length;i++) 1168 { 1169 UsesInfo info = _search_receptacle(names[i]); 1171 result[i] = new ReceptacleDescriptionImpl(info.name(), 1172 info.type_id(), 1173 !info.simple(), 1174 (org.omg.Components.ConnectionDescription[]) 1175 info.connections().values().toArray( 1176 new org.omg.Components.ConnectionDescription[0])); 1177 } 1178 1179 return result; 1180 } 1181 1182 1188 1201 public org.omg.Components.EventConsumerBase 1202 get_consumer(String sink_name) 1203 throws org.omg.Components.InvalidName 1204 { 1205 ConsumesInfo info = _search_consumer(sink_name); 1207 1208 return info.consumer(); 1210 } 1211 1212 1227 public org.omg.Components.Cookie 1228 subscribe(String publisher_name, 1229 org.omg.Components.EventConsumerBase subscriber) 1230 throws org.omg.Components.InvalidName, 1231 org.omg.Components.InvalidConnection, 1232 org.omg.Components.ExceededConnectionLimit 1233 { 1234 PublishesInfo info = _search_publisher(publisher_name); 1236 1237 if (!subscriber._is_a(info.type_id())) 1239 { 1240 throw new org.omg.Components.InvalidConnection(); 1241 } 1242 1243 int nb_connections = info.consumers().size(); 1244 1245 if (nb_connections >= info.limit()) 1247 { 1248 throw new org.omg.Components.ExceededConnectionLimit(); 1249 } 1250 1251 CookieImpl ck = CookieImpl.generate(); 1253 1254 1258 1263 1266 info.consumers().put(ck, new SubscriberDescriptionImpl(ck, subscriber)); 1268 1270 return ck; 1272 } 1273 1274 1290 public org.omg.Components.EventConsumerBase 1291 unsubscribe(String publisher_name, 1292 org.omg.Components.Cookie ck) 1293 throws org.omg.Components.InvalidName, 1294 org.omg.Components.InvalidConnection 1295 { 1296 PublishesInfo info = _search_publisher(publisher_name); 1298 1299 Object sd = info.consumers().remove(ck); 1301 1302 if(sd == null) 1304 { 1305 throw new org.omg.Components.InvalidConnection(); 1306 } 1307 1308 return ((org.omg.Components.SubscriberDescription)sd).consumer; 1310 } 1311 1312 1328 public void 1329 connect_consumer(String emitter_name, 1330 org.omg.Components.EventConsumerBase consumer) 1331 throws org.omg.Components.InvalidName, 1332 org.omg.Components.AlreadyConnected, 1333 org.omg.Components.InvalidConnection 1334 { 1335 EmitsInfo info = _search_emitter(emitter_name); 1337 1338 if (!consumer._is_a(info.type_id())) 1340 { 1341 throw new org.omg.Components.InvalidConnection(); 1342 } 1343 1344 if(info.consumer() != null) 1346 { 1347 throw new org.omg.Components.AlreadyConnected(); 1348 } 1349 1350 1354 1359 1362 info.consumer(consumer); 1366 } 1367 1368 1384 public org.omg.Components.EventConsumerBase 1385 disconnect_consumer(String source_name) 1386 throws org.omg.Components.InvalidName, 1387 org.omg.Components.NoConnection 1388 { 1389 EmitsInfo info = _search_emitter(source_name); 1391 1392 if(info.consumer() == null) 1394 { 1395 throw new org.omg.Components.NoConnection(); 1396 } 1397 1398 org.omg.Components.EventConsumerBase consumer = info.consumer(); 1400 1401 info.consumer(null); 1403 1404 return info.consumer(); 1406 } 1407 1408 1415 public org.omg.Components.ConsumerDescription[] 1416 get_all_consumers() 1417 { 1418 org.omg.Components.ConsumerDescription[] result = 1420 new org.omg.Components.ConsumerDescription[consumers_.size()]; 1421 1422 int idx = 0; 1424 for(java.util.Enumeration enumeration = consumers_.elements(); enumeration.hasMoreElements(); ) 1425 { 1426 ConsumesInfo info = (ConsumesInfo)enumeration.nextElement(); 1427 result[idx++] = new ConsumerDescriptionImpl(info.name(), info.type_id(), info.consumer()); 1428 } 1429 1430 return result; 1431 } 1432 1433 1440 public org.omg.Components.ConsumerDescription[] 1441 get_named_consumers(String [] names) 1442 throws org.omg.Components.InvalidName 1443 { 1444 org.omg.Components.ConsumerDescription result[] = 1446 new org.omg.Components.ConsumerDescription[names.length]; 1447 1448 for(int i=0;i<names.length;i++) 1450 { 1451 ConsumesInfo info = _search_consumer(names[i]); 1453 result[i] = new ConsumerDescriptionImpl(info.name(), info.type_id(), info.consumer()); 1454 } 1455 1456 return result; 1457 } 1458 1459 1466 public org.omg.Components.EmitterDescription[] 1467 get_all_emitters() 1468 { 1469 org.omg.Components.EmitterDescription[] result = 1471 new org.omg.Components.EmitterDescription[emitters_.size()]; 1472 1473 int idx = 0; 1475 for(java.util.Enumeration enumeration = emitters_.elements(); enumeration.hasMoreElements(); ) 1476 { 1477 EmitsInfo info = (EmitsInfo)enumeration.nextElement(); 1478 result[idx++] = new EmitterDescriptionImpl(info.name(), info.type_id(), info.consumer()); 1479 } 1480 1481 return result; 1482 } 1483 1484 1491 public org.omg.Components.EmitterDescription[] 1492 get_named_emitters(String [] names) 1493 throws org.omg.Components.InvalidName 1494 { 1495 org.omg.Components.EmitterDescription result[] = 1497 new org.omg.Components.EmitterDescription[names.length]; 1498 1499 for(int i=0;i<names.length;i++) 1501 { 1502 EmitsInfo info = _search_emitter(names[i]); 1504 result[i] = new EmitterDescriptionImpl(info.name(), info.type_id(), info.consumer()); 1505 } 1506 1507 return result; 1508 } 1509 1510 1517 public org.omg.Components.PublisherDescription[] 1518 get_all_publishers() 1519 { 1520 org.omg.Components.PublisherDescription[] result = 1522 new org.omg.Components.PublisherDescription[publishers_.size()]; 1523 1524 int idx = 0; 1526 for(java.util.Enumeration enumeration = publishers_.elements(); enumeration.hasMoreElements(); ) 1527 { 1528 PublishesInfo info = (PublishesInfo)enumeration.nextElement(); 1529 result[idx++] = new PublisherDescriptionImpl(info.name(), info.type_id(), 1530 (org.omg.Components.SubscriberDescription[]) 1531 info.consumers().values().toArray( 1532 new org.omg.Components.SubscriberDescription[0])); 1533 } 1534 1535 return result; 1536 } 1537 1538 1545 public org.omg.Components.PublisherDescription[] 1546 get_named_publishers(String [] names) 1547 throws org.omg.Components.InvalidName 1548 { 1549 org.omg.Components.PublisherDescription result[] = 1551 new org.omg.Components.PublisherDescription[names.length]; 1552 1553 for(int i=0;i<names.length;i++) 1555 { 1556 PublishesInfo info = _search_publisher(names[i]); 1558 result[i] = new PublisherDescriptionImpl(info.name(), info.type_id(), 1559 (org.omg.Components.SubscriberDescription[]) 1560 info.consumers().values().toArray( 1561 new org.omg.Components.SubscriberDescription[0])); 1562 } 1563 1564 return result; 1565 } 1566 1567 1573 1581 public org.omg.CORBA.IRObject 1582 get_component_def() 1583 { 1584 return _home_ref().get_component_def(); 1585 } 1586 1587 1595 public org.omg.Components.CCMHome 1596 get_ccm_home() 1597 { 1598 return _home_ref(); 1599 } 1600 1601 1612 public org.omg.Components.PrimaryKeyBase 1613 get_primary_key() 1614 throws org.omg.Components.NoKeyAvailable 1615 { 1616 if(_primary_key() == null) 1618 { 1619 throw new org.omg.Components.NoKeyAvailable(); 1620 } 1621 1622 return _primary_key(); 1624 } 1625 1626 1635 1638 public synchronized void 1640 configuration_complete() 1641 throws org.omg.Components.InvalidConfiguration 1642 { 1643 ready_ = true; 1647 1648 super.notifyAll(); 1650 } 1651 1652 1654 1660 public void 1661 remove() 1662 throws org.omg.Components.RemoveFailure 1663 { 1664 1672 org.omg.Components.CCMObject component_ref = _component_servant().the_component_ref(); 1674 1675 _component_servant().remove(); 1677 1678 ((CCMHomeImpl)_component_servant().the_home_servant().the_home_executor()) 1680 .unregister_component(component_ref); 1681 } 1682 1683 1689 public org.omg.Components.ComponentPortDescription 1690 get_all_ports() 1691 { 1692 return new ComponentPortDescriptionImpl(get_all_facets(), 1693 get_all_receptacles(), 1694 get_all_consumers(), 1695 get_all_emitters(), 1696 get_all_publishers()); 1697 } 1698 1699 1705 1713 public org.omg.Components.CCMHome 1714 get_CCM_home() 1715 { 1716 return _home_ref(); 1717 } 1718 1719 1727 public org.omg.CORBA.Object 1728 get_CCM_object() 1729 { 1730 return _component_servant().the_component_ref(); 1731 } 1732 1733} 1734 1735 1739class ThreadPushEvent 1740extends Thread 1741{ 1742 1748 1749 private EventConsumerBaseHolder consumer; 1750 1751 1754 private org.omg.CORBA.Any event; 1755 1756 1759 private java.lang.String value_name; 1760 1761 1767 1774 public 1775 ThreadPushEvent(EventConsumerBaseHolder consumer, 1776 java.lang.String value_name, 1777 org.omg.CORBA.Any event) 1778 { 1779 this.consumer = consumer; 1780 this.value_name = value_name; 1781 this.event = event; 1782 } 1783 1784 1790 1793 public void run() 1794 { 1795 org.omg.Components.EventConsumerBase ecb = consumer.getEventConsumerBase(); 1797 1798 org.omg.CORBA.Request request = ecb._request("push_"+value_name); 1800 1801 request.set_return_type(org.objectweb.openccm.corba.TypeCodeUtils.getTC_void()); 1803 1804 request.arguments().add_value("event", event, org.omg.CORBA.ARG_IN.value); 1806 1807 try 1808 { 1809 request.send_oneway(); 1811 1812 Exception exc = request.env().exception(); 1813 if(exc!=null) 1814 { 1815 System.err.println(exc); 1819 ecb = null; 1820 } 1821 } 1822 catch(org.omg.CORBA.SystemException exc) 1823 { 1824 System.err.println(exc); 1828 ecb = null; 1829 } 1830 1831 consumer.setEventConsumerBase(ecb); 1833 } 1834} 1835 1836 | Popular Tags |