changing activation service logic to use presto-api module
[unimgr.git] / impl / src / main / java / org / opendaylight / unimgr / mef / nrp / api / ActivationDriverBuilder.java
1 /*
2  * Copyright (c) 2016 Cisco Systems Inc and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.unimgr.mef.nrp.api;
10
11 import java.util.HashSet;
12 import java.util.Map;
13 import java.util.Optional;
14 import java.util.Set;
15 import java.util.concurrent.ConcurrentHashMap;
16
17 import org.opendaylight.yang.gen.v1.urn.onf.core.network.module.rev160630.g_forwardingconstruct.FcPort;
18
19 /**
20  * Driver builder that can provide stateful driver that are used in NRP forwarding construct transaction.
21  * @author bartosz.michalik@amartus.com
22  */
23 public interface ActivationDriverBuilder {
24     /**
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
29      */
30     Optional<ActivationDriver> driverFor(FcPort port, BuilderContext context);
31
32     /**
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
38      */
39     Optional<ActivationDriver> driverFor(FcPort portA, FcPort portZ, BuilderContext context);
40
41     /**
42      * Blackboard pattern that allows for passing the context information between
43      * {@link ActivationDriverBuilder}s taking part in transaction.
44      */
45     class BuilderContext {
46         private Map<String, Object> ctx = new ConcurrentHashMap<>();
47
48         /**
49          * Get value of a certain type.
50          * @param key key
51          * @param <T> expected type
52          * @return value or empty
53          */
54         @SuppressWarnings("unchecked")
55         public <T> Optional<T> get(String key) {
56             return Optional.ofNullable((T) ctx.get(key));
57         }
58
59
60         /**
61          * Put value to blackboard.
62          * @param key key
63          * @param value value object
64          */
65         public void put(String key, Object value) {
66             ctx.put(key, value);
67         }
68
69         /**
70          * Remove value from blackboard.
71          * @param key key
72          */
73         public void remove(String key) {
74             ctx.remove(key);
75         }
76
77         /**
78          * Get all keys.
79          * @return available keys in blackboard
80          */
81         public Set<String> keys() {
82             return new HashSet<>(ctx.keySet());
83         }
84     }
85
86 }