use of org.onosproject.net.resource.ResourceConsumerId in project onos by opennetworkinglab.
the class ConsistentResourceStore method release.
@Override
public boolean release(List<ResourceAllocation> allocations) {
checkNotNull(allocations);
while (true) {
TransactionContext tx = service.transactionContextBuilder().build();
tx.begin();
TransactionalDiscreteResourceSubStore discreteTxStore = discreteStore.transactional(tx);
TransactionalContinuousResourceSubStore continuousTxStore = continuousStore.transactional(tx);
for (ResourceAllocation allocation : allocations) {
Resource resource = allocation.resource();
ResourceConsumerId consumerId = allocation.consumerId();
if (resource instanceof DiscreteResource) {
if (!discreteTxStore.release(consumerId, (DiscreteResource) resource)) {
return abortTransaction(tx);
}
} else if (resource instanceof ContinuousResource) {
if (!continuousTxStore.release(consumerId, (ContinuousResource) resource)) {
return abortTransaction(tx);
}
}
}
try {
if (commitTransaction(tx) == CommitStatus.SUCCESS) {
return true;
}
} catch (InterruptedException | ExecutionException | TimeoutException e) {
log.warn("Failed to release {}: {}", allocations, e);
return false;
}
}
}
use of org.onosproject.net.resource.ResourceConsumerId in project onos by opennetworkinglab.
the class TransactionalDiscreteResourceSubStore method allocate.
@Override
public boolean allocate(ResourceConsumerId consumerId, DiscreteResource resource) {
// if the resource is not registered, then abort
Optional<DiscreteResource> lookedUp = lookup(resource.id());
if (!lookedUp.isPresent()) {
return false;
}
ResourceConsumerId oldValue = consumers.put(resource.id(), consumerId);
return oldValue == null;
}
Aggregations