OpenSplice Java 5 DCPS  v6.x
OpenSplice Java 5 OpenSplice Data Distribution Service Data-Centric Publish-Subscribe API
DurabilityServiceImpl.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.policy;
22 
23 import java.util.concurrent.TimeUnit;
24 
25 import org.omg.dds.core.Duration;
27 import org.omg.dds.core.policy.History;
32 
33 public class DurabilityServiceImpl extends QosPolicyImpl implements
35  private static final long serialVersionUID = -3906397729567497050L;
36  private final Duration serviceCleanupDelay;
37  private final History history;
38  private final int maxSamples;
39  private final int maxInstances;
40  private final int maxSamplesPerInstance;
41 
43  super(environment);
44  this.serviceCleanupDelay = environment.getSPI().zeroDuration();
45  this.history = new HistoryImpl(environment, Kind.KEEP_LAST, 1);
46  this.maxSamples = -1;
47  this.maxInstances = -1;
48  this.maxSamplesPerInstance = -1;
49  }
50 
52  Duration serviceCleanupDelay, Kind historyKind, int historyDepth,
53  int maxSamples, int maxInstances, int maxSamplesPerInstance) {
54  super(environment);
55  this.serviceCleanupDelay = serviceCleanupDelay;
56  this.history = new HistoryImpl(environment, historyKind, historyDepth);
57  this.maxSamples = maxSamples;
58  this.maxInstances = maxInstances;
59  this.maxSamplesPerInstance = maxSamplesPerInstance;
60 
61  if (serviceCleanupDelay == null) {
62  throw new IllegalArgumentExceptionImpl(environment,
63  "Supplied invalid service cleanup delay.");
64  }
65  }
66 
67  @Override
69  return this.serviceCleanupDelay;
70  }
71 
72  @Override
73  public Kind getHistoryKind() {
74  return this.history.getKind();
75  }
76 
77  @Override
78  public int getHistoryDepth() {
79  return this.history.getDepth();
80  }
81 
82  @Override
83  public int getMaxSamples() {
84  return this.maxSamples;
85  }
86 
87  @Override
88  public int getMaxInstances() {
89  return this.maxInstances;
90  }
91 
92  @Override
93  public int getMaxSamplesPerInstance() {
94  return this.maxSamplesPerInstance;
95  }
96 
97  @Override
99  Duration serviceCleanupDelay) {
100  return new DurabilityServiceImpl(this.environment, serviceCleanupDelay,
101  this.history.getKind(), this.history.getDepth(), this.maxSamples,
102  this.maxInstances, this.maxSamplesPerInstance);
103  }
104 
105  @Override
106  public DurabilityService withServiceCleanupDelay(long serviceCleanupDelay,
107  TimeUnit unit) {
108  return new DurabilityServiceImpl(this.environment, this.environment
109  .getSPI().newDuration(serviceCleanupDelay, unit),
110  this.history.getKind(), this.history.getDepth(), this.maxSamples,
111  this.maxInstances, this.maxSamplesPerInstance);
112  }
113 
114  @Override
115  public DurabilityService withHistoryKind(Kind historyKind) {
116  return new DurabilityServiceImpl(this.environment,
117  this.serviceCleanupDelay, historyKind, this.history.getDepth(),
118  this.maxSamples, this.maxInstances, this.maxSamplesPerInstance);
119  }
120 
121  @Override
122  public DurabilityService withHistoryDepth(int historyDepth) {
123  return new DurabilityServiceImpl(this.environment,
124  this.serviceCleanupDelay, this.history.getKind(), historyDepth,
125  this.maxSamples, this.maxInstances, this.maxSamplesPerInstance);
126  }
127 
128  @Override
129  public DurabilityService withMaxSamples(int maxSamples) {
130  return new DurabilityServiceImpl(this.environment,
131  this.serviceCleanupDelay, this.history.getKind(), this.history.getDepth(),
132  maxSamples, this.maxInstances, this.maxSamplesPerInstance);
133  }
134 
135  @Override
136  public DurabilityService withMaxInstances(int maxInstances) {
137  return new DurabilityServiceImpl(this.environment,
138  this.serviceCleanupDelay, this.history.getKind(), this.history.getDepth(),
139  this.maxSamples, maxInstances, this.maxSamplesPerInstance);
140  }
141 
142  @Override
143  public DurabilityService withMaxSamplesPerInstance(int maxSamplesPerInstance) {
144  return new DurabilityServiceImpl(this.environment,
145  this.serviceCleanupDelay, this.history.getKind(), this.history.getDepth(),
146  this.maxSamples, this.maxInstances, maxSamplesPerInstance);
147  }
148 
149  @Override
150  public Class<? extends QosPolicy> getPolicyClass() {
151  return DurabilityService.class;
152  }
153 
154  @Override
155  public boolean equals(Object other) {
156  if (!(other instanceof DurabilityServiceImpl)) {
157  return false;
158  }
159  DurabilityServiceImpl d = (DurabilityServiceImpl) other;
160 
161  if (!this.history.equals(d.history)) {
162  return false;
163  }
164  if (this.maxInstances != d.maxInstances) {
165  return false;
166  }
167  if (this.maxSamples != d.maxSamples) {
168  return false;
169  }
170  if (this.maxSamplesPerInstance != d.maxSamplesPerInstance) {
171  return false;
172  }
173  return this.serviceCleanupDelay.equals(d.serviceCleanupDelay);
174  }
175 
176  @Override
177  public int hashCode() {
178  final int prime = 31;
179  int result = 17;
180 
181  result = prime * result + this.history.hashCode();
182  result = prime * result + this.maxInstances;
183  result = prime * result + this.maxSamples;
184  result = prime * result + this.maxSamplesPerInstance;
185  result = prime * result + this.serviceCleanupDelay.hashCode();
186 
187  return result;
188  }
189 }
Specifies the configuration of the durability service.
DurabilityServiceImpl(OsplServiceEnvironment environment)
DurabilityService withServiceCleanupDelay(Duration serviceCleanupDelay)
Copy this policy and override the value of the property.
DurabilityServiceImpl(OsplServiceEnvironment environment, Duration serviceCleanupDelay, Kind historyKind, int historyDepth, int maxSamples, int maxInstances, int maxSamplesPerInstance)
DurabilityService withMaxSamples(int maxSamples)
Copy this policy and override the value of the property.
DurabilityService withMaxInstances(int maxInstances)
Copy this policy and override the value of the property.
DurabilityService withMaxSamplesPerInstance(int maxSamplesPerInstance)
Copy this policy and override the value of the property.
DurabilityService withHistoryDepth(int historyDepth)
Copy this policy and override the value of the property.
DurabilityService withServiceCleanupDelay(long serviceCleanupDelay, TimeUnit unit)
Copy this policy and override the value of the property.
This class is the abstract root for all the QoS policies.
Definition: QosPolicy.java:118
A span of elapsed time expressed with nanosecond precision.
Definition: Duration.java:35
Specifies the behavior of the Service in the case where the value of a sample changes (one or more ti...
Definition: History.java:76