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 demo.dds.dcps.foosample;
028:
029: import org.omg.CORBA.ORB;
030: import org.omg.CosNaming.NamingContextExt;
031: import org.omg.CosNaming.NamingContextExtHelper;
032: import org.omg.dds.DataReader;
033: import org.omg.dds.DataReaderListener;
034: import org.omg.dds.DataReaderListenerHelper;
035: import org.omg.dds.DataReaderQos;
036: import org.omg.dds.DeadlineQosPolicy;
037: import org.omg.dds.DestinationOrderQosPolicyKind;
038: import org.omg.dds.DomainParticipant;
039: import org.omg.dds.DomainParticipantFactory;
040: import org.omg.dds.DomainParticipantFactoryHelper;
041: import org.omg.dds.DomainParticipantQos;
042: import org.omg.dds.DurabilityQosPolicy;
043: import org.omg.dds.DurabilityQosPolicyKind;
044: import org.omg.dds.Duration_t;
045: import org.omg.dds.EntityFactoryQosPolicy;
046: import org.omg.dds.GroupDataQosPolicy;
047: import org.omg.dds.LivelinessQosPolicyKind;
048: import org.omg.dds.PartitionQosPolicy;
049: import org.omg.dds.ReliabilityQosPolicyKind;
050: import org.omg.dds.Subscriber;
051: import org.omg.dds.SubscriberQos;
052: import org.omg.dds.TopicDataQosPolicy;
053: import org.omg.dds.TopicQos;
054: import org.omg.dds.UserDataQosPolicy;
055: import org.omg.PortableServer.POA;
056: import org.omg.PortableServer.POAHelper;
057:
058: /**
059: * Simple example : Receive a Foo data (Integer)
060: */
061: public class FooConsumer implements Runnable {
062:
063: private String[] args;
064:
065: /**
066: * @param args
067: */
068: public static void main(String[] args) {
069:
070: FooConsumer fooConsumer = new FooConsumer();
071: fooConsumer.setArgs(args);
072: new Thread(fooConsumer).start();
073: }
074:
075: /**
076: *
077: */
078: public void run() {
079: try {
080: // create and initialize the ORB
081:
082: ORB orb = ORB.init(args, null);
083: POA poa = POAHelper.narrow(orb
084: .resolve_initial_references("RootPOA"));
085: poa.the_POAManager().activate();
086: DomainParticipantFactory domainparticipantFactory;
087: DomainParticipant domainparticipant;
088: Subscriber suscriber;
089: FooDataReader foodatareader;
090: DataReader datareader;
091: org.omg.dds.Topic topic;
092: SubscriberQos suscriberqos;
093: DataReaderQos datareaderqos;
094: org.omg.CORBA.Object objRef = orb
095: .resolve_initial_references("NameService");
096: // Use NamingContextExt which is part of the Interoperable
097: // Naming Service (INS) specification.
098: NamingContextExt ncRef = NamingContextExtHelper
099: .narrow(objRef);
100:
101: // resolve the Object Reference in Naming
102: String rname = "DomainParticipantFactory";
103: byte tab[] = new byte[1];
104: tab[0] = 1;
105: org.omg.dds.UserDataQosPolicy UDQP = new UserDataQosPolicy(
106: tab);
107: DomainParticipantQos DPQOS = new DomainParticipantQos(UDQP,
108: new EntityFactoryQosPolicy());
109: domainparticipantFactory = DomainParticipantFactoryHelper
110: .narrow(ncRef.resolve_str(rname));
111: TopicQos tq = new TopicQos(new TopicDataQosPolicy(tab),
112: new DurabilityQosPolicy(DurabilityQosPolicyKind
113: .from_int(0), new Duration_t(0, 0)),
114: new DeadlineQosPolicy(new Duration_t(0, 0)),
115: new org.omg.dds.LatencyBudgetQosPolicy(
116: new Duration_t(0, 0)),
117: new org.omg.dds.LivelinessQosPolicy(
118: LivelinessQosPolicyKind.from_int(0),
119: new Duration_t(0, 0)),
120: new org.omg.dds.ReliabilityQosPolicy(
121: ReliabilityQosPolicyKind.from_int(0),
122: new Duration_t(0, 0)),
123: new org.omg.dds.DestinationOrderQosPolicy(
124: DestinationOrderQosPolicyKind.from_int(0)),
125: new org.omg.dds.HistoryQosPolicy(
126: org.omg.dds.HistoryQosPolicyKind
127: .from_int(0), 0),
128: new org.omg.dds.ResourceLimitsQosPolicy(0, 0, 0),
129: new org.omg.dds.TransportPriorityQosPolicy(0),
130: new org.omg.dds.LifespanQosPolicy(new Duration_t(0,
131: 0)), new org.omg.dds.OwnershipQosPolicy(
132: org.omg.dds.OwnershipQosPolicyKind
133: .from_int(0)));
134: domainparticipant = domainparticipantFactory
135: .create_participant(0, DPQOS, null);
136: topic = domainparticipant.create_topic("foo",
137: "demo.dds.dcps.foosample.Foo", tq, null);
138: String st[] = new String[1];
139: st[0] = "";
140: suscriberqos = new SubscriberQos(
141: new org.omg.dds.PresentationQosPolicy(
142: org.omg.dds.PresentationQosPolicyAccessScopeKind
143: .from_int(0), false, false),
144: new PartitionQosPolicy(st), new GroupDataQosPolicy(
145: tab),
146: new org.omg.dds.EntityFactoryQosPolicy(false));
147: suscriber = domainparticipant.create_subscriber(
148: suscriberqos, null);
149: datareaderqos = new DataReaderQos(new DurabilityQosPolicy(
150: DurabilityQosPolicyKind.from_int(0),
151: new Duration_t(0, 0)), new DeadlineQosPolicy(
152: new Duration_t(0, 0)),
153: new org.omg.dds.LatencyBudgetQosPolicy(
154: new Duration_t(0, 0)),
155: new org.omg.dds.LivelinessQosPolicy(
156: LivelinessQosPolicyKind.from_int(0),
157: new Duration_t(0, 0)),
158: new org.omg.dds.ReliabilityQosPolicy(
159: ReliabilityQosPolicyKind.from_int(0),
160: new Duration_t(0, 0)),
161: new org.omg.dds.DestinationOrderQosPolicy(
162: DestinationOrderQosPolicyKind.from_int(0)),
163: new org.omg.dds.HistoryQosPolicy(
164: org.omg.dds.HistoryQosPolicyKind
165: .from_int(0), 0),
166: new org.omg.dds.ResourceLimitsQosPolicy(0, 0, 0),
167: new org.omg.dds.UserDataQosPolicy(tab),
168: new org.omg.dds.TimeBasedFilterQosPolicy(
169: new Duration_t(0, 0)),
170: new org.omg.dds.ReaderDataLifecycleQosPolicy(
171: new Duration_t(0, 0)));
172: datareader = suscriber.create_datareader(topic,
173: datareaderqos, null);
174: foodatareader = FooDataReaderHelper.narrow(datareader);
175: DataReaderListener listener = DataReaderListenerHelper
176: .narrow(poa
177: .servant_to_reference(new FooDataReaderListenerImpl()));
178: foodatareader.set_listener(listener, 0);
179: orb.run();
180: } catch (Exception e) {
181: System.out.println(" ERROR : " + e);
182: e.printStackTrace();
183: }
184:
185: }
186:
187: public void end() {
188: Thread.currentThread().destroy();
189: }
190:
191: /**
192: * @param args The args to set.
193: */
194: public void setArgs(String[] args) {
195: this.args = args;
196: }
197: }
|