OpenSplice Java 5 DCPS  v6.x
OpenSplice Java 5 OpenSplice Data Distribution Service Data-Centric Publish-Subscribe API
DomainParticipantFactoryImpl.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.domain;
22 
23 import java.util.Arrays;
24 import java.util.Collection;
25 import java.util.HashMap;
26 import java.util.HashSet;
27 
29 import org.omg.dds.core.status.Status;
39 
42  implements org.opensplice.dds.domain.DomainParticipantFactory {
43  private OsplServiceEnvironment environment;
44  private DDS.DomainParticipantFactory factory;
45  private HashMap<DDS.DomainParticipant, DomainParticipantImpl> participants;
46 
48  this.environment = environment;
49  this.participants = new HashMap<DDS.DomainParticipant, DomainParticipantImpl>();
50  this.factory = DDS.DomainParticipantFactory.get_instance();
51  }
52 
53  public void destroyParticipant(DomainParticipantImpl participant) {
54  DDS.DomainParticipant old = participant.getOld();
55 
56  synchronized (this.participants) {
57  old.delete_contained_entities();
58  int rc = this.factory.delete_participant(old);
59  this.participants.remove(old);
60  Utilities.checkReturnCode(rc, this.environment,
61  "DomainParticipant.close() failed.");
62  }
63  }
64 
65  @Override
67  return this.environment;
68  }
69 
70  @Override
72  return createParticipant(DDS.DOMAIN_ID_DEFAULT.value);
73  }
74 
75  @Override
76  public DomainParticipant createParticipant(int domainId) {
77  return this.createParticipant(domainId,
78  this.getDefaultParticipantQos(), null, new HashSet<Class<? extends Status>>());
79  }
80 
81  @Override
82  public DomainParticipant createParticipant(int domainId,
84  Collection<Class<? extends Status>> statuses) {
85  DomainParticipantImpl participant;
86 
87  synchronized (this.participants) {
88  participant = new DomainParticipantImpl(this.environment, this,
89  domainId, qos, listener, statuses);
90  this.participants.put(participant.getOld(), participant);
91  }
92  return participant;
93  }
94 
95  @Override
96  public DomainParticipant createParticipant(int domainId,
98  Class<? extends Status>... statuses) {
99  return createParticipant(domainId, qos, listener, Arrays.asList(statuses));
100  }
101 
102  @Override
103  public DomainParticipant lookupParticipant(int domainId) {
104  DomainParticipantImpl participant;
105  DDS.DomainParticipant oldParticipant;
106 
107  synchronized (this.participants) {
108  oldParticipant = factory.lookup_participant(domainId);
109 
110  if (oldParticipant != null) {
111  participant = participants.get(oldParticipant);
112  } else {
113  participant = null;
114  }
115  }
116  return participant;
117  }
118 
119  @Override
121  DDS.DomainParticipantFactoryQosHolder holder = new DDS.DomainParticipantFactoryQosHolder();
122  int rc = this.factory.get_qos(holder);
123 
124  Utilities.checkReturnCode(rc, this.environment,
125  "DomainParticipantFactory.getQos() failed.");
126  return DomainParticipantFactoryQosImpl.convert(this.environment,
127  holder.value);
128  }
129 
130  @Override
132  if (qos == null) {
133  throw new IllegalArgumentExceptionImpl(this.environment,
134  "Supplied DomainParticipantFactoryQos is null.");
135  }
136  if (qos instanceof DomainParticipantFactoryQosImpl) {
137  DDS.DomainParticipantFactoryQos oldQos = ((DomainParticipantFactoryQosImpl) qos)
138  .convert();
139  int rc = this.factory.set_qos(oldQos);
140  Utilities.checkReturnCode(rc, this.environment,
141  "DomainParticipantFactory.setQos() failed.");
142  } else {
143  throw new IllegalOperationExceptionImpl(this.environment,
144  "DomainParticipantFactoryQos not supplied by OpenSplice Service provider.");
145  }
146  }
147 
148  @Override
151  DDS.DomainParticipantQosHolder holder;
152  int rc;
153 
154  holder = new DDS.DomainParticipantQosHolder();
155  rc = this.factory.get_default_participant_qos(holder);
156  Utilities.checkReturnCode(rc, this.environment,
157  "DomainParticipantFactory.getDefaultParticipantQos() failed.");
158 
159  qos = DomainParticipantQosImpl.convert(this.environment, holder.value);
160 
161  return qos;
162  }
163 
164  @Override
166  DDS.DomainParticipantQos oldQos;
167  int rc;
168 
169  if (qos == null) {
170  throw new IllegalArgumentExceptionImpl(this.environment,
171  "Supplied DomainParticipantQos is null.");
172  }
173  oldQos = ((DomainParticipantQosImpl) qos).convert();
174  rc = this.factory.set_default_participant_qos(oldQos);
175  Utilities.checkReturnCode(rc, this.environment,
176  "DomainParticipantFactory.setDefaultParticipantQos() failed.");
177 
178  }
179 
180  @Override
181  public void detachAllDomains(boolean blockOperations, boolean deleteEntities) {
182  this.factory.detach_all_domains(blockOperations, deleteEntities);
183  }
184 
185 
186 }
The DomainParticipant object plays several roles:
DomainParticipant createParticipant(int domainId, DomainParticipantQos qos, DomainParticipantListener listener, Class<? extends Status >... statuses)
static DomainParticipantQosImpl convert(OsplServiceEnvironment env, DDS.DomainParticipantQos oldQos)
DomainParticipant createParticipant(int domainId, DomainParticipantQos qos, DomainParticipantListener listener, Collection< Class<? extends Status >> statuses)
static void checkReturnCode(int retCode, OsplServiceEnvironment environment, String message)
Definition: Utilities.java:33
static DomainParticipantFactoryQosImpl convert(OsplServiceEnvironment env, DDS.DomainParticipantFactoryQos oldQos)
The sole purpose of this class is to allow the creation and destruction of org.omg.dds.domain.DomainParticipant objects.
This is the interface that can be implemented by an application-provided class and then registered wi...
DDS implementations are rooted in this class, a concrete subclass of which can be instantiated based ...
void detachAllDomains(boolean blockOperations, boolean deleteEntities)
Status is the abstract root class for all communication status objects.
Definition: Status.java:41