21 package org.opensplice.dds.pub;
23 import java.lang.reflect.Field;
24 import java.lang.reflect.InvocationTargetException;
25 import java.lang.reflect.Method;
26 import java.util.HashSet;
28 import java.util.concurrent.TimeUnit;
29 import java.util.concurrent.TimeoutException;
55 private final DDS.DataWriter old;
56 private final Method registerInstance;
57 private final Method registerInstanceTimestamp;
58 private final Method unregisterInstance;
59 private final Method unregisterInstanceTimestamp;
60 private final Method write;
61 private final Method writeTimestamp;
62 private final Method dispose;
63 private final Method disposeTimestamp;
64 private final Method writeDispose;
65 private final Method writeDisposeTimestamp;
66 private final Method getKeyValue;
67 private final Method lookupInstance;
68 private final Class<?> sampleHolderClz;
69 private final Field samplHolderValueField;
72 DDS.DataWriter writer, Class<TYPE> typeClz) {
73 Class<?> typedWriterClz;
74 String typedWriterClzName;
77 this.environment = environment;
79 typedWriterClzName = typeClz.getName() +
"DataWriterImpl";
82 typedWriterClz = Class.forName(typedWriterClzName);
84 this.sampleHolderClz = Class.forName(typeClz.getName() +
"Holder");
85 this.samplHolderValueField = this.sampleHolderClz
86 .getDeclaredField(
"value");
88 this.registerInstance = typedWriterClz.getMethod(
89 "register_instance", typeClz);
90 this.registerInstanceTimestamp = typedWriterClz.getMethod(
91 "register_instance_w_timestamp", typeClz, DDS.Time_t.class);
92 this.unregisterInstance = typedWriterClz.getMethod(
93 "unregister_instance", typeClz,
long.
class);
94 this.unregisterInstanceTimestamp = typedWriterClz.getMethod(
95 "unregister_instance_w_timestamp", typeClz,
long.
class,
97 this.write = typedWriterClz.getMethod(
"write", typeClz,
long.
class);
98 this.writeTimestamp = typedWriterClz.getMethod(
"write_w_timestamp",
99 typeClz,
long.
class, DDS.Time_t.class);
100 this.dispose = typedWriterClz.getMethod(
"dispose", typeClz,
102 this.disposeTimestamp = typedWriterClz.getMethod(
103 "dispose_w_timestamp", typeClz,
long.
class,
105 this.writeDispose = typedWriterClz.getMethod(
"writedispose",
106 typeClz,
long.
class);
107 this.writeDisposeTimestamp = typedWriterClz.getMethod(
108 "writedispose_w_timestamp", typeClz,
long.
class,
110 this.getKeyValue = typedWriterClz.getMethod(
"get_key_value",
111 this.sampleHolderClz,
long.
class);
112 this.lookupInstance = typedWriterClz.getMethod(
"lookup_instance",
115 }
catch (ClassNotFoundException e) {
118 "Cannot find Typed DataWriter '" 120 +
"' that should be generated with OpenSplice idlpp");
121 }
catch (NoSuchMethodException e) {
124 "Cannot find correct methods in '" 126 +
"' that should be generated with OpenSplice idlpp ( " 127 + e.getMessage() +
").");
128 }
catch (NoSuchFieldException e) {
131 "Cannot find 'value' field in " 132 +
"the typed sampleHolderClass " 133 +
"that should be generated with OpenSplice idlpp ( " 134 + e.getMessage() +
").");
135 }
catch (SecurityException e) {
138 "Cannot find 'value' field in " 139 +
"the typed sampleHolderClass " 140 +
"that should be generated with OpenSplice idlpp ( " 141 + e.getMessage() +
").");
147 return this.environment;
151 throws TimeoutException {
154 if (instanceData == null) {
156 "Illegal instanceData (null) provided.");
159 handle = (Long) this.registerInstance
160 .invoke(this.old, instanceData);
161 }
catch (IllegalAccessException e) {
163 "DataWriter.registerInstance() failed (" + e.getMessage()
167 }
catch (IllegalArgumentException e) {
169 "DataWriter.registerInstance() failed (" + e.getMessage()
171 }
catch (InvocationTargetException e) {
173 "DataWriter.registerInstance() failed (" + e.getMessage()
180 Time sourceTimestamp)
throws TimeoutException {
183 if (instanceData == null) {
185 "Illegal instanceData (null) provided.");
188 handle = (Long) this.registerInstanceTimestamp.invoke(
this.old,
191 }
catch (IllegalAccessException e) {
193 "DataWriter.registerInstance() failed (" + e.getMessage()
197 }
catch (IllegalArgumentException e) {
199 "DataWriter.registerInstance() failed (" + e.getMessage()
201 }
catch (InvocationTargetException e) {
203 "DataWriter.registerInstance() failed (" + e.getMessage()
210 long sourceTimestamp, TimeUnit unit)
throws TimeoutException {
211 return this.registerInstance(instanceData,
new TimeImpl(
212 this.environment, sourceTimestamp, unit));
216 throws TimeoutException {
217 this.unregisterInstance(handle, null);
221 throws TimeoutException {
223 int rc = (Integer) this.unregisterInstance.invoke(
this.old,
226 "Datawriter.unregisterInstance() failed.");
227 }
catch (IllegalAccessException e) {
229 "DataWriter.unregisterInstance() failed (" + e.getMessage()
233 }
catch (IllegalArgumentException e) {
235 "DataWriter.unregisterInstance() failed (" + e.getMessage()
237 }
catch (InvocationTargetException e) {
239 "DataWriter.unregisterInstance() failed (" + e.getMessage()
245 Time sourceTimestamp)
throws TimeoutException {
247 int rc = (Integer) this.unregisterInstanceTimestamp.invoke(
248 this.old, instanceData,
252 "Datawriter.unregisterInstance() failed.");
253 }
catch (IllegalAccessException e) {
255 "DataWriter.unregisterInstance() failed (" + e.getMessage()
259 }
catch (IllegalArgumentException e) {
261 "DataWriter.unregisterInstance() failed (" + e.getMessage()
263 }
catch (InvocationTargetException e) {
265 "DataWriter.unregisterInstance() failed (" + e.getMessage()
271 long sourceTimestamp, TimeUnit unit)
throws TimeoutException {
272 this.unregisterInstance(handle, instanceData,
new TimeImpl(
273 this.environment, sourceTimestamp, unit));
277 public void write(TYPE instanceData)
throws TimeoutException {
278 this.write(instanceData, this.environment.getSPI().nilHandle());
281 public void write(TYPE instanceData,
Time sourceTimestamp)
282 throws TimeoutException {
283 this.write(instanceData, this.environment.getSPI().nilHandle(),
287 public void write(TYPE instanceData,
long sourceTimestamp, TimeUnit unit)
288 throws TimeoutException {
289 this.write(instanceData,
new TimeImpl(this.environment,
290 sourceTimestamp, unit));
295 throws TimeoutException {
297 int rc = (Integer) this.write.invoke(
this.old, instanceData,
300 "DataWriter.write() failed.");
301 }
catch (IllegalAccessException e) {
303 "DataWriter.write() failed (" + e.getMessage() +
").");
306 }
catch (IllegalArgumentException e) {
308 "DataWriter.write() failed (" + e.getMessage() +
").");
309 }
catch (InvocationTargetException e) {
311 "DataWriter.write() failed (" + e.getMessage() +
").");
316 Time sourceTimestamp)
throws TimeoutException {
318 int rc = (Integer) this.writeTimestamp.invoke(
this.old,
322 "DataWriter.write() failed.");
323 }
catch (IllegalAccessException e) {
325 "DataWriter.write() failed (" + e.getMessage() +
").");
328 }
catch (IllegalArgumentException e) {
330 "DataWriter.write() failed (" + e.getMessage() +
").");
331 }
catch (InvocationTargetException e) {
333 "DataWriter.write() failed (" + e.getMessage() +
").");
338 long sourceTimestamp, TimeUnit unit)
throws TimeoutException {
339 this.write(instanceData, handle,
new TimeImpl(this.environment,
340 sourceTimestamp, unit));
344 this.dispose(instanceHandle, null);
348 throws TimeoutException {
350 int rc = (Integer) this.dispose.invoke(
this.old, instanceData,
353 "DataWriter.dispose() failed.");
354 }
catch (IllegalAccessException e) {
356 "DataWriter.dispose() failed (" + e.getMessage() +
").");
359 }
catch (IllegalArgumentException e) {
361 "DataWriter.dispose() failed (" + e.getMessage() +
").");
362 }
catch (InvocationTargetException e) {
364 "DataWriter.dispose() failed (" + e.getMessage() +
").");
369 Time sourceTimestamp)
throws TimeoutException {
371 int rc = (Integer) this.disposeTimestamp.invoke(
this.old,
376 "DataWriter.dispose() failed.");
377 }
catch (IllegalAccessException e) {
379 "DataWriter.dispose() failed (" + e.getMessage() +
").");
382 }
catch (IllegalArgumentException e) {
384 "DataWriter.dispose() failed (" + e.getMessage() +
").");
385 }
catch (InvocationTargetException e) {
387 "DataWriter.dispose() failed (" + e.getMessage() +
").");
393 long sourceTimestamp, TimeUnit unit)
throws TimeoutException {
394 this.dispose(instanceHandle, instanceData,
new TimeImpl(
395 this.environment, sourceTimestamp, unit));
399 @SuppressWarnings(
"unchecked")
404 if (keyHolder == null) {
405 return this.getKeyValue(handle);
409 holder = this.sampleHolderClz.newInstance();
410 this.samplHolderValueField.set(holder, keyHolder);
411 int rc = (Integer) this.getKeyValue.invoke(
this.old, holder,
414 "DataWriter.getKeyValue() failed.");
415 result = (TYPE) this.samplHolderValueField.get(holder);
416 }
catch (IllegalAccessException e) {
418 "DataWriter.getKeyValue() failed (" + e.getMessage() +
").");
421 }
catch (IllegalArgumentException e) {
423 "DataWriter.getKeyValue() failed (" + e.getMessage() +
").");
424 }
catch (InvocationTargetException e) {
426 "DataWriter.getKeyValue() failed (" + e.getMessage() +
").");
427 }
catch (InstantiationException e) {
429 "DataWriter.getKeyValue() failed (" + e.getMessage() +
").");
434 @SuppressWarnings(
"unchecked")
440 holder = this.sampleHolderClz.newInstance();
441 int rc = (Integer) this.getKeyValue.invoke(
this.old, holder,
444 "DataWriter.getKeyValue() failed.");
445 result = (TYPE) this.samplHolderValueField.get(holder);
446 }
catch (IllegalAccessException e) {
448 "DataWriter.getKeyValue() failed (" + e.getMessage() +
").");
451 }
catch (IllegalArgumentException e) {
453 "DataWriter.getKeyValue() failed (" + e.getMessage() +
").");
454 }
catch (InvocationTargetException e) {
456 "DataWriter.getKeyValue() failed (" + e.getMessage() +
").");
457 }
catch (InstantiationException e) {
459 "DataWriter.getKeyValue() failed (" + e.getMessage() +
").");
467 if (keyHolder == null) {
469 "Illegal keyHolder (null) provided.");
472 long result = (Long) this.lookupInstance
473 .invoke(this.old, keyHolder);
475 }
catch (IllegalAccessException e) {
477 "DataWriter.lookupInstance() failed (" + e.getMessage()
481 }
catch (IllegalArgumentException e) {
483 "DataWriter.lookupInstance() failed (" + e.getMessage()
485 }
catch (InvocationTargetException e) {
487 "DataWriter.lookupInstance() failed (" + e.getMessage()
494 this.writeDispose(instanceData, this.environment.
getSPI().
nilHandle());
499 throws TimeoutException {
505 TimeUnit unit)
throws TimeoutException {
507 new TimeImpl(this.environment, sourceTimestamp, unit));
511 throws TimeoutException {
513 int rc = (Integer) this.writeDispose.invoke(
this.old, instanceData,
516 "DataWriter.writeDispose() failed.");
517 }
catch (IllegalAccessException e) {
519 "DataWriter.writeDispose() failed (" + e.getMessage()
523 }
catch (IllegalArgumentException e) {
525 "DataWriter.writeDispose() failed (" + e.getMessage()
527 }
catch (InvocationTargetException e) {
529 "DataWriter.writeDispose() failed (" + e.getMessage()
536 Time sourceTimestamp)
throws TimeoutException {
538 int rc = (Integer) this.writeDisposeTimestamp.invoke(
this.old,
542 "DataWriter.writeDispose() failed.");
543 }
catch (IllegalAccessException e) {
545 "DataWriter.writeDispose() failed (" + e.getMessage()
549 }
catch (IllegalArgumentException e) {
551 "DataWriter.writeDispose() failed (" + e.getMessage()
553 }
catch (InvocationTargetException e) {
555 "DataWriter.writeDispose() failed (" + e.getMessage()
561 long sourceTimestamp, TimeUnit unit)
throws TimeoutException {
562 this.writeDispose(instanceData, handle,
new TimeImpl(this.environment,
563 sourceTimestamp, unit));
568 int rc = this.old.assert_liveliness();
570 "DataWriter.assertLiveliness() failed.");
574 DDS.InstanceHandleSeqHolder holder =
new DDS.InstanceHandleSeqHolder();
575 Set<InstanceHandle> handles;
577 int rc = this.old.get_matched_subscriptions(holder);
579 "DataWriter.getMatchedSubscriptions() failed.");
581 handles =
new HashSet<InstanceHandle>();
583 for (
long handle : holder.value) {
591 DDS.SubscriptionBuiltinTopicDataHolder holder =
new DDS.SubscriptionBuiltinTopicDataHolder();
592 int rc = this.old.get_matched_subscription_data(holder,
595 "DataWriter.getMatchedSubscriptionData() failed.");
596 if (holder.value != null) {
601 "No data for this instanceHandle.");
605 DDS.DataWriterQosHolder holder =
new DDS.DataWriterQosHolder();
606 int rc = this.old.get_qos(holder);
608 "DataWriter.getQos() failed.");
618 "Supplied DataWriterQos is null.");
622 }
catch (ClassCastException e) {
624 "Setting non-OpenSplice Qos not supported.");
626 int rc = this.old.set_qos(q.
convert());
628 "DataWriter.setQos() failed.");
632 throws TimeoutException {
633 int rc = this.old.wait_for_acknowledgments(
Utilities.
convert(
this.environment,
636 "DataWriter.waitForAcknowledgments() failed.");
640 throws TimeoutException {
646 DDS.LivelinessLostStatusHolder holder =
new DDS.LivelinessLostStatusHolder();
648 int rc = this.old.get_liveliness_lost_status(holder);
650 "DataWriter.getLivelinessLostStatus() failed.");
656 DDS.OfferedDeadlineMissedStatusHolder holder =
new DDS.OfferedDeadlineMissedStatusHolder();
658 int rc = this.old.get_offered_deadline_missed_status(holder);
660 "DataWriter.getOfferedDeadlineMissedStatus() failed.");
666 DDS.OfferedIncompatibleQosStatusHolder holder =
new DDS.OfferedIncompatibleQosStatusHolder();
668 int rc = this.old.get_offered_incompatible_qos_status(holder);
670 "DataWriter.getOfferedIncompatibleQosStatus() failed.");
676 DDS.PublicationMatchedStatusHolder holder =
new DDS.PublicationMatchedStatusHolder();
678 int rc = this.old.get_publication_matched_status(holder);
680 "DataWriter.getPublicationMatchedStatus() failed.");
OfferedDeadlineMissedStatus getOfferedDeadlineMissedStatus()
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.
static void checkReturnCodeWithTimeout(int retCode, OsplServiceEnvironment environment, String message)
Set< InstanceHandle > getMatchedSubscriptions()
void writeDispose(TYPE instanceData, InstanceHandle handle)
OfferedIncompatibleQosStatus getOfferedIncompatibleQosStatus()
void waitForAcknowledgments(Duration maxWait)
InstanceHandle nilHandle()
void dispose(InstanceHandle instanceHandle)
void write(TYPE instanceData, InstanceHandle handle, long sourceTimestamp, TimeUnit unit)
static DDS.Duration_t convert(OsplServiceEnvironment environment, Duration d)
void write(TYPE instanceData, InstanceHandle handle)
ServiceEnvironment getEnvironment()
void writeDispose(TYPE instanceData, InstanceHandle handle, long sourceTimestamp, TimeUnit unit)
LivelinessLostStatus getLivelinessLostStatus()
static QosPolicyCount [] convert(OsplServiceEnvironment env, DDS.QosPolicyCount[] old)
PublicationMatchedStatus getPublicationMatchedStatus()
void write(TYPE instanceData, InstanceHandle handle, Time sourceTimestamp)
void unregisterInstance(InstanceHandle handle, TYPE instanceData)
static DataWriterQosImpl convert(OsplServiceEnvironment env, DDS.DataWriterQos oldQos)
void writeDispose(TYPE instanceData)
InstanceHandle lookupInstance(TYPE keyHolder)
void unregisterInstance(InstanceHandle handle, TYPE instanceData, Time sourceTimestamp)
The DCPSSubscription topic communicates the existence of datareaders by means of the SubscriptionBuil...
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.".
void unregisterInstance(InstanceHandle handle)
void write(TYPE instanceData, Time sourceTimestamp)
InstanceHandle registerInstance(TYPE instanceData)
An opaque handle that can be used to refer to a local or remote entity.
void writeDispose(TYPE instanceData, InstanceHandle handle, Time sourceTimestamp)
static void checkReturnCode(int retCode, OsplServiceEnvironment environment, String message)
void dispose(InstanceHandle instanceHandle, TYPE instanceData)
void waitForAcknowledgments(long maxWait, TimeUnit unit)
ServiceProviderInterface getSPI()
void dispose(InstanceHandle instanceHandle, TYPE instanceData, Time sourceTimestamp)
InstanceHandle registerInstance(TYPE instanceData, Time sourceTimestamp)
A supertype of all DDS classes and interfaces.
void writeDispose(TYPE instanceData, long sourceTimestamp, TimeUnit unit)
void setQos(DataWriterQos qos)
A org.omg.dds.core.policy.QosPolicy value was incompatible with what was requested.
SubscriptionBuiltinTopicData getMatchedSubscriptionData(InstanceHandle subscriptionHandle)
Duration newDuration(long duration, TimeUnit unit)
Construct a org.omg.dds.core.Duration of the given magnitude.
A span of elapsed time expressed with nanosecond precision.
void unregisterInstance(InstanceHandle handle, TYPE instanceData, long sourceTimestamp, TimeUnit unit)
ReflectionDataWriter(OsplServiceEnvironment environment, DDS.DataWriter writer, Class< TYPE > typeClz)
DDS implementations are rooted in this class, a concrete subclass of which can be instantiated based ...
InstanceHandle registerInstance(TYPE instanceData, long sourceTimestamp, TimeUnit unit)
void writeDispose(TYPE instanceData, Time sourceTimestamp)
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 dispose(InstanceHandle instanceHandle, TYPE instanceData, long sourceTimestamp, TimeUnit unit)
void write(TYPE instanceData, long sourceTimestamp, TimeUnit unit)
A moment in time expressed with nanosecond precision (though not necessarily nanosecond accuracy)...
void write(TYPE instanceData)