blob: ff879b57b6d525cbdaf87229dc68861e6386a5a2 [file] [log] [blame]
Jordan Halterman2c045992018-03-20 21:33:00 -07001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.store.service;
17
18import java.util.concurrent.TimeUnit;
19
20import org.onosproject.store.primitives.DistributedPrimitiveOptions;
21
22/**
23 * Builder for constructing new {@link AsyncLeaderElector} instances.
24 */
25public abstract class LeaderElectorOptions<O extends LeaderElectorOptions<O>>
26 extends DistributedPrimitiveOptions<O> {
27
28 private long electionTimeoutMillis = DistributedPrimitive.DEFAULT_OPERATION_TIMEOUT_MILLIS;
29
30 public LeaderElectorOptions() {
31 super(DistributedPrimitive.Type.LEADER_ELECTOR);
32 }
33
34 /**
35 * Sets the election timeout in milliseconds.
36 *
37 * @param electionTimeoutMillis the election timeout in milliseconds
38 * @return leader elector builder
39 */
40 public O withElectionTimeout(long electionTimeoutMillis) {
41 this.electionTimeoutMillis = electionTimeoutMillis;
42 return (O) this;
43 }
44
45 /**
46 * Sets the election timeout.
47 *
48 * @param electionTimeout the election timeout
49 * @param timeUnit the timeout time unit
50 * @return leader elector builder
51 */
52 public O withElectionTimeout(long electionTimeout, TimeUnit timeUnit) {
53 return withElectionTimeout(timeUnit.toMillis(electionTimeout));
54 }
55
56 /**
57 * Returns the election timeout in milliseconds.
58 *
59 * @return the election timeout in milliseconds
60 */
61 public final long electionTimeoutMillis() {
62 return electionTimeoutMillis;
63 }
64}