OpenSplice Java 5 DCPS  v6.x
OpenSplice Java 5 OpenSplice Data Distribution Service Data-Centric Publish-Subscribe API
ReliabilityImpl.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;
29 
30 public class ReliabilityImpl extends QosPolicyImpl implements Reliability {
31  private static final long serialVersionUID = 6430015862797188917L;
32  private final Kind kind;
33  private final Duration maxBlockingTime;
34  private final boolean synchronous;
35 
37  super(environment);
38  this.kind = Kind.BEST_EFFORT;
39  this.maxBlockingTime = environment.getSPI().newDuration(100,
40  TimeUnit.MILLISECONDS);
41  this.synchronous = false;
42  }
43 
45  Duration maxBlockingTime, boolean synchronous) {
46  super(environment);
47 
48  if (kind == null) {
49  throw new IllegalArgumentExceptionImpl(environment,
50  "Supplied invalid kind.");
51  }
52  if (maxBlockingTime == null) {
53  throw new IllegalArgumentExceptionImpl(environment,
54  "Supplied invalid maxBlockingTime.");
55  }
56  this.kind = kind;
57  this.maxBlockingTime = maxBlockingTime;
58  this.synchronous = synchronous;
59  }
60 
61  @Override
63  return this;
64  }
65 
66  @Override
68  if (this.kind.equals(o.getKind())) {
69  int max = this.maxBlockingTime.compareTo(o.getMaxBlockingTime());
70 
71  if(max == 0){
72  if(o instanceof ReliabilityImpl){
73  if (this.synchronous == ((ReliabilityImpl) o)
74  .isSynchronous()) {
75  return 0;
76  } else if (this.synchronous) {
77  return 1;
78  }
79  return -1;
80  }
81  }
82  return max;
83  } else if (this.kind.equals(Kind.RELIABLE)) {
84  return 1;
85  }
86  return -1;
87  }
88 
89  @Override
90  public boolean equals(Object other) {
91  if (!(other instanceof ReliabilityImpl)) {
92  return false;
93  }
94  ReliabilityImpl r = (ReliabilityImpl) other;
95 
96  if (this.kind != r.kind) {
97  return false;
98  }
99  if (this.synchronous != r.synchronous) {
100  return false;
101  }
102  return this.maxBlockingTime.equals(r.maxBlockingTime);
103  }
104 
105  @Override
106  public Kind getKind() {
107  return this.kind;
108  }
109 
110  @Override
112  return this.maxBlockingTime;
113  }
114 
115  @Override
116  public Reliability withKind(Kind kind) {
117  return new ReliabilityImpl(this.environment, kind,
118  this.maxBlockingTime, this.synchronous);
119  }
120 
121  @Override
122  public Reliability withMaxBlockingTime(Duration maxBlockingTime) {
123  return new ReliabilityImpl(this.environment, this.kind,
124  maxBlockingTime, this.synchronous);
125  }
126 
127  @Override
128  public Reliability withMaxBlockingTime(long maxBlockingTime, TimeUnit unit) {
129  return new ReliabilityImpl(this.environment, this.kind,
130  this.environment.getSPI().newDuration(maxBlockingTime, unit),
131  this.synchronous);
132  }
133 
134  @Override
136  return new ReliabilityImpl(this.environment, Kind.BEST_EFFORT,
137  this.maxBlockingTime, this.synchronous);
138  }
139 
140  @Override
142  return new ReliabilityImpl(this.environment, Kind.RELIABLE,
143  this.maxBlockingTime, this.synchronous);
144  }
145 
146  @Override
147  public boolean isSynchronous() {
148  return this.synchronous;
149  }
150 
151  @Override
152  public Reliability withSynchronous(boolean synchronous) {
153  return new ReliabilityImpl(this.environment, this.kind,
154  this.maxBlockingTime, synchronous);
155  }
156 
157  @Override
158  public Class<? extends QosPolicy> getPolicyClass() {
159  return org.omg.dds.core.policy.Reliability.class;
160  }
161 
162  @Override
163  public int hashCode() {
164  final int prime = 31;
165  int result = 17;
166 
167  result = prime * result + this.kind.hashCode();
168  result = prime * result + (this.synchronous ? 1 : 0);
169 
170  return prime * result + this.maxBlockingTime.hashCode();
171  }
172 
173 }
Reliability withMaxBlockingTime(long maxBlockingTime, TimeUnit unit)
Copy this policy and override the value of the property.
ReliabilityImpl(OsplServiceEnvironment environment, Kind kind, Duration maxBlockingTime, boolean synchronous)
int compareTo(org.omg.dds.core.policy.Reliability o)
Reliability withMaxBlockingTime(Duration maxBlockingTime)
Copy this policy and override the value of the property.
Reliability withSynchronous(boolean synchronous)
Comparable< org.omg.dds.core.policy.Reliability > requestedOfferedContract()
This class is the abstract root for all the QoS policies.
Definition: QosPolicy.java:118
Duration newDuration(long duration, TimeUnit unit)
Construct a org.omg.dds.core.Duration of the given magnitude.
A span of elapsed time expressed with nanosecond precision.
Definition: Duration.java:35
This policy indicates the level of reliability requested by a org.omg.dds.sub.DataReader or offered b...
ReliabilityImpl(OsplServiceEnvironment environment)