Migrate to 171221 revision of MEF NRP API
[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.params.xml.ns.yang.tapi.common.rev171113.Uuid;
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 to participate in connectivity service processing.
26      * @param context (de)activation context
27      * @return {@link Optional#empty()} in case it cannot be instantiated for a port, driver otherwise
28      */
29     Optional<ActivationDriver> driverFor(BuilderContext context);
30
31     Uuid getNodeUuid();
32
33     /**
34      * Blackboard pattern that allows for passing the context information between
35      * {@link ActivationDriverBuilder}s taking part in transaction.
36      */
37     class BuilderContext {
38         private Map<String, Object> ctx = new ConcurrentHashMap<>();
39
40         /**
41          * Get value of a certain type.
42          * @param key key
43          * @param <T> expected type
44          * @return value or empty
45          */
46         @SuppressWarnings("unchecked")
47         public <T> Optional<T> get(String key) {
48             return Optional.ofNullable((T) ctx.get(key));
49         }
50
51
52         /**
53          * Put value to blackboard.
54          * @param key key
55          * @param value value object
56          */
57         public void put(String key, Object value) {
58             ctx.put(key, value);
59         }
60
61         /**
62          * Remove value from blackboard.
63          * @param key key
64          */
65         public void remove(String key) {
66             ctx.remove(key);
67         }
68
69         /**
70          * Get all keys.
71          * @return available keys in blackboard
72          */
73         public Set<String> keys() {
74             return new HashSet<>(ctx.keySet());
75         }
76     }
77
78 }