blob: 556ad17bacf4a4103d4053eef739e93f934cd900 [file] [log] [blame]
Madan Jampani39fff102016-02-14 13:17:28 -08001/*
2 * Copyright 2016 Open Networking Laboratory
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.primitives.impl;
17
18import org.onosproject.store.primitives.DistributedPrimitiveCreator;
19import org.onosproject.store.service.AsyncLeaderElector;
20import org.onosproject.store.service.LeaderElectorBuilder;
21
22/**
23 * Default implementation of {@code LeaderElectorBuilder}.
24 */
25public class DefaultLeaderElectorBuilder extends LeaderElectorBuilder {
26
27 private final DistributedPrimitiveCreator base;
28 private final DistributedPrimitiveCreator federated;
29
30 public DefaultLeaderElectorBuilder(DistributedPrimitiveCreator base, DistributedPrimitiveCreator federated) {
31 this.base = base;
32 this.federated = federated;
33 }
34
35 @Override
36 public AsyncLeaderElector build() {
37 DistributedPrimitiveCreator creator = partitionsDisabled() ? base : federated;
38 return creator.newAsyncLeaderElector(name());
39 }
40}