21 package org.opensplice.dds.sub;
23 import java.lang.reflect.Array;
24 import java.lang.reflect.Field;
25 import java.util.ArrayList;
26 import java.util.List;
33 import DDS.SampleInfo;
34 import DDS.SampleInfoSeqHolder;
38 private final Class<?> dataSeqHolderClaz;
39 private final Class<TYPE> dataClaz;
40 private final Field dataSeqHolderValueField;
42 private SampleInfoSeqHolder infoSeqHolder;
43 private Object dataSeqHolder;
44 private List<Sample<TYPE>> sampleList;
45 private int lastLength;
48 Class<?> dataSeqHolderClaz, Field dataSeqHolderValueField,
50 this.environment = environment;
51 this.sampleList = preAllocated;
52 this.dataSeqHolderClaz = dataSeqHolderClaz;
53 this.dataClaz = dataClaz;
54 this.dataSeqHolderValueField = dataSeqHolderValueField;
62 if (preAllocated == null) {
63 this.sampleList =
new ArrayList<Sample<TYPE>>();
64 this.infoSeqHolder =
new SampleInfoSeqHolder();
65 this.dataSeqHolder = dataSeqHolderClaz.newInstance();
66 }
else if (preAllocated == this.sampleList) {
67 if (this.lastLength != preAllocated.size()) {
68 if (this.lastLength == -1) {
69 this.infoSeqHolder =
new SampleInfoSeqHolder();
70 this.dataSeqHolder = dataSeqHolderClaz.newInstance();
72 this.infoSeqHolder.value =
new SampleInfo[preAllocated
74 this.dataSeqHolderValueField.set(this.dataSeqHolder,
75 Array.newInstance(dataClaz, preAllocated.size()));
79 this.sampleList = preAllocated;
80 this.infoSeqHolder =
new SampleInfoSeqHolder();
81 this.dataSeqHolder = dataSeqHolderClaz.newInstance();
84 this.lastLength = this.sampleList.size();
85 }
catch (InstantiationException e) {
87 + e.getMessage() +
").");
88 }
catch (IllegalAccessException e) {
90 + e.getMessage() +
").");
91 }
catch (ClassCastException ce) {
93 "Usage of non-OpenSplice Sample implementation is not supported.");
97 private void copyData() {
101 this.infoSeqHolder.value =
new SampleInfo[this.sampleList.size()];
102 this.dataSeqHolderValueField.set(this.dataSeqHolder,
103 Array.newInstance(dataClaz,
this.sampleList.size()));
104 Object dataValue = this.dataSeqHolderValueField
105 .get(this.dataSeqHolder);
110 Array.set(dataValue, i++, sample.getData());
112 }
catch (IllegalAccessException e) {
114 + e.getMessage() +
").");
115 }
catch (ClassCastException ce) {
117 "Usage of non-OpenSplice Sample implementation is not supported.");
123 this.updateReferencesImproved();
126 @SuppressWarnings(
"unchecked")
127 private void updateReferencesImproved() {
130 assert (this.lastLength == this.sampleList.size());
132 if (this.infoSeqHolder.value.length >
this.lastLength) {
134 Object dataValue = this.dataSeqHolderValueField
135 .get(this.dataSeqHolder);
136 index = this.lastLength;
138 while (index < this.infoSeqHolder.value.length) {
141 (TYPE)Array.get(dataValue, index),
142 this.infoSeqHolder.value[index]));
145 }
catch (IllegalArgumentException e) {
147 + e.getMessage() +
").");
148 }
catch (IllegalAccessException e) {
150 + e.getMessage() +
").");
152 }
else if (this.infoSeqHolder.value.length <
this.lastLength) {
153 index = this.infoSeqHolder.value.length;
154 int curLength = this.lastLength;
156 while (index < curLength) {
157 this.sampleList.remove(index);
161 this.lastLength = this.sampleList.size();
166 return this.dataSeqHolder;
171 return this.infoSeqHolder;
176 return this.sampleList;
Object getDataSeqHolder()
SampleInfoSeqHolder getInfoSeqHolder()
A Sample represents an atom of data information (i.e., one value for one instance) as returned by a o...
List< Sample< TYPE > > getSampleList()
PreAllocatorImpl(OsplServiceEnvironment environment, Class<?> dataSeqHolderClaz, Field dataSeqHolderValueField, Class< TYPE > dataClaz, List< Sample< TYPE >> preAllocated)
void setSampleList(List< Sample< TYPE >> preAllocated)