2 * Copyright (c) 2016 Cisco Systems Inc 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
9 package org.opendaylight.unimgr.mef.nrp.api;
11 import java.util.HashSet;
13 import java.util.Optional;
15 import java.util.concurrent.ConcurrentHashMap;
17 import org.opendaylight.yang.gen.v1.urn.onf.core.network.module.rev160630.g_forwardingconstruct.FcPort;
20 * Driver builder that can provide stateful driver that are used in NRP forwarding construct transaction.
21 * @author bartosz.michalik@amartus.com
23 public interface ActivationDriverBuilder {
25 * Get driver for a single port.
26 * @param port to configure
27 * @param context (de)activation context
28 * @return {@link Optional#empty()} in case it cannot be instantiated for a port, driver otherwise
30 Optional<ActivationDriver> driverFor(FcPort port, BuilderContext context);
33 * Get driver for two ports.
34 * @param portA a-end port
35 * @param portZ z-end port
36 * @param context blackboard for recording state during driver selection
37 * @return {@link Optional#empty()} in case it cannot be instantiated for a port, driver otherwise
39 Optional<ActivationDriver> driverFor(FcPort portA, FcPort portZ, BuilderContext context);
42 * Blackboard pattern that allows for passing the context information between
43 * {@link ActivationDriverBuilder}s taking part in transaction.
45 class BuilderContext {
46 private Map<String, Object> ctx = new ConcurrentHashMap<>();
49 * Get value of a certain type.
51 * @param <T> expected type
52 * @return value or empty
54 @SuppressWarnings("unchecked")
55 public <T> Optional<T> get(String key) {
56 return Optional.ofNullable((T) ctx.get(key));
61 * Put value to blackboard.
63 * @param value value object
65 public void put(String key, Object value) {
70 * Remove value from blackboard.
73 public void remove(String key) {
79 * @return available keys in blackboard
81 public Set<String> keys() {
82 return new HashSet<>(ctx.keySet());