OpenSplice Java 5 DCPS  v6.x
OpenSplice Java 5 OpenSplice Data Distribution Service Data-Centric Publish-Subscribe API
EntityQosImpl.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.core;
22 
23 import java.util.Collection;
24 import java.util.HashMap;
25 import java.util.Map;
26 import java.util.Set;
27 
28 import org.omg.dds.core.EntityQos;
32 
33 public abstract class EntityQosImpl<T extends QosPolicy> implements
34  EntityQos<T> {
35  private static final long serialVersionUID = -5714560284083338546L;
37  protected HashMap<Class<? extends T>, T> policies;
38 
40  Collection<T> policies) {
41  this.environment = environment;
42  this.policies = new HashMap<Class<? extends T>, T>();
43  this.setupPolicies(policies);
44  this.setupMissingPolicies();
45  }
46 
47  public EntityQosImpl(OsplServiceEnvironment environment, T... policies) {
48  this.environment = environment;
49  this.policies = new HashMap<Class<? extends T>, T>();
50  this.setupPolicies(policies);
51  this.setupMissingPolicies();
52  }
53 
54  protected void setupPolicies(Collection<T> policies) {
55  synchronized(this.policies) {
56  for (T p : policies) {
57  this.policies.put(this.getClassIdForPolicy(p), p);
58  }
59  }
60  }
61 
62  protected void setupPolicies(T... policies) {
63  synchronized(this.policies) {
64  for (T p : policies) {
65  this.policies.put(this.getClassIdForPolicy(p), p);
66  }
67  }
68  }
69 
70  @SuppressWarnings("unchecked")
71  protected Class<? extends T> getClassIdForPolicy(T policy) {
72  Class<?>[] interfaces = policy.getClass().getInterfaces();
73 
74  if (interfaces.length == 0) {
75  throw new IllegalArgumentExceptionImpl(this.environment,
76  "Provided policy not a valid policy.");
77  }
78  /*
79  * Ensure extended policies in OpenSplice are still stored using the OMG
80  * class if it exists (as some policies are OpenSplice only, not all of
81  * them have a OMG parent).
82  */
83  if (interfaces[0].getName().startsWith(
84  "org.opensplice.dds.core.policy.")) {
85  Class<?>[] superInterfaces = interfaces[0].getInterfaces();
86 
87  if (superInterfaces.length != 0) {
88  if (!superInterfaces[0].getName().startsWith(
89  "org.omg.dds.core.policy.QosPolicy")) {
90  return (Class<? extends T>) (superInterfaces[0]);
91  }
92  }
93  }
94  return (Class<? extends T>) interfaces[0];
95  }
96 
97  @Override
99  return this.environment;
100  }
101 
102  @Override
103  public void clear() {
104  synchronized (this.policies) {
105  this.policies.clear();
106  this.setupMissingPolicies();
107  }
108  }
109 
110  @Override
111  public boolean containsKey(Object arg0) {
112  synchronized (this.policies) {
113  return this.policies.containsKey(arg0);
114  }
115  }
116 
117  @Override
118  public boolean containsValue(Object arg0) {
119  synchronized (this.policies) {
120  return this.policies.containsValue(arg0);
121  }
122  }
123 
124  @Override
125  public Set<java.util.Map.Entry<Class<? extends T>, T>> entrySet() {
126  synchronized (this.policies) {
127  return this.policies.entrySet();
128  }
129  }
130 
131  @Override
132  public T get(Object arg0) {
133  synchronized (this.policies) {
134  return this.policies.get(arg0);
135  }
136  }
137 
138  @Override
139  public boolean isEmpty() {
140  return false;
141  }
142 
143  @Override
144  public Set<Class<? extends T>> keySet() {
145  synchronized (this.policies) {
146  return this.policies.keySet();
147  }
148  }
149 
150  @Override
151  public T put(Class<? extends T> arg0, T arg1) {
152  synchronized (this.policies) {
153  return this.policies.put(arg0, arg1);
154  }
155  }
156 
157  @Override
158  public void putAll(Map<? extends Class<? extends T>, ? extends T> arg0) {
159  synchronized (this.policies) {
160  this.policies.putAll(arg0);
161  }
162  }
163 
164  @Override
165  public T remove(Object arg0) {
166  T removed = null;
167 
168  synchronized (this.policies) {
169  removed = this.policies.remove(arg0);
170  this.setupMissingPolicies();
171  }
172  return removed;
173  }
174 
175  @Override
176  public int size() {
177  synchronized (this.policies) {
178  return this.policies.size();
179  }
180  }
181 
182  @Override
183  public Collection<T> values() {
184  synchronized (this.policies) {
185  return this.policies.values();
186  }
187  }
188 
189  @Override
190  public <POLICY extends T> POLICY get(Class<POLICY> id) {
191  synchronized (this.policies) {
192  return id.cast(this.policies.get(id));
193  }
194  }
195 
196  @Override
199  }
200 
201  protected abstract void setupMissingPolicies();
202 }
Set< java.util.Map.Entry< Class<? extends T >, T > > entrySet()
Set< Class<? extends T > > keySet()
EntityQosImpl(OsplServiceEnvironment environment, T... policies)
EntityQosImpl(OsplServiceEnvironment environment, Collection< T > policies)
void setupPolicies(Collection< T > policies)
Class<? extends T > getClassIdForPolicy(T policy)
T put(Class<? extends T > arg0, T arg1)
static PolicyFactory getPolicyFactory(ServiceEnvironment env)
void putAll(Map<? extends Class<? extends T >, ? extends T > arg0)
This class is the abstract root for all the QoS policies.
Definition: QosPolicy.java:118
final OsplServiceEnvironment environment
PolicyFactory getPolicyFactory()
Provides an instance of org.omg.dds.core.policy.PolicyFactory.
DDS implementations are rooted in this class, a concrete subclass of which can be instantiated based ...
HashMap< Class<? extends T >, T > policies
The Data-Distribution Service (DDS) relies on the use of QoS.
Definition: EntityQos.java:49