Sho SHIMIZU
Committed by Gerrit Code Review

Add default implementation for Resource/ResourceAllocation

- Instantiation of the implementations are needed in an implementation
  of ResourceService
- Device and link specific implementations are removed because the default
  implementations cover what these classes can do

Change-Id: Ia50b495e4d3bc21bf8f55f77a01f0532fae72720
...@@ -22,24 +22,24 @@ import java.util.Objects; ...@@ -22,24 +22,24 @@ import java.util.Objects;
22 import static com.google.common.base.Preconditions.checkNotNull; 22 import static com.google.common.base.Preconditions.checkNotNull;
23 23
24 /** 24 /**
25 - * Base implementation of a class representing resource which belongs to a particular subject. 25 + * Default implementation of a class representing resource which belongs to a particular subject.
26 * 26 *
27 * @param <S> type of the subject 27 * @param <S> type of the subject
28 * @param <T> type of the resource 28 * @param <T> type of the resource
29 */ 29 */
30 @Beta 30 @Beta
31 -public abstract class AbstractResource<S, T> implements Resource<S, T> { 31 +public class DefaultResource<S, T> implements Resource<S, T> {
32 32
33 private final S subject; 33 private final S subject;
34 private final T resource; 34 private final T resource;
35 35
36 /** 36 /**
37 - * Constructor expected to be called by constructors of the sub-classes. 37 + * Creates a resource with the specified subject and resource.
38 * 38 *
39 * @param subject identifier which this resource belongs to 39 * @param subject identifier which this resource belongs to
40 * @param resource resource of the subject 40 * @param resource resource of the subject
41 */ 41 */
42 - protected AbstractResource(S subject, T resource) { 42 + public DefaultResource(S subject, T resource) {
43 this.subject = checkNotNull(subject); 43 this.subject = checkNotNull(subject);
44 this.resource = checkNotNull(resource); 44 this.resource = checkNotNull(resource);
45 } 45 }
...@@ -64,10 +64,10 @@ public abstract class AbstractResource<S, T> implements Resource<S, T> { ...@@ -64,10 +64,10 @@ public abstract class AbstractResource<S, T> implements Resource<S, T> {
64 if (this == obj) { 64 if (this == obj) {
65 return true; 65 return true;
66 } 66 }
67 - if (!(obj instanceof AbstractResource)) { 67 + if (!(obj instanceof DefaultResource)) {
68 return false; 68 return false;
69 } 69 }
70 - final AbstractResource that = (AbstractResource) obj; 70 + final DefaultResource that = (DefaultResource) obj;
71 return Objects.equals(this.subject, that.subject) 71 return Objects.equals(this.subject, that.subject)
72 && Objects.equals(this.resource, that.resource); 72 && Objects.equals(this.resource, that.resource);
73 } 73 }
......
...@@ -22,26 +22,26 @@ import java.util.Objects; ...@@ -22,26 +22,26 @@ import java.util.Objects;
22 import static com.google.common.base.Preconditions.checkNotNull; 22 import static com.google.common.base.Preconditions.checkNotNull;
23 23
24 /** 24 /**
25 - * Base implementation of a class representing allocation of resource which belongs to a particular subject. 25 + * Default implementation of a class representing allocation of resource which belongs to a particular subject.
26 * 26 *
27 * @param <S> type of the subject 27 * @param <S> type of the subject
28 * @param <T> type of the resource 28 * @param <T> type of the resource
29 */ 29 */
30 @Beta 30 @Beta
31 -public abstract class AbstractResourceAllocation<S, T> implements ResourceAllocation<S, T> { 31 +public class DefaultResourceAllocation<S, T> implements ResourceAllocation<S, T> {
32 32
33 private final S subject; 33 private final S subject;
34 private final T resource; 34 private final T resource;
35 private final ResourceConsumer consumer; 35 private final ResourceConsumer consumer;
36 36
37 /** 37 /**
38 - * Constructor expected to be called by constructors of the sub-classes. 38 + * Creates an instance with the specified subject, resource and consumer.
39 * 39 *
40 * @param subject identifier which this resource belongs to 40 * @param subject identifier which this resource belongs to
41 * @param resource resource of the subject 41 * @param resource resource of the subject
42 * @param consumer consumer ot this resource 42 * @param consumer consumer ot this resource
43 */ 43 */
44 - protected AbstractResourceAllocation(S subject, T resource, ResourceConsumer consumer) { 44 + public DefaultResourceAllocation(S subject, T resource, ResourceConsumer consumer) {
45 this.subject = checkNotNull(subject); 45 this.subject = checkNotNull(subject);
46 this.resource = checkNotNull(resource); 46 this.resource = checkNotNull(resource);
47 this.consumer = consumer; 47 this.consumer = consumer;
...@@ -72,10 +72,10 @@ public abstract class AbstractResourceAllocation<S, T> implements ResourceAlloca ...@@ -72,10 +72,10 @@ public abstract class AbstractResourceAllocation<S, T> implements ResourceAlloca
72 if (this == obj) { 72 if (this == obj) {
73 return true; 73 return true;
74 } 74 }
75 - if (!(obj instanceof AbstractResourceAllocation)) { 75 + if (!(obj instanceof DefaultResourceAllocation)) {
76 return false; 76 return false;
77 } 77 }
78 - final AbstractResourceAllocation that = (AbstractResourceAllocation) obj; 78 + final DefaultResourceAllocation that = (DefaultResourceAllocation) obj;
79 return Objects.equals(this.subject, that.subject) 79 return Objects.equals(this.subject, that.subject)
80 && Objects.equals(this.resource, that.resource) 80 && Objects.equals(this.resource, that.resource)
81 && Objects.equals(this.consumer, that.consumer); 81 && Objects.equals(this.consumer, that.consumer);
......
1 -/*
2 - * Copyright 2015 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 - */
16 -package org.onosproject.net.newresource;
17 -
18 -import com.google.common.annotations.Beta;
19 -import org.onosproject.net.DeviceId;
20 -
21 -/**
22 - * Represents resource which belongs to a particular device.
23 - *
24 - * @param <T> represents the type of the resource
25 - */
26 -@Beta
27 -public final class DeviceResource<T> extends AbstractResource<DeviceId, T> {
28 -
29 - /**
30 - * Creates a new device resource from the specified device identifier and resource.
31 - * (deviceId, resource) signifies a resource identifier which is globally unique.
32 - *
33 - * @param deviceId device identifier which this resource belongs to
34 - * @param resource resource of the device
35 - */
36 - public DeviceResource(DeviceId deviceId, T resource) {
37 - super(deviceId, resource);
38 - }
39 -}
1 -/*
2 - * Copyright 2015 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 - */
16 -package org.onosproject.net.newresource;
17 -
18 -import com.google.common.annotations.Beta;
19 -import org.onosproject.net.DeviceId;
20 -
21 -/**
22 - * Represents allocation of resource bound to device.
23 - *
24 - * @param <T> type of the resource
25 - */
26 -@Beta
27 -public final class DeviceResourceAllocation<T> extends AbstractResourceAllocation<DeviceId, T> {
28 -
29 - /**
30 - * Creates a new allocation of resource bound to the specified device and consumed by the specified user.
31 - *
32 - * @param device device identifier which this resource belongs to
33 - * @param resource resource of the device
34 - * @param consumer consumer of this resource
35 - */
36 - public DeviceResourceAllocation(DeviceId device, T resource, ResourceConsumer consumer) {
37 - super(device, resource, consumer);
38 - }
39 -}
1 -/*
2 - * Copyright 2015 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 - */
16 -package org.onosproject.net.newresource;
17 -
18 -import com.google.common.annotations.Beta;
19 -import org.onosproject.net.LinkKey;
20 -
21 -/**
22 - * Represents resource which belongs to a particular link.
23 - *
24 - * @param <T> represents the type of the resource
25 - */
26 -@Beta
27 -public final class LinkResource<T> extends AbstractResource<LinkKey, T> {
28 -
29 - /**
30 - * Creates a new link resource from the specified link identifier and resource.
31 - * (linkKey, resource) signifies a resource identifier which is globally unique.
32 - *
33 - * @param linkKey link identifier which this resource belongs to
34 - * @param resource resource of the link
35 - */
36 - public LinkResource(LinkKey linkKey, T resource) {
37 - super(linkKey, resource);
38 - }
39 -}
1 -/*
2 - * Copyright 2015 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 - */
16 -package org.onosproject.net.newresource;
17 -
18 -import com.google.common.annotations.Beta;
19 -import org.onosproject.net.LinkKey;
20 -
21 -/**
22 - * Represents allocation of resource bound to link.
23 - *
24 - * @param <T> type of the resource
25 - */
26 -@Beta
27 -public final class LinkResourceAllocation<T> extends AbstractResourceAllocation<LinkKey, T> {
28 -
29 - /**
30 - * Creates a new allocation of resource bound to the specified device and consumed by the specified user.
31 - *
32 - * @param link device identifier which this resource belongs to
33 - * @param resource resource of the device
34 - * @param consumer consumer of this resource
35 - */
36 - public LinkResourceAllocation(LinkKey link, T resource, ResourceConsumer consumer) {
37 - super(link, resource, consumer);
38 - }
39 -}