OpenSplice Java 5 DCPS  v6.x
OpenSplice Java 5 OpenSplice Data Distribution Service Data-Centric Publish-Subscribe API
Listener.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.io.Serializable;
24 import java.util.EventListener;
25 import java.util.concurrent.CountDownLatch;
26 
29 
30 public abstract class Listener<T> extends AbstractDDSObject implements EventListener, Serializable {
31  private static final long serialVersionUID = 5928369585907075474L;
32  private final CountDownLatch initialised;
34  protected T listener;
35 
36  public Listener(OsplServiceEnvironment environment, T listener,
37  boolean waitUntilInitialised) {
38  this.environment = environment;
39  this.listener = listener;
40 
41  if (waitUntilInitialised) {
42  this.initialised = new CountDownLatch(1);
43  } else {
44  this.initialised = new CountDownLatch(0);
45  }
46  }
47 
49  return this.environment;
50  }
51 
52  public T getRealListener(){
53  return this.listener;
54  }
55 
56  public void setInitialised() {
57  this.initialised.countDown();
58  }
59 
60  public void waitUntilInitialised() {
61  try {
62  this.initialised.await();
63  } catch (InterruptedException e) {
64  throw new AlreadyClosedExceptionImpl(this.environment,
65  "Listener interrupted.");
66  }
67  }
68 }
OsplServiceEnvironment environment
Definition: Listener.java:33
ServiceEnvironment getEnvironment()
Definition: Listener.java:48
DDS implementations are rooted in this class, a concrete subclass of which can be instantiated based ...
Listener(OsplServiceEnvironment environment, T listener, boolean waitUntilInitialised)
Definition: Listener.java:36