OpenSplice Java 5 DCPS  v6.x
OpenSplice Java 5 OpenSplice Data Distribution Service Data-Centric Publish-Subscribe API
DataWriterImpl.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.pub;
22 
23 import java.util.Collection;
24 import java.util.Set;
25 import java.util.concurrent.TimeUnit;
26 import java.util.concurrent.TimeoutException;
27 
28 import org.omg.dds.core.Duration;
31 import org.omg.dds.core.Time;
36 import org.omg.dds.core.status.Status;
37 import org.omg.dds.pub.DataWriter;
39 import org.omg.dds.pub.DataWriterQos;
41 import org.omg.dds.topic.Topic;
50 
51 public class DataWriterImpl<TYPE> extends AbstractDataWriter<TYPE> {
52  private final TopicImpl<TYPE> topic;
53  private final ReflectionDataWriter<TYPE> reflectionWriter;
54 
58  Collection<Class<? extends Status>> statuses) {
59  super(environment, parent);
60  this.topic = topic;
61 
62  if (qos == null) {
63  throw new IllegalArgumentExceptionImpl(this.environment,
64  "Supplied DataWriterQos is null.");
65  }
66  if (topic == null) {
67  throw new IllegalArgumentExceptionImpl(this.environment,
68  "Supplied Topic is null.");
69  }
70  DDS.DataWriterQos oldQos;
71 
72  try {
73  oldQos = ((DataWriterQosImpl) qos).convert();
74  } catch (ClassCastException e) {
75  throw new IllegalArgumentExceptionImpl(this.environment,
76  "Cannot create DataWriter with non-OpenSplice qos");
77  }
78 
79  if (listener != null) {
80  this.listener = new DataWriterListenerImpl<TYPE>(this.environment,
81  this, listener, true);
82  } else {
83  this.listener = null;
84  }
85  DDS.DataWriter old = this.parent.getOld().create_datawriter(
86  topic.getOld(), oldQos, this.listener,
87  StatusConverter.convertMask(this.environment, statuses));
88 
89  if (old == null) {
90  Utilities.throwLastErrorException(this.environment);
91  }
92  this.setOld(old);
93  this.reflectionWriter = new ReflectionDataWriter<TYPE>(
94  this.environment, this.getOld(), this.topic.getTypeSupport()
95  .getType());
96  this.topic.retain();
97 
98  if (this.listener != null) {
99  this.listener.setInitialised();
100  }
101  }
102 
103  private void setListener(DataWriterListener<TYPE> listener, int mask) {
104  DataWriterListenerImpl<TYPE> wrapperListener;
105  int rc;
106 
107  if (listener != null) {
108  wrapperListener = new DataWriterListenerImpl<TYPE>(
109  this.environment, this, listener);
110  } else {
111  wrapperListener = null;
112  }
113  rc = this.getOld().set_listener(wrapperListener, mask);
115  "DataWriter.setListener() failed.");
116 
117  this.listener = wrapperListener;
118  }
119 
120  @Override
121  public void setListener(DataWriterListener<TYPE> listener) {
122  this.setListener(listener, StatusConverter.getAnyMask());
123  }
124 
125  @Override
126  public void setListener(DataWriterListener<TYPE> listener,
127  Collection<Class<? extends Status>> statuses) {
128  this.setListener(listener,
129  StatusConverter.convertMask(this.environment, statuses));
130  }
131 
132  @Override
133  public void setListener(DataWriterListener<TYPE> listener,
134  Class<? extends Status>... statuses) {
135  this.setListener(listener,
136  StatusConverter.convertMask(this.environment, statuses));
137  }
138 
139  @Override
141  return this.reflectionWriter.getQos();
142  }
143 
144  @Override
145  public void setQos(DataWriterQos qos) {
146  this.reflectionWriter.setQos(qos);
147  }
148 
149  @SuppressWarnings("unchecked")
150  @Override
151  public <OTHER> DataWriter<OTHER> cast() {
152  DataWriter<OTHER> other;
153  try {
154  other = (DataWriter<OTHER>) this;
155  } catch (ClassCastException cce) {
157  "Unable to perform requested cast.");
158  }
159  return other;
160  }
161 
162  @Override
164  return this.topic;
165  }
166 
167  @Override
168  public void waitForAcknowledgments(Duration maxWait)
169  throws TimeoutException {
170  this.reflectionWriter.waitForAcknowledgments(maxWait);
171  }
172 
173  @Override
174  public void waitForAcknowledgments(long maxWait, TimeUnit unit)
175  throws TimeoutException {
176  this.reflectionWriter.waitForAcknowledgments(maxWait, unit);
177  }
178 
179  @Override
181  return this.reflectionWriter.getLivelinessLostStatus();
182  }
183 
184  @Override
186  return this.reflectionWriter.getOfferedDeadlineMissedStatus();
187  }
188 
189  @Override
191  return this.reflectionWriter.getOfferedIncompatibleQosStatus();
192  }
193 
194  @Override
196  return this.reflectionWriter.getPublicationMatchedStatus();
197  }
198 
199  @Override
200  public void assertLiveliness() {
201  this.reflectionWriter.assertLiveliness();
202  }
203 
204  @Override
205  public Set<InstanceHandle> getMatchedSubscriptions() {
206  return this.reflectionWriter.getMatchedSubscriptions();
207  }
208 
209  @Override
211  InstanceHandle subscriptionHandle) {
212  return this.reflectionWriter
213  .getMatchedSubscriptionData(subscriptionHandle);
214  }
215 
216  @Override
217  public InstanceHandle registerInstance(TYPE instanceData)
218  throws TimeoutException {
219  return this.reflectionWriter.registerInstance(instanceData);
220  }
221 
222  @Override
223  public InstanceHandle registerInstance(TYPE instanceData,
224  Time sourceTimestamp) throws TimeoutException {
225  return this.reflectionWriter.registerInstance(instanceData,
226  sourceTimestamp);
227  }
228 
229  @Override
230  public InstanceHandle registerInstance(TYPE instanceData,
231  long sourceTimestamp, TimeUnit unit) throws TimeoutException {
232  return this.reflectionWriter.registerInstance(instanceData,
233  sourceTimestamp, unit);
234  }
235 
236  @Override
237  public void unregisterInstance(InstanceHandle handle)
238  throws TimeoutException {
239  this.reflectionWriter.unregisterInstance(handle);
240  }
241 
242  @Override
243  public void unregisterInstance(InstanceHandle handle, TYPE instanceData)
244  throws TimeoutException {
245  this.reflectionWriter.unregisterInstance(handle, instanceData);
246  }
247 
248  @Override
249  public void unregisterInstance(InstanceHandle handle, TYPE instanceData,
250  Time sourceTimestamp) throws TimeoutException {
251  this.reflectionWriter.unregisterInstance(handle, instanceData,
252  sourceTimestamp);
253  }
254 
255  @Override
256  public void unregisterInstance(InstanceHandle handle, TYPE instanceData,
257  long sourceTimestamp, TimeUnit unit) throws TimeoutException {
258  this.reflectionWriter.unregisterInstance(handle, instanceData,
259  sourceTimestamp, unit);
260  }
261 
262  @Override
263  public void write(TYPE instanceData) throws TimeoutException {
264  this.reflectionWriter.write(instanceData, this.environment.getSPI()
265  .nilHandle());
266  }
267 
268  @Override
269  public void write(TYPE instanceData, Time sourceTimestamp)
270  throws TimeoutException {
271  this.reflectionWriter.write(instanceData, this.environment.getSPI()
272  .nilHandle(), sourceTimestamp);
273  }
274 
275  @Override
276  public void write(TYPE instanceData, long sourceTimestamp, TimeUnit unit)
277  throws TimeoutException {
278  this.reflectionWriter.write(instanceData, new TimeImpl(
279  this.environment, sourceTimestamp, unit));
280  }
281 
282  @Override
283  public void write(TYPE instanceData, InstanceHandle handle)
284  throws TimeoutException {
285  this.reflectionWriter.write(instanceData, handle);
286  }
287 
288  @Override
289  public void write(TYPE instanceData, InstanceHandle handle,
290  Time sourceTimestamp) throws TimeoutException {
291  this.reflectionWriter.write(instanceData, handle, sourceTimestamp);
292  }
293 
294  @Override
295  public void write(TYPE instanceData, InstanceHandle handle,
296  long sourceTimestamp, TimeUnit unit) throws TimeoutException {
297  this.reflectionWriter
298  .write(instanceData, handle, sourceTimestamp, unit);
299  }
300 
301  @Override
302  public void dispose(InstanceHandle instanceHandle) throws TimeoutException {
303  this.reflectionWriter.dispose(instanceHandle, null);
304  }
305 
306  @Override
307  public void dispose(InstanceHandle instanceHandle, TYPE instanceData)
308  throws TimeoutException {
309  this.reflectionWriter.dispose(instanceHandle, instanceData);
310  }
311 
312  @Override
313  public void dispose(InstanceHandle instanceHandle, TYPE instanceData,
314  Time sourceTimestamp) throws TimeoutException {
315  this.reflectionWriter.dispose(instanceHandle, instanceData,
316  sourceTimestamp);
317  }
318 
319  @Override
320  public void dispose(InstanceHandle instanceHandle, TYPE instanceData,
321  long sourceTimestamp, TimeUnit unit) throws TimeoutException {
322  this.reflectionWriter.dispose(instanceHandle, instanceData,
323  sourceTimestamp, unit);
324  }
325 
326  @Override
327  public TYPE getKeyValue(TYPE keyHolder, InstanceHandle handle) {
328  return this.reflectionWriter.getKeyValue(keyHolder, handle);
329  }
330 
331  @Override
332  public TYPE getKeyValue(InstanceHandle handle) {
333  return this.reflectionWriter.getKeyValue(handle);
334  }
335 
336  @Override
337  public InstanceHandle lookupInstance(TYPE keyHolder) {
338  return this.reflectionWriter.lookupInstance(keyHolder);
339  }
340 
341  @Override
343  DDS.StatusCondition oldCondition = this.getOld().get_statuscondition();
344 
345  if (oldCondition == null) {
347  }
349  oldCondition, this);
350  }
351 
352  @Override
353  public void writeDispose(TYPE instanceData) throws TimeoutException {
354  this.reflectionWriter.writeDispose(instanceData);
355 
356  }
357 
358  @Override
359  public void writeDispose(TYPE instanceData, Time sourceTimestamp)
360  throws TimeoutException {
361  this.reflectionWriter.writeDispose(instanceData, sourceTimestamp);
362  }
363 
364  @Override
365  public void writeDispose(TYPE instanceData, long sourceTimestamp,
366  TimeUnit unit) throws TimeoutException {
367  this.reflectionWriter.writeDispose(instanceData, sourceTimestamp, unit);
368  }
369 
370  @Override
371  public void writeDispose(TYPE instanceData, InstanceHandle handle)
372  throws TimeoutException {
373  this.reflectionWriter.writeDispose(instanceData, handle);
374  }
375 
376  @Override
377  public void writeDispose(TYPE instanceData, InstanceHandle handle,
378  Time sourceTimestamp) throws TimeoutException {
379  this.reflectionWriter.writeDispose(instanceData, handle,
380  sourceTimestamp);
381  }
382 
383  @Override
384  public void writeDispose(TYPE instanceData, InstanceHandle handle,
385  long sourceTimestamp, TimeUnit unit) throws TimeoutException {
386  this.reflectionWriter.writeDispose(instanceData, handle,
387  sourceTimestamp, unit);
388 
389  }
390 
391  @Override
392  protected void destroy() {
393  super.destroy();
394  this.topic.close();
395  }
396 }
OfferedDeadlineMissedStatus getOfferedDeadlineMissedStatus()
SubscriptionBuiltinTopicData getMatchedSubscriptionData(InstanceHandle subscriptionHandle)
This operation retrieves information on a subscription that is currently "associated" with the DataWr...
void writeDispose(TYPE instanceData, InstanceHandle handle)
This class contains the statistics about the discovered number of org.omg.dds.sub.DataReaders that are compatible with the org.omg.dds.pub.DataWriter to which the Status is attached.
PublicationMatchedStatus getPublicationMatchedStatus()
This operation obtains the PublicationMatchedStatus object of the DataWriter.
OfferedIncompatibleQosStatus getOfferedIncompatibleQosStatus()
This operation obtains the OfferedIncompatibleQosStatus object of the DataWriter. ...
TYPE getKeyValue(InstanceHandle handle)
This operation can be used to retrieve the instance key that corresponds to an instance handle...
A StatusCondition object is an immutable object that specifies Condition that is associated with each...
OfferedIncompatibleQosStatus getOfferedIncompatibleQosStatus()
void writeDispose(TYPE instanceData, InstanceHandle handle, Time sourceTimestamp)
void dispose(InstanceHandle instanceHandle)
This operation requests the middleware to delete the data (the actual deletion is postponed until the...
void write(TYPE instanceData, Time sourceTimestamp)
This operation performs the same functions as write(Object) except that the application provides the ...
TypeSupport< TYPE > getTypeSupport()
Returns the org.omg.dds.type.TypeSupport used to create this TopicDescription.
Definition: TopicImpl.java:267
void dispose(InstanceHandle instanceHandle, TYPE instanceData)
This operation requests the middleware to delete the data (the actual deletion is postponed until the...
InstanceHandle registerInstance(TYPE instanceData, Time sourceTimestamp)
This operation performs the same function as registerInstance(Object) and can be used instead in the ...
void unregisterInstance(InstanceHandle handle, TYPE instanceData)
This operation reverses the action of registerInstance(Object).
DataWriter allows the application to set the value of the data to be published under a given org...
Definition: DataWriter.java:86
void write(TYPE instanceData, long sourceTimestamp, TimeUnit unit)
This operation performs the same functions as write(Object) except that the application provides the ...
void unregisterInstance(InstanceHandle handle, TYPE instanceData, long sourceTimestamp, TimeUnit unit)
This operation performs the same function as unregisterInstance(InstanceHandle, Object) and can be us...
TYPE getKeyValue(TYPE keyHolder, InstanceHandle handle)
This operation can be used to retrieve the instance key that corresponds to an instance handle...
void write(TYPE instanceData, InstanceHandle handle)
This operation modifies the value of a data instance.
The DCPSSubscription topic communicates the existence of datareaders by means of the SubscriptionBuil...
static Set< Class<? extends Status > > convertMask(OsplServiceEnvironment environment, int state)
The liveliness that the org.omg.dds.pub.DataWriter has committed through its org.omg.dds.core.policy.Liveliness was not respected; thus org.omg.dds.sub.DataReader entities will consider the DataWriter as no longer "active.".
Set< InstanceHandle > getMatchedSubscriptions()
This operation retrieves the list of subscriptions currently "associated" with the DataWriter; that i...
void writeDispose(TYPE instanceData, Time sourceTimestamp)
void setListener(DataWriterListener< TYPE > listener, Collection< Class<? extends Status >> statuses)
DataWriterImpl(OsplServiceEnvironment environment, PublisherImpl parent, TopicImpl< TYPE > topic, DataWriterQos qos, DataWriterListener< TYPE > listener, Collection< Class<? extends Status >> statuses)
void unregisterInstance(InstanceHandle handle)
This operation reverses the action of registerInstance(Object).
void setListener(DataWriterListener< TYPE > listener, Class<? extends Status >... statuses)
An opaque handle that can be used to refer to a local or remote entity.
void dispose(InstanceHandle instanceHandle, TYPE instanceData, long sourceTimestamp, TimeUnit unit)
This operation performs the same functions as dispose(InstanceHandle, Object) except that the applica...
static void checkReturnCode(int retCode, OsplServiceEnvironment environment, String message)
Definition: Utilities.java:33
StatusCondition< DataWriter< TYPE > > getStatusCondition()
void waitForAcknowledgments(Duration maxWait)
This operation is intended to be used only if the DataWriter has org.omg.dds.core.policy.Reliability#getKind() set to org.omg.dds.core.policy.Reliability.Kind#RELIABLE.
LivelinessLostStatus getLivelinessLostStatus()
This operation obtains the LivelinessLostStatus object of the DataWriter.
InstanceHandle registerInstance(TYPE instanceData)
This operation informs the Service that the application will be modifying a particular instance...
void dispose(InstanceHandle instanceHandle, TYPE instanceData, Time sourceTimestamp)
This operation performs the same functions as dispose(InstanceHandle, Object) except that the applica...
void writeDispose(TYPE instanceData, long sourceTimestamp, TimeUnit unit)
void assertLiveliness()
This operation manually asserts the liveliness of the DataWriter.
Since a org.omg.dds.pub.DataWriter is a kind of org.omg.dds.core.Entity, it has the ability to have a...
OfferedDeadlineMissedStatus getOfferedDeadlineMissedStatus()
This operation obtains the OfferedDeadlineMissedStatus object of the DataWriter.
void setListener(DataWriterListener< TYPE > listener)
InstanceHandle lookupInstance(TYPE keyHolder)
This operation takes as a parameter an instance and returns a handle that can be used in subsequent o...
A org.omg.dds.core.policy.QosPolicy value was incompatible with what was requested.
void write(TYPE instanceData)
This operation modifies the value of a data instance.
SubscriptionBuiltinTopicData getMatchedSubscriptionData(InstanceHandle subscriptionHandle)
A span of elapsed time expressed with nanosecond precision.
Definition: Duration.java:35
void writeDispose(TYPE instanceData, InstanceHandle handle, long sourceTimestamp, TimeUnit unit)
void write(TYPE instanceData, InstanceHandle handle, long sourceTimestamp, TimeUnit unit)
This operation performs the same function as write(Object, InstanceHandle) except that it also provid...
void write(TYPE instanceData, InstanceHandle handle, Time sourceTimestamp)
This operation performs the same function as write(Object, InstanceHandle) except that it also provid...
InstanceHandle registerInstance(TYPE instanceData, long sourceTimestamp, TimeUnit unit)
This operation performs the same function as registerInstance(Object) and can be used instead in the ...
static void throwLastErrorException(OsplServiceEnvironment environment)
Definition: Utilities.java:182
void waitForAcknowledgments(long maxWait, TimeUnit unit)
This operation is intended to be used only if the DataWriter has org.omg.dds.core.policy.Reliability#getKind() set to org.omg.dds.core.policy.Reliability.Kind#RELIABLE.
Topic is the most basic description of the data to be published and subscribed.
Definition: Topic.java:55
The deadline that the org.omg.dds.pub.DataWriter has committed through its org.omg.dds.core.policy.Deadline was not respected for a specific instance.
void unregisterInstance(InstanceHandle handle, TYPE instanceData, Time sourceTimestamp)
This operation performs the same function as unregisterInstance(InstanceHandle, Object) and can be us...
A moment in time expressed with nanosecond precision (though not necessarily nanosecond accuracy)...
Definition: Time.java:34
Status is the abstract root class for all communication status objects.
Definition: Status.java:41