OpenSplice Java 5 DCPS  v6.x
OpenSplice Java 5 OpenSplice Data Distribution Service Data-Centric Publish-Subscribe API
OsplServiceEnvironment.java
Go to the documentation of this file.
1 /*
2  * Vortex OpenSplice
3  *
4  * This software and documentation are Copyright 2006 to 2021 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.Map;
24 import java.util.concurrent.ConcurrentHashMap;
25 import java.util.Set;
26 import java.util.concurrent.TimeUnit;
27 
28 import org.omg.dds.core.Duration;
32 import org.omg.dds.core.QosProvider;
34 import org.omg.dds.core.Time;
35 import org.omg.dds.core.WaitSet;
37 import org.omg.dds.core.status.Status;
39 import org.omg.dds.type.TypeSupport;
49 
51  private final Map<String, Object> environment;
52  private final OpenSpliceServiceProviderInterface osplSPI;
53 
54  public OsplServiceEnvironment(Map<String, Object> environment) {
55  this.environment = new ConcurrentHashMap<String, Object>();
56 
57  if (environment != null) {
58  this.environment.putAll(environment);
59  }
60  this.osplSPI = new OpenSpliceServiceProviderInterface(this);
61  }
62 
64  this.environment = null;
65  this.osplSPI = new OpenSpliceServiceProviderInterface(this);
66  }
67 
68  public Object getEnvironmentValue(String name) {
69  Object value;
70 
71  if (this.environment != null) {
72  value = this.environment.get(name);
73  } else {
74  value = null;
75  }
76  return value;
77  }
78 
79  @Override
81  return this.osplSPI;
82  }
83 
84  public static class OpenSpliceServiceProviderInterface implements
86  private final OsplServiceEnvironment environment;
87  private final DomainParticipantFactoryImpl factory;
88  private final PolicyFactoryImpl policyFactory;
89 
91  OsplServiceEnvironment environment) {
92  this.environment = environment;
93  this.factory = new DomainParticipantFactoryImpl(this.environment);
94  this.policyFactory = new PolicyFactoryImpl(this.environment);
95  }
96 
97  @Override
99  return this.factory;
100  }
101 
102  @Override
104  throw new UnsupportedOperationExceptionImpl(this.environment,
105  "getTypeFactory() not implemented yet.");
106  }
107 
108  @Override
109  public <TYPE> TypeSupport<TYPE> newTypeSupport(Class<TYPE> type,
110  String registeredName) {
111  TypeSupport<TYPE> result = null;
112  Class<?> superType;
113  String typeName;
114 
115  try {
116  typeName = type.getName();
117  superType = Class.forName(typeName).getSuperclass();
118 
119  if (superType != null) {
120  if ("com.google.protobuf.GeneratedMessage".equals(superType
121  .getName())) {
123  this.environment, type, registeredName);
124 
125  } else {
126  result = new TypeSupportImpl<TYPE>(this.environment,
127  type, registeredName);
128  }
129  } else {
131  this.environment,
132  "Allocating new TypeSupport failed. "
133  + type.getName()
134  + "' is not a support type for this DDS implementation.");
135  }
136  } catch (ClassNotFoundException e) {
137  throw new PreconditionNotMetExceptionImpl(this.environment,
138  "Allocating new TypeSupport failed. " + e.getMessage());
139  }
140  return result;
141  }
142 
143  @Override
144  public Duration newDuration(long duration, TimeUnit unit) {
145  return new DurationImpl(this.environment, duration, unit);
146  }
147 
148  @Override
150  return new DurationImpl(this.environment,
151  DDS.DURATION_INFINITE_SEC.value,
152  DDS.DURATION_INFINITE_NSEC.value);
153  }
154 
155  @Override
157  return new DurationImpl(this.environment,
158  DDS.DURATION_ZERO_SEC.value, DDS.DURATION_ZERO_NSEC.value);
159  }
160 
161  @Override
162  public ModifiableTime newTime(long time, TimeUnit units) {
163  return new ModifiableTimeImpl(this.environment, time, units);
164  }
165 
166  @Override
167  public Time invalidTime() {
168  return new TimeImpl(this.environment,
169  DDS.TIMESTAMP_INVALID_SEC.value,
170  DDS.TIMESTAMP_INVALID_NSEC.value);
171  }
172 
173  @Override
175  return new InstanceHandleImpl(this.environment,
176  DDS.HANDLE_NIL.value);
177  }
178 
179  @Override
181  return new GuardConditionImpl(this.environment);
182  }
183 
184  @Override
185  public WaitSet newWaitSet() {
186  return new WaitSetImpl(this.environment);
187  }
188 
189  @Override
190  public Set<Class<? extends Status>> allStatusKinds() {
191  return StatusConverter.convertMask(this.environment,
192  DDS.STATUS_MASK_ANY_V1_2.value);
193  }
194 
195  @Override
196  public Set<Class<? extends Status>> noStatusKinds() {
197  return StatusConverter.convertMask(this.environment,
198  DDS.STATUS_MASK_NONE.value);
199  }
200 
201  @Override
202  public QosProvider newQosProvider(String uri, String profile) {
203  return new QosProviderImpl(this.environment, uri, profile);
204  }
205 
206  @Override
208  return this.policyFactory;
209  }
210 
211  @Override
213  throw new UnsupportedOperationExceptionImpl(this.environment,
214  "getDynamicDataFactory() not implemented yet.");
215  }
216 
217  @Override
219  throw new UnsupportedOperationExceptionImpl(this.environment,
220  "newKeyedString() not implemented yet.");
221  }
222 
223  @Override
225  throw new UnsupportedOperationExceptionImpl(this.environment,
226  "newKeyedBytes() not implemented yet.");
227  }
228 
229  }
230 
231 }
static< SOME_TYPE > org.omg.dds.type.TypeSupport< SOME_TYPE > getInstance(OsplServiceEnvironment environment, Class< SOME_TYPE > dataType, String registeredName)
Duration newDuration(long duration, TimeUnit unit)
Construct a org.omg.dds.core.Duration of the given magnitude.
A GuardCondition object is a specific Condition whose triggerValue is completely under the control of...
A WaitSet object allows an application to wait until one or more of the attached org.omg.dds.core.Condition objects has a triggerValue of true or else until the timeout expires.
Definition: WaitSet.java:117
static Set< Class<? extends Status > > convertMask(OsplServiceEnvironment environment, int state)
QosProvider newQosProvider(String uri, String profile)
Create a QosProvider fetching QoS configuration from the specified URI.
An opaque handle that can be used to refer to a local or remote entity.
PolicyFactory getPolicyFactory()
Provides an instance of org.omg.dds.core.policy.PolicyFactory.
This interface is for the use of the DDS implementation, not of DDS applications. ...
The sole purpose of this class is to allow the creation and destruction of org.omg.dds.domain.DomainParticipant objects.
The QoS provider API allows users to specify the QoS settings of their DCPS entities outside of appli...
OsplServiceEnvironment(Map< String, Object > environment)
ModifiableTime newTime(long time, TimeUnit units)
Construct a specific instant in time.
TypeSupport is an abstract interface that has to be specialized for each concrete type that will be u...
A span of elapsed time expressed with nanosecond precision.
Definition: Duration.java:35
DDS implementations are rooted in this class, a concrete subclass of which can be instantiated based ...
A moment in time expressed with nanosecond precision (though not necessarily nanosecond accuracy)...
Definition: Time.java:34
Status is the abstract root class for all communication status objects.
Definition: Status.java:41