OpenSplice Java 5 DCPS  v6.x
OpenSplice Java 5 OpenSplice Data Distribution Service Data-Centric Publish-Subscribe API
ContentFilteredTopicImpl.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.Arrays;
24 import java.util.List;
25 import java.util.concurrent.atomic.AtomicInteger;
26 
30 import org.omg.dds.topic.Topic;
32 import org.omg.dds.type.TypeSupport;
39 
40 public class ContentFilteredTopicImpl<TYPE> implements
42  private final AbstractTopic<TYPE> relatedTopic;
43  private final DDS.ContentFilteredTopic old;
44  private final DomainParticipantImpl parent;
45  private final OsplServiceEnvironment environment;
46  private AtomicInteger refCount;
47 
49  DomainParticipantImpl parent, String name,
50  AbstractTopic<TYPE> relatedTopic, String filterExpression,
51  List<String> expressionParameters) {
52  this.environment = environment;
53  this.parent = parent;
54  this.relatedTopic = relatedTopic;
55  this.relatedTopic.retain();
56  this.refCount = new AtomicInteger(1);
57 
58  if (expressionParameters != null) {
59  this.old = parent.getOld().create_contentfilteredtopic(
60  name,
61  relatedTopic.getOld(),
62  filterExpression,
63  expressionParameters
64  .toArray(new String[expressionParameters.size()]));
65  } else {
66  this.old = parent.getOld().create_contentfilteredtopic(name,
67  relatedTopic.getOld(), filterExpression, null);
68  }
69 
70  if (this.old == null) {
71  Utilities.throwLastErrorException(this.environment);
72  }
73  }
74 
75  @Override
77  return this.relatedTopic.getTypeSupport();
78  }
79 
80  @SuppressWarnings("unchecked")
81  @Override
82  public <OTHER> TopicDescription<OTHER> cast() {
84 
85  try {
86  other = (TopicDescription<OTHER>) this;
87  } catch (ClassCastException cce) {
88  throw new IllegalOperationExceptionImpl(this.environment,
89  "Unable to perform requested cast.");
90  }
91  return other;
92  }
93 
94  @Override
95  public String getTypeName() {
96  return this.old.get_type_name();
97  }
98 
99  @Override
100  public String getName() {
101  return this.old.get_name();
102  }
103 
104  @Override
106  return this.parent;
107  }
108 
109  @Override
110  public void close() {
111  int newValue = this.refCount.decrementAndGet();
112 
113  if (newValue == 0) {
114  this.parent.destroyContentFilteredTopic(this);
115  } else if (newValue < 0) {
116  throw new AlreadyClosedExceptionImpl(this.environment,
117  "ContentFilteredTopic already closed.");
118  }
119  }
120 
121  @Override
123  return this.environment;
124  }
125 
126  @Override
127  public DDS.TopicDescription getOld() {
128  return this.old;
129  }
130 
131  @Override
132  public String getFilterExpression() {
133  return this.old.get_filter_expression();
134  }
135 
136  @Override
137  public List<String> getExpressionParameters() {
138  DDS.StringSeqHolder holder = new DDS.StringSeqHolder();
139  int rc = this.old.get_expression_parameters(holder);
140  Utilities.checkReturnCode(rc, this.environment,
141  "ContentFilteredTopic.getExpressionParameters() failed.");
142  return Arrays.asList(holder.value);
143  }
144 
145  @Override
146  public void setExpressionParameters(List<String> expressionParameters) {
147  if (expressionParameters == null) {
148  throw new IllegalArgumentExceptionImpl(this.environment,
149  "expressionParameters == null");
150  }
151  this.old.set_expression_parameters(expressionParameters
152  .toArray(new String[expressionParameters.size()]));
153 
154  }
155 
156  @Override
158  return this.relatedTopic;
159  }
160 
161  @Override
162  public void setExpressionParameters(String... expressionParameters) {
163  if (expressionParameters == null) {
164  throw new IllegalArgumentExceptionImpl(this.environment,
165  "expressionParameters == null");
166  }
167  this.setExpressionParameters(Arrays.asList(expressionParameters));
168  }
169 
170  @Override
171  public void retain() {
172  int newValue = this.refCount.incrementAndGet();
173 
174  if (newValue <= 0) {
175  int refCount = this.refCount.decrementAndGet();
176  throw new AlreadyClosedExceptionImpl(this.environment,
177  "ContentFilteredTopic already closed. refcount:" + refCount);
178  }
179  assert (newValue > newValue - 1);
180  assert (newValue > 1);
181  }
182 
183 }
The DomainParticipant object plays several roles:
ContentFilteredTopicImpl(OsplServiceEnvironment environment, DomainParticipantImpl parent, String name, AbstractTopic< TYPE > relatedTopic, String filterExpression, List< String > expressionParameters)
void close()
Dispose the resources held by this object.
Topic<? extends TYPE > getRelatedTopic()
The org.omg.dds.topic.Topic associated with the ContentFilteredTopic, that is, the Topic specified wh...
List< String > getExpressionParameters()
This operation returns the expression parameters associated with the ContentFilteredTopic, that is, the parameters specified on the last successful call to setExpressionParameters(List), or if setExpressionParameters(List) was never called, the parameters specified when the ContentFilteredTopic was created.
String getTypeName()
Returns the type name used to create the TopicDescription.
String getFilterExpression()
The filter expression associated with the ContentFilteredTopic, that is, the expression specified whe...
void setExpressionParameters(List< String > expressionParameters)
This operation changes the expression parameters associated with the ContentFilteredTopic.
void setExpressionParameters(String... expressionParameters)
This operation changes the expression parameters associated with the ContentFilteredTopic.
DomainParticipant getParent()
Returns the org.omg.dds.domain.DomainParticipant to which the TopicDescription belongs.
static void checkReturnCode(int retCode, OsplServiceEnvironment environment, String message)
Definition: Utilities.java:33
TypeSupport< TYPE > getTypeSupport()
Returns the org.omg.dds.type.TypeSupport used to create this TopicDescription.
String getName()
Returns the name used to create the TopicDescription.
TypeSupport is an abstract interface that has to be specialized for each concrete type that will be u...
ContentFilteredTopic is a specialization of TopicDescription that allows for content-based subscripti...
DDS implementations are rooted in this class, a concrete subclass of which can be instantiated based ...
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
void retain()
Indicates that references to this object may go out of scope but that the application expects to look...