blob: 6c926d88469783d0da263e04927296cebf9ed342 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.provider;
tom64b7aac2014-08-26 00:18:21 -070017
18import static com.google.common.base.Preconditions.checkState;
19
20/**
21 * Base implementation of a provider service, which tracks the provider to
22 * which it is issued and can be invalidated.
23 *
24 * @param <P> type of the information provider
25 */
26public abstract class AbstractProviderService<P extends Provider> implements ProviderService<P> {
27
28 private boolean isValid = true;
29 private final P provider;
30
31 /**
32 * Creates a provider service on behalf of the specified provider.
33 *
34 * @param provider provider to which this service is being issued
35 */
36 protected AbstractProviderService(P provider) {
37 this.provider = provider;
38 }
39
40 /**
41 * Invalidates this provider service.
42 */
43 public void invalidate() {
44 isValid = false;
45 }
46
47 /**
48 * Checks the validity of this provider service.
49 *
50 * @throws java.lang.IllegalStateException if the service is no longer valid
51 */
52 public void checkValidity() {
53 checkState(isValid, "Provider service is no longer valid");
54 }
55
56 @Override
57 public P provider() {
58 return provider;
59 }
60
61}