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