2 * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.mdsal.singleton.dom.impl;
10 import static com.google.common.base.Verify.verify;
11 import static com.google.common.base.Verify.verifyNotNull;
12 import static java.util.Objects.requireNonNull;
14 import com.google.common.util.concurrent.ListenableFuture;
15 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
16 import org.eclipse.jdt.annotation.NonNullByDefault;
17 import org.eclipse.jdt.annotation.Nullable;
18 import org.opendaylight.mdsal.singleton.dom.impl.ClusterSingletonServiceGroupImpl.ServiceState;
21 @SuppressFBWarnings(value = "NP_NULL_PARAM_DEREF_NONVIRTUAL", justification = "SpotBugs does not grok @Nullable field")
22 final class ServiceInfo {
23 private static final ServiceInfo STARTED = new ServiceInfo(ServiceState.STARTED, null);
25 private final @Nullable ListenableFuture<?> future;
26 private final ServiceState state;
28 private ServiceInfo(final ServiceState state, final @Nullable ListenableFuture<?> future) {
29 this.state = requireNonNull(state);
33 static ServiceInfo started() {
37 ServiceState getState() {
41 ListenableFuture<?> getFuture() {
42 return verifyNotNull(future);
45 ServiceInfo toState(final ServiceState newState) {
46 verify(state != newState, "Attempted to re-transition into %s", state);
47 return new ServiceInfo(newState, null);
50 ServiceInfo toState(final ServiceState newState, final ListenableFuture<?> newFuture) {
51 verify(state != newState, "Attempted to re-transition into %s", state);
52 return new ServiceInfo(newState, requireNonNull(newFuture));