OpenSplice Java 5 DCPS  v6.x
OpenSplice Java 5 OpenSplice Data Distribution Service Data-Centric Publish-Subscribe API
LivelinessImpl.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.policy;
22 
23 import java.util.concurrent.TimeUnit;
24 
25 import org.omg.dds.core.Duration;
30 
31 public class LivelinessImpl extends QosPolicyImpl implements Liveliness {
32  private static final long serialVersionUID = 8654350221156374238L;
33  private final Kind kind;
34  private final Duration leaseDuration;
35 
37  super(environment);
38  this.kind = Kind.AUTOMATIC;
39  this.leaseDuration = environment.getSPI().infiniteDuration();
40  }
41 
43  Duration leaseDuration) {
44  super(environment);
45 
46  if (kind == null) {
47  throw new IllegalArgumentExceptionImpl(environment,
48  "Supplied kind is null.");
49  }
50  if (leaseDuration == null) {
51  throw new IllegalArgumentExceptionImpl(environment,
52  "Supplied lease duration is null.");
53  }
54  this.kind = kind;
55  this.leaseDuration = leaseDuration;
56  }
57 
58  @Override
59  public Comparable<Liveliness> requestedOfferedContract() {
60  return this;
61  }
62 
63  @Override
64  public int compareTo(Liveliness o) {
65  /* AUTOMATIC < MANUAL_BY_PARTICIPANT < MANUAL_BY_TOPIC and offered
66  * leaseDuration <= requested leaseDuration */
67  Kind other = o.getKind();
68 
69  if (this.kind.equals(other)) {
70  return this.leaseDuration.compareTo(o.getLeaseDuration());
71  } else if (this.kind.equals(Kind.AUTOMATIC)) {
72  return -1;
73  } else if (this.kind.equals(Kind.MANUAL_BY_PARTICIPANT)) {
74  if (other.equals(Kind.AUTOMATIC)) {
75  return 1;
76  }
77  return -1;
78  }
79  return 1;
80  }
81 
82  @Override
83  public boolean equals(Object other) {
84  if (!(other instanceof LivelinessImpl)) {
85  return false;
86  }
87  LivelinessImpl l = (LivelinessImpl) other;
88 
89  if (!l.kind.equals(this.kind)) {
90  return false;
91  }
92  return this.leaseDuration.equals(l.leaseDuration);
93  }
94 
95  @Override
96  public Kind getKind() {
97  return this.kind;
98  }
99 
100  @Override
102  return this.leaseDuration;
103  }
104 
105  @Override
106  public Liveliness withKind(Kind kind) {
107  return new LivelinessImpl(this.environment, kind, this.leaseDuration);
108  }
109 
110  @Override
111  public Liveliness withLeaseDuration(Duration leaseDuration) {
112  return new LivelinessImpl(this.environment, this.kind, leaseDuration);
113  }
114 
115  @Override
116  public Liveliness withLeaseDuration(long leaseDuration, TimeUnit unit) {
117  return new LivelinessImpl(this.environment, this.kind, this.environment
118  .getSPI().newDuration(leaseDuration, unit));
119  }
120 
121  @Override
123  return new LivelinessImpl(this.environment, Kind.AUTOMATIC,
124  leaseDuration);
125  }
126 
127  @Override
130  leaseDuration);
131  }
132 
133  @Override
136  leaseDuration);
137  }
138 
139  @Override
140  public Class<? extends QosPolicy> getPolicyClass() {
141  return Liveliness.class;
142  }
143 
144  @Override
145  public int hashCode() {
146  final int prime = 31;
147  int result = 17;
148 
149  result = prime * result + this.kind.hashCode();
150  return prime * result + this.leaseDuration.hashCode();
151  }
152 
153 }
Class<? extends QosPolicy > getPolicyClass()
MANUAL_BY_PARTICIPANT
The user application takes responsibility to signal liveliness to the Service.
Liveliness withKind(Kind kind)
Copy this policy and override the value of the property.
Liveliness withLeaseDuration(long leaseDuration, TimeUnit unit)
Copy this policy and override the value of the property.
AUTOMATIC
The infrastructure will automatically signal liveliness for the org.omg.dds.pub.DataWriters at least ...
Liveliness withLeaseDuration(Duration leaseDuration)
Copy this policy and override the value of the property.
Comparable< Liveliness > requestedOfferedContract()
Determines the mechanism and parameters used by the application to determine whether an org...
This class is the abstract root for all the QoS policies.
Definition: QosPolicy.java:118
LivelinessImpl(OsplServiceEnvironment environment)
MANUAL_BY_TOPIC
The user application takes responsibility to signal liveliness to the Service.
A span of elapsed time expressed with nanosecond precision.
Definition: Duration.java:35
LivelinessImpl(OsplServiceEnvironment environment, Kind kind, Duration leaseDuration)