2 * Copyright (c) 2020 PANTHEON.tech, 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.dom.schema.osgi;
10 import com.google.common.annotations.Beta;
11 import com.google.common.primitives.UnsignedLong;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.yangtools.concepts.Immutable;
14 import org.osgi.framework.Constants;
17 * Additional interface for exposing linear generation of the backing effective model. Implementations of this interface
18 * are expected to be effectively-immutable.
20 * @param <S> service type
23 public interface ModelGenerationAware<S> extends Immutable {
25 @NonNull UnsignedLong getGeneration();
27 @NonNull S getService();
30 * Get service ranking based on the generation. Higher generation results in a higher ranking.
32 * @return Ranging for use with {@link Constants#SERVICE_RANKING}
34 default @NonNull Integer getServiceRanking() {
35 return computeServiceRanking(getGeneration().longValue());
39 * Calculate service ranking based on generation. Higher generation results in a higher ranking.
41 * @param generation generation number, treated as an unsigned long
42 * @return Ranging for use with {@link Constants#SERVICE_RANKING}
44 static @NonNull Integer computeServiceRanking(final long generation) {
45 return generation >= 0 && generation <= Integer.MAX_VALUE ? (int) generation : Integer.MAX_VALUE;