001: /*
002: * DDS (Data Distribution Service) for JacORB
003: *
004: * Copyright (C) 2005 , Ahmed yehdih <ahmed.yehdih@gmail.com>, fouad
005: * allaoui <fouad.allaoui@gmail.com>, Didier Donsez (didier.donsez@ieee.org)
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Library General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU Library General Public License for more details.
016: *
017: * You should have received a copy of the GNU Library General Public
018: * License along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
020: * 02111-1307, USA.
021: *
022: * Coontact: Ahmed yehdih <ahmed.yehdih@gmail.com>, fouad allaoui
023: * <fouad.allaoui@gmail.com>, Didier Donsez (didier.donsez@ieee.org)
024: * Contributor(s)
025: *
026: **/
027: package org.jacorb.dds;
028:
029: import java.util.Iterator;
030: import java.util.Vector;
031:
032: import org.omg.dds.ContentFilteredTopic;
033: import org.omg.dds.DomainParticipantListener;
034: import org.omg.dds.DomainParticipantPOA;
035: import org.omg.dds.DomainParticipantQos;
036: import org.omg.dds.DomainParticipantQosHolder;
037: import org.omg.dds.Duration_t;
038: import org.omg.dds.MultiTopic;
039: import org.omg.dds.Publisher;
040: import org.omg.dds.PublisherListener;
041: import org.omg.dds.PublisherQos;
042: import org.omg.dds.PublisherQosHolder;
043: import org.omg.dds.RETCODE_OK;
044: import org.omg.dds.RETCODE_PRECONDITION_NOT_MET;
045: import org.omg.dds.RETCODE_UNSUPPORTED;
046: import org.omg.dds.StatusCondition;
047: import org.omg.dds.Subscriber;
048: import org.omg.dds.SubscriberListener;
049: import org.omg.dds.SubscriberQos;
050: import org.omg.dds.SubscriberQosHolder;
051: import org.omg.dds.Topic;
052: import org.omg.dds.TopicDescription;
053: import org.omg.dds.TopicListener;
054: import org.omg.dds.TopicQos;
055: import org.omg.dds.TopicQosHolder;
056:
057: /**
058: * The DomainParticipant object plays several roles:
059: * - It acts as a container for all other Entity objects
060: * - It acts as factory for the Publisher, Subscriber, Topic and MultiTopic Entity objects.
061: * - It represents the participation of the application on a communication plane that
062: * isolates applications running on the same set of physical computers from each other.
063: * A domain establishes a 'virtual network' linking all applications that share the
064: * same domainId9 and isolating them from applications running on different domains.
065: * In this way, several independent distributed applications can coexist in the same
066: * physical network without interfering, or even being aware of each other.
067: * - It provides administration services in the domain, offering operations that allow the
068: * application to 'ignore' locally any information about a given participant
069: */
070: public class DomainParticipantImpl extends DomainParticipantPOA {
071:
072: private org.omg.CORBA.ORB orb;
073: private org.omg.PortableServer.POA poa;
074: private int domainId;
075: private org.omg.dds.DomainParticipantQos qos;
076: private org.omg.dds.DomainParticipantListener a_listener;
077: private Vector Vector_Publisher;
078: private Vector Vector_Subscriber;
079: private Vector Vector_Topic;
080:
081: /**
082: * @param domainId
083: * @param qos
084: * @param a_listener
085: */
086: public DomainParticipantImpl(int domainId,
087: org.omg.dds.DomainParticipantQos qos,
088: org.omg.dds.DomainParticipantListener a_listener) {
089:
090: this .domainId = domainId;
091: this .qos = qos;
092: this .a_listener = a_listener;
093: Vector_Publisher = new Vector();
094: Vector_Subscriber = new Vector();
095: Vector_Topic = new Vector();
096: }
097:
098: /**
099: * @param Pub
100: */
101: public void addPublisher(Publisher Pub) {
102: Vector_Publisher.add(Pub);
103: }
104:
105: /**
106: * @param Pub
107: */
108: public void deletePublisher(Publisher Pub) {
109: Vector_Publisher.remove(Pub);
110: }
111:
112: /**
113: * @param Sub
114: */
115: public void addsubscriber(Subscriber Sub) {
116: Vector_Subscriber.add(Sub);
117: }
118:
119: /**
120: * @param Sub
121: */
122: public void deleteSubscriber(Subscriber Sub) {
123: Vector_Subscriber.remove(Sub);
124: }
125:
126: /**
127: * @param Top
128: */
129: public void addTopic(Topic Top) {
130: Vector_Topic.add(Top);
131: }
132:
133: /**
134: * @param Top
135: */
136: public void deleteTopic(Topic Top) {
137: Vector_Topic.remove(Top);
138: }
139:
140: /**
141: * Sets the pOA attribute of the RepertoryImpl object
142: *
143: *@param poa The new pOA value
144: */
145: public void setPOA(org.omg.PortableServer.POA poa) {
146: this .poa = poa;
147: }
148:
149: /**
150: * Sets the oRB attribute of the RepertoryImpl object
151: *
152: *@param orb The new oRB value
153: */
154: public void setORB(org.omg.CORBA.ORB orb) {
155: this .orb = orb;
156: }
157:
158: /**
159: * @param qos
160: * @param a_listener
161: * @return
162: */
163: public Publisher create_publisher(PublisherQos qos,
164: PublisherListener a_listener) {
165: org.omg.dds.Publisher ref = null;
166: PublisherImpl impl = new PublisherImpl(qos, a_listener, _this ());
167: impl.setORB(orb);
168: impl.setPOA(poa);
169:
170: try {
171: org.omg.CORBA.Object oref = poa.servant_to_reference(impl);
172: ref = org.omg.dds.PublisherHelper.narrow(oref);
173: addPublisher(ref);
174: } catch (Exception e) {
175: }
176: return ref;
177: }
178:
179: /**
180: * @param p
181: * @return
182: */
183: public int delete_publisher(Publisher p) {
184:
185: try {
186: boolean delete_ok = ((PublisherImpl) poa
187: .reference_to_servant(p)).isDeletable();
188: if (delete_ok) {
189: deletePublisher(p);
190: } else {
191: return RETCODE_PRECONDITION_NOT_MET.value;
192: }
193: } catch (Exception e) {
194:
195: }
196:
197: return RETCODE_OK.value;
198: }
199:
200: /**
201: * @param qos
202: * @param a_listener
203: * @return
204: */
205: public Subscriber create_subscriber(SubscriberQos qos,
206: SubscriberListener a_listener) {
207:
208: org.omg.dds.Subscriber ref = null;
209: org.jacorb.dds.SubscriberImpl impl = new org.jacorb.dds.SubscriberImpl(
210: qos, a_listener, _this ());
211: impl.setORB(orb);
212: impl.setPOA(poa);
213: try {
214: org.omg.CORBA.Object oref = poa.servant_to_reference(impl);
215: ref = org.omg.dds.SubscriberHelper.narrow(oref);
216: addsubscriber(ref);
217: } catch (Exception e) {
218: }
219: return ref;
220: }
221:
222: /**
223: * @param s
224: * @return
225: */
226: public int delete_subscriber(Subscriber s) {
227:
228: try {
229: boolean delete_ok = ((SubscriberImpl) poa
230: .reference_to_servant(s)).isDeletable();
231: if (delete_ok) {
232: deleteSubscriber(s);
233: } else {
234: return RETCODE_PRECONDITION_NOT_MET.value;
235: }
236: } catch (Exception e) {
237:
238: }
239:
240: return RETCODE_OK.value;
241: }
242:
243: /**
244: * Not Implemented
245: * @return
246: */
247: public Subscriber get_builtin_subscriber() {
248: return null;
249: }
250:
251: /**
252: * @param topic_name
253: * @param type_name
254: * @param qos
255: * @param a_listener
256: * @return
257: */
258: public Topic create_topic(String topic_name, String type_name,
259: TopicQos qos, TopicListener a_listener) {
260:
261: org.omg.dds.Topic ref = null;
262: org.jacorb.dds.TopicImpl impl = new org.jacorb.dds.TopicImpl(
263: topic_name, type_name, qos, a_listener, _this ());
264: impl.setORB(orb);
265: impl.setPOA(poa);
266: try {
267: ref = (Topic) lookup_topicdescription(topic_name);
268: //not exist another topic has same name
269: if (ref == null) {
270: org.omg.CORBA.Object oref = poa
271: .servant_to_reference(impl);
272: ref = org.omg.dds.TopicHelper.narrow(oref);
273: addTopic(ref);
274: } else {
275: if (!(ref.get_type_name().equals(type_name))) {
276: ref = null;
277: }
278: }
279: } catch (Exception e) {
280: }
281:
282: return ref;
283: }
284:
285: /**
286: * @param a_topic
287: * @return
288: */
289: public int delete_topic(Topic a_topic) {
290:
291: Iterator It = Vector_Subscriber.iterator();
292: Subscriber temp;
293: while (It.hasNext()) {
294: temp = (Subscriber) It.next();
295: if (temp.lookup_datareader(a_topic.get_name()) != null) {
296:
297: return RETCODE_PRECONDITION_NOT_MET.value;
298: }
299: }
300: It = Vector_Publisher.iterator();
301: Publisher pub;
302: while (It.hasNext()) {
303: pub = (Publisher) It.next();
304: if (pub.lookup_datawriter(a_topic.get_name()) != null) {
305:
306: return RETCODE_PRECONDITION_NOT_MET.value;
307: }
308: }
309: delete_topic(a_topic);
310: return RETCODE_OK.value;
311: }
312:
313: public Topic find_topic(String topic_name, Duration_t timeout) {
314:
315: return null;
316: }
317:
318: /**
319: * @param name
320: * @return
321: */
322: public TopicDescription lookup_topicdescription(String name) {
323:
324: TopicDescription topic = null, temp;
325: Iterator Iter = Vector_Topic.iterator();
326: while (Iter.hasNext()) {
327: temp = (TopicDescription) Iter.next();
328: if (temp.get_name().equals(name))
329: topic = temp;
330: }
331:
332: return topic;
333: }
334:
335: /**
336: * Not Implemented
337: * @return
338: */
339: public ContentFilteredTopic create_contentfilteredtopic(
340: String name, Topic related_topic, String filter_expression,
341: String[] filter_parameters) {
342: return null;
343: }
344:
345: /**
346: * Not Implemented
347: * @return
348: */
349: public int delete_contentfilteredtopic(
350: ContentFilteredTopic a_contentfilteredtopic) {
351: return 0;
352: }
353:
354: /**
355: * Not Implemented
356: * @return
357: */
358: public MultiTopic create_multitopic(String name, String type_name,
359: String subscription_expression,
360: String[] expression_parameters) {
361: return null;
362: }
363:
364: /**
365: * Not Implemented
366: * @return
367: */
368: public int delete_multitopic(MultiTopic a_multitopic) {
369: return 0;
370: }
371:
372: /**
373: * Not Implemented
374: * @return
375: */
376: public int delete_contained_entities() {
377: return 0;
378: }
379:
380: /**
381: * @param qos
382: * @return
383: */
384: public int set_qos(DomainParticipantQos qos) {
385: this .qos = qos;
386: return 0;
387: }
388:
389: /**
390: * @param qos
391: */
392: public void get_qos(DomainParticipantQosHolder qos) {
393: qos.value = this .qos;
394: }
395:
396: /**
397: * @param a_listener
398: * @param mask
399: * @return
400: */
401: public int set_listener(DomainParticipantListener a_listener,
402: int mask) {
403: // TODO Auto-generated method stub
404: return 0;
405: }
406:
407: /**
408: * Not Implemented
409: * @return
410: */
411: public DomainParticipantListener get_listener() {
412: return null;
413: }
414:
415: /**
416: * Not Implemented
417: * @return
418: */
419: public int ignore_participant(int handle) {
420: return 0;
421: }
422:
423: /**
424: * Not Implemented
425: * @return
426: */
427: public int ignore_topic(int handle) {
428: return 0;
429: }
430:
431: /**
432: * Not Implemented
433: * @return
434: */
435: public int ignore_publication(int handle) {
436: return 0;
437: }
438:
439: /**
440: * Not Implemented
441: * @return
442: */
443: public int ignore_subscription(int handle) {
444: return 0;
445: }
446:
447: /**
448: * Not Implemented
449: * @return
450: */
451: public int get_domain_id() {
452: return this .domainId;
453: }
454:
455: /**
456: * Not Implemented
457: * @return
458: */
459: public void assert_liveliness() {
460: }
461:
462: /**
463: * Not Implemented
464: * @return
465: */
466: public int set_default_publisher_qos(PublisherQos qos) {
467: return 0;
468: }
469:
470: /**
471: * Not Implemented
472: * @return
473: */
474: public void get_default_publisher_qos(PublisherQosHolder qos) {
475: }
476:
477: /**
478: * Not Implemented
479: * @return
480: */
481: public int set_default_subscriber_qos(SubscriberQos qos) {
482: return 0;
483: }
484:
485: /**
486: * Not Implemented
487: * @return
488: */
489: public void get_default_subscriber_qos(SubscriberQosHolder qos) {
490: }
491:
492: /**
493: * Not Implemented
494: * @return
495: */
496: public int set_default_topic_qos(TopicQos qos) {
497: return 0;
498: }
499:
500: /**
501: * Not Implemented
502: * @return
503: */
504: public void get_default_topic_qos(TopicQosHolder qos) {
505: }
506:
507: /**
508: * Not Implemented
509: * @return
510: */
511: public int enable() {
512: return 0;
513: }
514:
515: /**
516: * Not Implemented
517: * @return
518: */
519: public StatusCondition get_statuscondition() {
520: return null;
521: }
522:
523: /**
524: * Not Implemented
525: * @return
526: */
527: public int get_status_changes() {
528: return RETCODE_UNSUPPORTED.value;
529: }
530:
531: /**
532: * @return Returns the vector_Publisher.
533: */
534: public Vector getVector_Publisher() {
535: return Vector_Publisher;
536: }
537:
538: /**
539: * @return Returns the vector_Subscriber.
540: */
541: public Vector getVector_Subscriber() {
542: return Vector_Subscriber;
543: }
544:
545: /**
546: * @return Returns the vector_Topic.
547: */
548: public Vector getVector_Topic() {
549: return Vector_Topic;
550: }
551:
552: /**
553: * @return
554: */
555: public boolean isDeletable() {
556: return getVector_Publisher().isEmpty()
557: && getVector_Subscriber().isEmpty()
558: && getVector_Topic().isEmpty();
559: }
560: }
|