OpenSplice Java 5 DCPS  v6.x
OpenSplice Java 5 OpenSplice Data Distribution Service Data-Centric Publish-Subscribe API
SampleImpl.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.sub;
22 
25 import org.omg.dds.core.Time;
26 import org.omg.dds.sub.InstanceState;
27 import org.omg.dds.sub.SampleState;
28 import org.omg.dds.sub.ViewState;
33 
34 public class SampleImpl<TYPE> implements org.opensplice.dds.sub.Sample<TYPE> {
35  private static final long serialVersionUID = 1010323161410625511L;
36  private transient OsplServiceEnvironment environment;
37  private TYPE data;
38  private DDS.SampleInfo info;
39 
40  public SampleImpl(OsplServiceEnvironment environment, TYPE data,
41  DDS.SampleInfo info) {
42  this.environment = environment;
43  this.data = data;
44  this.info = info;
45  }
46 
47  @Override
49  return this.environment;
50  }
51 
52  @Override
53  public TYPE getData() {
54  if (this.info.valid_data == false) {
55  return null;
56  }
57  return this.data;
58  }
59 
60  @Override
61  public TYPE getKeyValue() {
62  return this.data;
63  }
64 
65  public void setData(TYPE data){
66  this.data = data;
67  }
68 
69  public void setInfo(DDS.SampleInfo info){
70  this.info = info;
71  }
72 
73  public DDS.SampleInfo getInfo(){
74  return this.info;
75  }
76 
77  public void setContent(TYPE data, DDS.SampleInfo info){
78  this.data = data;
79  this.info = info;
80  }
81 
82  @Override
84  return DataStateImpl.getSampleStateFromOld(this.environment,
85  this.info.sample_state);
86  }
87 
88  @Override
90  return DataStateImpl.getViewStateFromOld(this.environment,
91  this.info.view_state);
92  }
93 
94  @Override
96  return DataStateImpl.getInstanceStateFromOld(this.environment,
97  this.info.instance_state);
98  }
99 
100  @Override
102  return Utilities.convert(this.environment, this.info.source_timestamp);
103  }
104 
105  @Override
107  return new InstanceHandleImpl(this.environment,
108  this.info.instance_handle);
109  }
110 
111  @Override
113  return new InstanceHandleImpl(this.environment,
114  this.info.publication_handle);
115  }
116 
117  @Override
119  return this.info.disposed_generation_count;
120  }
121 
122  @Override
124  return this.info.no_writers_generation_count;
125  }
126 
127  @Override
128  public int getSampleRank() {
129  return this.info.sample_rank;
130  }
131 
132  @Override
133  public int getGenerationRank() {
134  return this.info.generation_rank;
135  }
136 
137  @Override
139  return this.info.absolute_generation_rank;
140  }
141 
142  @Override
144  try {
145  @SuppressWarnings("unchecked")
146  SampleImpl<TYPE> cloned = (SampleImpl<TYPE>) super.clone();
147  cloned.environment = this.environment;
148  cloned.data = this.data;
149  cloned.info.absolute_generation_rank = this.info.absolute_generation_rank;
150  cloned.info.disposed_generation_count = this.info.disposed_generation_count;
151  cloned.info.generation_rank = this.info.generation_rank;
152  cloned.info.instance_handle = this.info.instance_handle;
153  cloned.info.no_writers_generation_count = this.info.no_writers_generation_count;
154  cloned.info.publication_handle = this.info.publication_handle;
155  cloned.info.reception_timestamp.sec = this.info.reception_timestamp.sec;
156  cloned.info.reception_timestamp.nanosec = this.info.reception_timestamp.nanosec;
157  cloned.info.sample_rank = this.info.sample_rank;
158  cloned.info.sample_state = this.info.sample_state;
159  cloned.info.source_timestamp.sec = this.info.source_timestamp.sec;
160  cloned.info.source_timestamp.nanosec = this.info.source_timestamp.nanosec;
161  cloned.info.valid_data = this.info.valid_data;
162  cloned.info.view_state = this.info.view_state;
163 
164  return cloned;
165  } catch (CloneNotSupportedException e) {
166  throw new UnsupportedOperationExceptionImpl(this.environment,
167  "Cloning of Sample not supported.");
168  }
169  }
170 }
A Sample represents an atom of data information (i.e., one value for one instance) as returned by a o...
Definition: Sample.java:116
For each instance the Data Distribution Service internally maintains an InstanceState.
ViewState getViewState()
For each instance (identified by the key), the middleware internally maintains a viewState relative t...
Definition: SampleImpl.java:89
int getGenerationRank()
The sampleRank and generationRank available in the Sample are computed based solely on the actual sam...
For each sample, the Data Distribution Service internally maintains a SampleState specific to each Da...
static DDS.Duration_t convert(OsplServiceEnvironment environment, Duration d)
Definition: Utilities.java:232
static InstanceState getInstanceStateFromOld(OsplServiceEnvironment env, int state)
Time getSourceTimestamp()
Gets the timestamp of the sample.
InstanceHandle getInstanceHandle()
Gets the InstanceHandle of the associated data Sample.
InstanceHandle getPublicationHandle()
Gets the InstanceHandle of the associated publication.
ServiceEnvironment getEnvironment()
Definition: SampleImpl.java:48
TYPE getData()
Get the data associated with this Sample, if any.
Definition: SampleImpl.java:53
int getDisposedGenerationCount()
For each instance the middleware internally maintains two counts: the disposedGenerationCount and noW...
An opaque handle that can be used to refer to a local or remote entity.
void setContent(TYPE data, DDS.SampleInfo info)
Definition: SampleImpl.java:77
static SampleState getSampleStateFromOld(OsplServiceEnvironment env, int state)
InstanceState getInstanceState()
For each instance the middleware internally maintains an instanceState.
Definition: SampleImpl.java:95
For each instance (identified by the key), the Data Distribution Service internally maintains a ViewS...
Definition: ViewState.java:26
int getAbsoluteGenerationRank()
The sampleRank and generationRank available in the Sample are computed based solely on the actual sam...
SampleImpl(OsplServiceEnvironment environment, TYPE data, DDS.SampleInfo info)
Definition: SampleImpl.java:40
int getNoWritersGenerationCount()
For each instance the middleware internally maintains two counts: the disposedGenerationCount and noW...
static ViewState getViewStateFromOld(OsplServiceEnvironment env, int state)
DDS implementations are rooted in this class, a concrete subclass of which can be instantiated based ...
SampleState getSampleState()
For each sample received, the middleware internally maintains a sampleState relative to each org...
Definition: SampleImpl.java:83
void setInfo(DDS.SampleInfo info)
Definition: SampleImpl.java:69
int getSampleRank()
The sampleRank and generationRank available in the Sample are computed based solely on the actual sam...
A moment in time expressed with nanosecond precision (though not necessarily nanosecond accuracy)...
Definition: Time.java:34