2 * Copyright (c) 2017 Inocybe Technologies and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netvirt.aclservice.api;
10 import java.util.Collection;
11 import java.util.Map.Entry;
12 import java.util.function.BiConsumer;
13 import java.util.function.BiFunction;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.opendaylight.netvirt.aclservice.api.utils.AclInterface;
19 * Interface for an AclInterface cache.
21 * @author Thomas Pantelis
23 public interface AclInterfaceCache {
26 * Adds a new AclInterface if not already existing, otherwise updates the existing instance. In either case,
27 * the given updateFunction is used to build a new instance.
29 * @param interfaceId the interface Id
30 * @param updateFunction the function used to build a new instance from the provided AclInterface.Builder. If an
31 * instance already exists in the cache, the previous instance is passed to the function and
32 * the Builder is initially populated from the existing instance.
33 * @return the new or updated AclInterface
36 AclInterface addOrUpdate(@NonNull String interfaceId,
37 @NonNull BiConsumer<AclInterface, AclInterface.Builder> updateFunction);
40 * Updates an existing AclInterface instance in the cache. The given updateFunction is used to build a new instance.
42 * @param interfaceId the interface Id
43 * @param updateFunction the function used to build a new instance from the provided AclInterface.Builder. The
44 * previous instance is passed to the function and the Builder is initially populated from
45 * the existing instance. The function returns a boolean indicating if any updates were
47 * @return the updated AclInterface or null if no instance was present or no updates were made
50 AclInterface updateIfPresent(@NonNull String interfaceId,
51 @NonNull BiFunction<AclInterface, AclInterface.Builder, Boolean> updateFunction);
54 * Removes an AclInterface instance from the cache.
56 * @param interfaceId the interface Id
57 * @return the AclInterface if present, null oherwise
59 AclInterface remove(@NonNull String interfaceId);
62 * Gets an AclInterface instance from the cache if present.
64 * @param interfaceId the interface Id
65 * @return the AclInterface instance if found, null otherwise
68 AclInterface get(@NonNull String interfaceId);
71 Collection<Entry<String, AclInterface>> entries();