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;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Base implementation of a class representing resource which belongs to a particular subject.
* Default implementation of a class representing resource which belongs to a particular subject.
*
* @param <S> type of the subject
* @param <T> type of the resource
*/
@Beta
public abstract class AbstractResource<S, T> implements Resource<S, T> {
public class DefaultResource<S, T> implements Resource<S, T> {
private final S subject;
private final T resource;
/**
* Constructor expected to be called by constructors of the sub-classes.
* Creates a resource with the specified subject and resource.
*
* @param subject identifier which this resource belongs to
* @param resource resource of the subject
*/
protected AbstractResource(S subject, T resource) {
public DefaultResource(S subject, T resource) {
this.subject = checkNotNull(subject);
this.resource = checkNotNull(resource);
}
......@@ -64,10 +64,10 @@ public abstract class AbstractResource<S, T> implements Resource<S, T> {
if (this == obj) {
return true;
}
if (!(obj instanceof AbstractResource)) {
if (!(obj instanceof DefaultResource)) {
return false;
}
final AbstractResource that = (AbstractResource) obj;
final DefaultResource that = (DefaultResource) obj;
return Objects.equals(this.subject, that.subject)
&& Objects.equals(this.resource, that.resource);
}
......
......@@ -22,26 +22,26 @@ import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Base implementation of a class representing allocation of resource which belongs to a particular subject.
* Default implementation of a class representing allocation of resource which belongs to a particular subject.
*
* @param <S> type of the subject
* @param <T> type of the resource
*/
@Beta
public abstract class AbstractResourceAllocation<S, T> implements ResourceAllocation<S, T> {
public class DefaultResourceAllocation<S, T> implements ResourceAllocation<S, T> {
private final S subject;
private final T resource;
private final ResourceConsumer consumer;
/**
* Constructor expected to be called by constructors of the sub-classes.
* Creates an instance with the specified subject, resource and consumer.
*
* @param subject identifier which this resource belongs to
* @param resource resource of the subject
* @param consumer consumer ot this resource
*/
protected AbstractResourceAllocation(S subject, T resource, ResourceConsumer consumer) {
public DefaultResourceAllocation(S subject, T resource, ResourceConsumer consumer) {
this.subject = checkNotNull(subject);
this.resource = checkNotNull(resource);
this.consumer = consumer;
......@@ -72,10 +72,10 @@ public abstract class AbstractResourceAllocation<S, T> implements ResourceAlloca
if (this == obj) {
return true;
}
if (!(obj instanceof AbstractResourceAllocation)) {
if (!(obj instanceof DefaultResourceAllocation)) {
return false;
}
final AbstractResourceAllocation that = (AbstractResourceAllocation) obj;
final DefaultResourceAllocation that = (DefaultResourceAllocation) obj;
return Objects.equals(this.subject, that.subject)
&& Objects.equals(this.resource, that.resource)
&& Objects.equals(this.consumer, that.consumer);
......
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.newresource;
import com.google.common.annotations.Beta;
import org.onosproject.net.DeviceId;
/**
* Represents resource which belongs to a particular device.
*
* @param <T> represents the type of the resource
*/
@Beta
public final class DeviceResource<T> extends AbstractResource<DeviceId, T> {
/**
* Creates a new device resource from the specified device identifier and resource.
* (deviceId, resource) signifies a resource identifier which is globally unique.
*
* @param deviceId device identifier which this resource belongs to
* @param resource resource of the device
*/
public DeviceResource(DeviceId deviceId, T resource) {
super(deviceId, resource);
}
}
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.newresource;
import com.google.common.annotations.Beta;
import org.onosproject.net.DeviceId;
/**
* Represents allocation of resource bound to device.
*
* @param <T> type of the resource
*/
@Beta
public final class DeviceResourceAllocation<T> extends AbstractResourceAllocation<DeviceId, T> {
/**
* Creates a new allocation of resource bound to the specified device and consumed by the specified user.
*
* @param device device identifier which this resource belongs to
* @param resource resource of the device
* @param consumer consumer of this resource
*/
public DeviceResourceAllocation(DeviceId device, T resource, ResourceConsumer consumer) {
super(device, resource, consumer);
}
}
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.newresource;
import com.google.common.annotations.Beta;
import org.onosproject.net.LinkKey;
/**
* Represents resource which belongs to a particular link.
*
* @param <T> represents the type of the resource
*/
@Beta
public final class LinkResource<T> extends AbstractResource<LinkKey, T> {
/**
* Creates a new link resource from the specified link identifier and resource.
* (linkKey, resource) signifies a resource identifier which is globally unique.
*
* @param linkKey link identifier which this resource belongs to
* @param resource resource of the link
*/
public LinkResource(LinkKey linkKey, T resource) {
super(linkKey, resource);
}
}
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.newresource;
import com.google.common.annotations.Beta;
import org.onosproject.net.LinkKey;
/**
* Represents allocation of resource bound to link.
*
* @param <T> type of the resource
*/
@Beta
public final class LinkResourceAllocation<T> extends AbstractResourceAllocation<LinkKey, T> {
/**
* Creates a new allocation of resource bound to the specified device and consumed by the specified user.
*
* @param link device identifier which this resource belongs to
* @param resource resource of the device
* @param consumer consumer of this resource
*/
public LinkResourceAllocation(LinkKey link, T resource, ResourceConsumer consumer) {
super(link, resource, consumer);
}
}