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.NonNull;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.opendaylight.mdsal.singleton.dom.impl.ActiveServiceGroup.ServiceState;
19 final class ServiceInfo {
20 static final @NonNull ServiceInfo STARTED = new ServiceInfo(ServiceState.STARTED, null);
22 private final @Nullable ListenableFuture<?> future;
23 private final @NonNull ServiceState state;
25 private ServiceInfo(final ServiceState state, final @Nullable ListenableFuture<?> future) {
26 this.state = requireNonNull(state);
30 @NonNull ServiceState getState() {
34 @NonNull ListenableFuture<?> getFuture() {
35 return verifyNotNull(future);
38 @NonNull ServiceInfo toState(final @NonNull ServiceState newState) {
39 verify(state != newState, "Attempted to re-transition into %s", state);
40 return new ServiceInfo(newState, null);
43 @NonNull ServiceInfo toState(final @NonNull ServiceState newState, final @NonNull ListenableFuture<?> newFuture) {
44 verify(state != newState, "Attempted to re-transition into %s", state);
45 return new ServiceInfo(newState, requireNonNull(newFuture));