blob: d3d6951e672c3c156031f3a70969c224fe211ad4 [file] [log] [blame]
Madan Jampani39fff102016-02-14 13:17:28 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Madan Jampani39fff102016-02-14 13:17:28 -08003 *
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
Jordan Halterman7b7644f2017-10-16 12:57:55 -070018import java.util.concurrent.TimeUnit;
19
Madan Jampani39fff102016-02-14 13:17:28 -080020import org.onosproject.store.primitives.DistributedPrimitiveBuilder;
21
22/**
23 * Builder for constructing new {@link AsyncLeaderElector} instances.
24 */
25public abstract class LeaderElectorBuilder
26 extends DistributedPrimitiveBuilder<LeaderElectorBuilder, AsyncLeaderElector> {
Jordan Halterman7b7644f2017-10-16 12:57:55 -070027
28 private long electionTimeoutMillis = DistributedPrimitive.DEFAULT_OPERATION_TIMEOUT_MILLIS;
29
Madan Jampani39fff102016-02-14 13:17:28 -080030 public LeaderElectorBuilder() {
31 super(DistributedPrimitive.Type.LEADER_ELECTOR);
32 }
Jordan Halterman7b7644f2017-10-16 12:57:55 -070033
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 LeaderElectorBuilder withElectionTimeout(long electionTimeoutMillis) {
41 this.electionTimeoutMillis = electionTimeoutMillis;
42 return 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 LeaderElectorBuilder 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 }
Madan Jampani39fff102016-02-14 13:17:28 -080064}