tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.provider; |
| 2 | |
| 3 | import static com.google.common.base.Preconditions.checkState; |
| 4 | |
| 5 | /** |
| 6 | * Base implementation of a provider service, which tracks the provider to |
| 7 | * which it is issued and can be invalidated. |
| 8 | * |
| 9 | * @param <P> type of the information provider |
| 10 | */ |
| 11 | public abstract class AbstractProviderService<P extends Provider> implements ProviderService<P> { |
| 12 | |
| 13 | private boolean isValid = true; |
| 14 | private final P provider; |
| 15 | |
| 16 | /** |
| 17 | * Creates a provider service on behalf of the specified provider. |
| 18 | * |
| 19 | * @param provider provider to which this service is being issued |
| 20 | */ |
| 21 | protected AbstractProviderService(P provider) { |
| 22 | this.provider = provider; |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Invalidates this provider service. |
| 27 | */ |
| 28 | public void invalidate() { |
| 29 | isValid = false; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Checks the validity of this provider service. |
| 34 | * |
| 35 | * @throws java.lang.IllegalStateException if the service is no longer valid |
| 36 | */ |
| 37 | public void checkValidity() { |
| 38 | checkState(isValid, "Provider service is no longer valid"); |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public P provider() { |
| 43 | return provider; |
| 44 | } |
| 45 | |
| 46 | } |