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 org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.opendaylight.mdsal.singleton.dom.impl.ClusterSingletonServiceGroupImpl.ServiceState;
20 final class ServiceInfo {
21 private static final ServiceInfo STARTED = new ServiceInfo(ServiceState.STARTED, null);
23 private final @Nullable ListenableFuture<?> future;
24 private final ServiceState state;
26 private ServiceInfo(final ServiceState state, final @Nullable ListenableFuture<?> future) {
27 this.state = requireNonNull(state);
31 static ServiceInfo started() {
35 ServiceState getState() {
39 ListenableFuture<?> getFuture() {
40 return verifyNotNull(future);
43 ServiceInfo toState(final ServiceState newState) {
44 verify(state != newState, "Attempted to re-transition into %s", state);
45 return new ServiceInfo(newState, null);
48 ServiceInfo toState(final ServiceState newState, final ListenableFuture<?> newFuture) {
49 verify(state != newState, "Attempted to re-transition into %s", state);
50 return new ServiceInfo(newState, requireNonNull(newFuture));