blob: 2411e26de3cfed07613662305abc5f8315233201 [file] [log] [blame]
yoonseone92748c2016-12-13 16:37:51 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
yoonseone92748c2016-12-13 16:37:51 -08003 *
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 */
16
17package org.onosproject.incubator.net.virtual.provider;
18
19import static com.google.common.base.Preconditions.checkState;
20
yoonseon1f518572017-01-03 17:27:26 -080021/**
22 * Base implementation of a virtual provider service,
23 * which tracks the provider to which it is issued and can be invalidated.
24 *
25 * @param <P> type of the information provider
26 */
yoonseone92748c2016-12-13 16:37:51 -080027public abstract class AbstractVirtualProviderService<P extends VirtualProvider>
yoonseon6b972c32016-12-06 16:45:03 -080028 implements VirtualProviderService<P> {
yoonseone92748c2016-12-13 16:37:51 -080029
30 private boolean isValid = true;
yoonseon1f518572017-01-03 17:27:26 -080031 private P provider = null;
yoonseone92748c2016-12-13 16:37:51 -080032
yoonseon1f518572017-01-03 17:27:26 -080033 /**
34 * Creates a virtual provider service on behalf of the specified provider.
35 *
36 * @param provider provider to which this service is being issued
37 */
38 protected void setProvider(P provider) {
yoonseone92748c2016-12-13 16:37:51 -080039 this.provider = provider;
40 }
41
42 /**
43 * Invalidates this provider service.
44 */
45 public void invalidate() {
46 isValid = false;
47 }
48
49 /**
50 * Checks the validity of this provider service.
51 *
52 * @throws java.lang.IllegalStateException if the service is no longer valid
53 */
54 public void checkValidity() {
55 checkState(isValid, "Provider service is no longer valid");
56 }
57
58 @Override
59 public P provider() {
60 return provider;
61 }
62}