use of org.opendaylight.netvirt.aclservice.api.utils.AclInterface.Builder in project netvirt by opendaylight.
the class AclInterfaceCacheImpl method updateIfPresent.
@Override
public AclInterface updateIfPresent(String interfaceId, BiFunction<AclInterface, AclInterface.Builder, Boolean> updateFunction) {
final AtomicBoolean updated = new AtomicBoolean(false);
AclInterface aclInterface = cache.computeIfPresent(interfaceId, (key, prevAclInterface) -> {
Builder builder = AclInterface.builder(prevAclInterface);
updated.set(updateFunction.apply(prevAclInterface, builder));
return builder.build();
});
return updated.get() ? aclInterface : null;
}
use of org.opendaylight.netvirt.aclservice.api.utils.AclInterface.Builder in project netvirt by opendaylight.
the class AclInterfaceCacheImpl method addOrUpdate.
@Override
public AclInterface addOrUpdate(@Nonnull String interfaceId, BiConsumer<AclInterface, AclInterface.Builder> updateFunction) {
while (true) {
// First try to update the existing instance in the cache if one exists.
AclInterface aclInterface = cache.computeIfPresent(interfaceId, (key, prevAclInterface) -> {
Builder builder = AclInterface.builder(prevAclInterface);
updateFunction.accept(prevAclInterface, builder);
return builder.build();
});
if (aclInterface == null) {
// No existing instance so try to put a new one.
Builder builder = AclInterface.builder();
builder.interfaceId(interfaceId);
updateFunction.accept(null, builder);
aclInterface = builder.build();
if (cache.putIfAbsent(interfaceId, aclInterface) == null) {
// The new instance was added.
return aclInterface;
}
// The new instance wasn't added - some one else beat us to it. Loop back up and try again.
} else {
return aclInterface;
}
}
}
Aggregations