OpenSplice Java 5 DCPS  v6.x
OpenSplice Java 5 OpenSplice Data Distribution Service Data-Centric Publish-Subscribe API
TopicImpl.java
Go to the documentation of this file.
1 /*
2  * Vortex OpenSplice
3  *
4  * This software and documentation are Copyright 2006 to 2024 ADLINK
5  * Technology Limited, its affiliated companies and licensors. All rights
6  * reserved.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 package org.opensplice.dds.topic;
22 
23 import java.util.Collection;
24 
27 import org.omg.dds.core.status.Status;
29 import org.omg.dds.topic.Topic;
32 import org.omg.dds.topic.TopicQos;
33 import org.omg.dds.type.TypeSupport;
46 
47 public class TopicImpl<TYPE>
48  extends
49  DomainEntityImpl<DDS.Topic, DomainParticipantImpl, DDS.DomainParticipant, TopicQos, TopicListener<TYPE>, TopicListenerImpl<TYPE>>
50  implements org.opensplice.dds.topic.AbstractTopic<TYPE> {
51  private AbstractTypeSupport<TYPE> typeSupport;
52 
54  DomainParticipantImpl participant, String topicName,
55  AbstractTypeSupport<TYPE> typeSupport, TopicQos qos,
57  Collection<Class<? extends Status>> statuses) {
58  super(environment, participant, participant.getOld());
59 
60  if (qos == null) {
61  throw new IllegalArgumentExceptionImpl(this.environment,
62  "Supplied DataReaderQos is null.");
63  }
64  if (typeSupport == null) {
65  throw new IllegalArgumentExceptionImpl(this.environment,
66  "Supplied TypeSupport is null.");
67  }
68  this.typeSupport = typeSupport;
69 
70  int rc = this.typeSupport.getOldTypeSupport().register_type(
71  parent.getOld(), this.typeSupport.getTypeName());
73  rc,
74  this.environment,
75  "Registration of Type with name '"
76  + this.typeSupport.getTypeName() + "' failed.");
77  DDS.TopicQos oldQos;
78 
79  try {
80  oldQos = ((TopicQosImpl) qos).convert();
81  } catch (ClassCastException e) {
82  throw new IllegalArgumentExceptionImpl(this.environment,
83  "Cannot create Topic with non-OpenSplice qos");
84  }
85 
86  if (listener != null) {
87  this.listener = new TopicListenerImpl<TYPE>(this.environment, this,
88  listener, true);
89  } else {
90  this.listener = null;
91  }
92  DDS.Topic old = this.parent.getOld().create_topic(topicName,
93  this.typeSupport.getTypeName(), oldQos, this.listener,
94  StatusConverter.convertMask(this.environment, statuses));
95 
96  if (old == null) {
97  Utilities.throwLastErrorException(this.environment);
98  }
99  this.setOld(old);
100 
101  if (this.listener != null) {
102  this.listener.setInitialised();
103  }
104  }
105 
106  @SuppressWarnings("unchecked")
108  DomainParticipantImpl participant, String topicName, DDS.Topic old) {
109  super(environment, participant, participant.getOld());
110  this.listener = null;
111 
112  if (topicName == null) {
113  throw new IllegalArgumentExceptionImpl(this.environment,
114  "Supplied Topic name is null.");
115  }
116  if (old == null) {
117  throw new IllegalArgumentExceptionImpl(environment,
118  "Invalid <null> Topic provided.");
119  }
120  this.setOld(old);
121 
122  try {
124 
125  if ("DCPSParticipant".equals(topicName)) {
126  temp = new TypeSupportImpl<DDS.ParticipantBuiltinTopicData>(
127  this.environment,
128  DDS.ParticipantBuiltinTopicData.class, null);
129  } else if ("DCPSTopic".equals(topicName)) {
130  temp = new TypeSupportImpl<DDS.TopicBuiltinTopicData>(
131  this.environment, DDS.TopicBuiltinTopicData.class, null);
132  } else if ("CMSubscriber".equals(topicName)) {
133  temp = new TypeSupportImpl<DDS.CMSubscriberBuiltinTopicData>(
134  this.environment,
135  DDS.CMSubscriberBuiltinTopicData.class, null);
136  } else if ("CMPublisher".equals(topicName)) {
137  temp = new TypeSupportImpl<DDS.CMPublisherBuiltinTopicData>(
138  this.environment,
139  DDS.CMPublisherBuiltinTopicData.class, null);
140  } else if ("CMParticipant".equals(topicName)) {
141  temp = new TypeSupportImpl<DDS.CMParticipantBuiltinTopicData>(
142  this.environment,
143  DDS.CMParticipantBuiltinTopicData.class, null);
144  } else if ("DCPSSubscription".equals(topicName)) {
145  temp = new TypeSupportImpl<DDS.SubscriptionBuiltinTopicData>(
146  this.environment,
147  DDS.SubscriptionBuiltinTopicData.class, null);
148  } else if ("CMDataReader".equals(topicName)) {
149  temp = new TypeSupportImpl<DDS.CMDataReaderBuiltinTopicData>(
150  this.environment,
151  DDS.CMDataReaderBuiltinTopicData.class, null);
152  } else if ("DCPSPublication".equals(topicName)) {
153  temp = new TypeSupportImpl<DDS.PublicationBuiltinTopicData>(
154  this.environment,
155  DDS.PublicationBuiltinTopicData.class, null);
156  } else if ("CMDataWriter".equals(topicName)) {
157  temp = new TypeSupportImpl<DDS.CMDataWriterBuiltinTopicData>(
158  this.environment,
159  DDS.CMDataWriterBuiltinTopicData.class, null);
160  } else if ("DCPSType".equals(topicName)) {
161  temp = new TypeSupportImpl<DDS.TypeBuiltinTopicData>(
162  this.environment,
163  DDS.TypeBuiltinTopicData.class, null);
164  } else {
165  temp = null;
166  }
167  this.typeSupport = (AbstractTypeSupport<TYPE>) temp;
168  } catch (ClassCastException cce) {
169  this.typeSupport = null;
170  }
171  }
172 
173  private void setListener(TopicListener<TYPE> listener, int mask) {
174  TopicListenerImpl<TYPE> wrapperListener;
175  int rc;
176 
177  if (listener != null) {
178  wrapperListener = new TopicListenerImpl<TYPE>(this.environment,
179  this, listener);
180  } else {
181  wrapperListener = null;
182  }
183  rc = this.getOld().set_listener(wrapperListener, mask);
185  "Topic.setListener() failed.");
186 
187  this.listener = wrapperListener;
188  }
189 
190  @Override
191  public void setListener(TopicListener<TYPE> listener) {
192  this.setListener(listener, StatusConverter.getAnyMask());
193  }
194 
195  @Override
196  public void setListener(TopicListener<TYPE> listener,
197  Collection<Class<? extends Status>> statuses) {
198  this.setListener(listener,
199  StatusConverter.convertMask(this.environment, statuses));
200  }
201 
202  @Override
203  public void setListener(TopicListener<TYPE> listener,
204  Class<? extends Status>... statuses) {
205  this.setListener(listener,
206  StatusConverter.convertMask(this.environment, statuses));
207  }
208 
209  @Override
210  public TopicQos getQos() {
211  DDS.TopicQosHolder holder = new DDS.TopicQosHolder();
212  int rc = this.getOld().get_qos(holder);
214  "Topic.getQos() failed.");
215 
216  return TopicQosImpl.convert(this.environment, holder.value);
217  }
218 
219  @Override
220  public void setQos(TopicQos qos) {
221  TopicQosImpl q;
222 
223  if (qos == null) {
225  "Supplied TopicQos is null.");
226  }
227  try {
228  q = (TopicQosImpl) qos;
229  } catch (ClassCastException e) {
231  "Setting non-OpenSplice Qos not supported.");
232  }
233  int rc = this.getOld().set_qos(q.convert());
235  "Topic.setQos() failed.");
236 
237  }
238 
239  @Override
241  DDS.InconsistentTopicStatusHolder holder = new DDS.InconsistentTopicStatusHolder();
242  int rc = this.getOld().get_inconsistent_topic_status(holder);
244  "Topic.getInconsistentTopicStatus()");
245 
246  return StatusConverter.convert(this.environment, holder.value);
247  }
248 
249  @Override
251  DDS.StatusCondition oldCondition = this.getOld().get_statuscondition();
252 
253  if (oldCondition == null) {
255  }
257  oldCondition, this);
258  }
259 
260  @Override
261  protected void destroy() {
262  this.parent.destroyTopic(this);
263 
264  }
265 
266  @Override
268  if (this.typeSupport == null) {
270  "TypeSupport is unknown for this Topic. Has Topic been "
271  + "obtained using DomainParticipant.findTopic() "
272  + "maybe?");
273  }
274  return this.typeSupport;
275  }
276 
277  @SuppressWarnings("unchecked")
278  @Override
279  public <OTHER> TopicDescription<OTHER> cast() {
281 
282  try {
283  other = (TopicDescription<OTHER>) this;
284  } catch (ClassCastException cce) {
286  "Unable to perform requested cast.");
287  }
288  return other;
289  }
290 
291  @Override
292  public String getTypeName() {
293  /*
294  * Can be null in case Topic has been obtained using the findTopic
295  * method
296  */
297  if (this.typeSupport != null) {
298  return this.typeSupport.getTypeName();
299  }
300  return null;
301  }
302 
303  @Override
304  public String getName() {
305  return this.getOld().get_name();
306  }
307 
308  @Override
310  return this.parent;
311  }
312 
313  @Override
314  public void disposeAllData() {
315  int rc = this.getOld().dispose_all_data();
317  "Topic.disposeAllData() failed.");
318  }
319 
320  @Override
322  DDS.AllDataDisposedTopicStatusHolder holder = new DDS.AllDataDisposedTopicStatusHolder();
323  int rc = this.getOld().get_all_data_disposed_topic_status(holder);
325  "Topic.getAllDataDisposedTopicStatus()");
326 
327  return StatusConverter.convert(this.environment, holder.value);
328  }
329 
330 }
String getName()
Returns the name used to create the TopicDescription.
Definition: TopicImpl.java:304
The DomainParticipant object plays several roles:
A StatusCondition object is an immutable object that specifies Condition that is associated with each...
InconsistentTopicStatus getInconsistentTopicStatus()
This method allows the application to retrieve the org.omg.dds.core.status.InconsistentTopicStatus of...
Definition: TopicImpl.java:240
TypeSupport< TYPE > getTypeSupport()
Returns the org.omg.dds.type.TypeSupport used to create this TopicDescription.
Definition: TopicImpl.java:267
StatusCondition< Topic< TYPE > > getStatusCondition()
Definition: TopicImpl.java:250
static TopicQosImpl convert(OsplServiceEnvironment env, DDS.TopicQos oldQos)
static QosPolicyCount [] convert(OsplServiceEnvironment env, DDS.QosPolicyCount[] old)
TopicImpl(OsplServiceEnvironment environment, DomainParticipantImpl participant, String topicName, AbstractTypeSupport< TYPE > typeSupport, TopicQos qos, TopicListener< TYPE > listener, Collection< Class<? extends Status >> statuses)
Definition: TopicImpl.java:53
void setListener(TopicListener< TYPE > listener, Class<? extends Status >... statuses)
Definition: TopicImpl.java:203
AllDataDisposedStatus getAllDataDisposedTopicStatus()
Definition: TopicImpl.java:321
String getTypeName()
Returns the type name used to create the TopicDescription.
Definition: TopicImpl.java:292
static Set< Class<? extends Status > > convertMask(OsplServiceEnvironment environment, int state)
abstract String getTypeName()
static void checkReturnCode(int retCode, OsplServiceEnvironment environment, String message)
Definition: Utilities.java:33
Since org.omg.dds.topic.Topic is a kind of org.omg.dds.core.Entity, it has the ability to have an ass...
All instances for one or more org.omg.dds.topic.Topics have been disposed through org...
TypeSupport is an abstract interface that has to be specialized for each concrete type that will be u...
void setListener(TopicListener< TYPE > listener)
Definition: TopicImpl.java:191
static void throwLastErrorException(OsplServiceEnvironment environment)
Definition: Utilities.java:182
This interface is the base for org.omg.dds.topic.Topic, org.omg.dds.topic.ContentFilteredTopic, and org.omg.dds.topic.MultiTopic.
Topic is the most basic description of the data to be published and subscribed.
Definition: Topic.java:55
Another topic exists with the same name but different characteristics.
abstract DDS.TypeSupport getOldTypeSupport()
void setListener(TopicListener< TYPE > listener, Collection< Class<? extends Status >> statuses)
Definition: TopicImpl.java:196
Status is the abstract root class for all communication status objects.
Definition: Status.java:41