blob: db5beccae21c82abe0ae99f5585cc88da81666ea [file] [log] [blame]
Yi Tsengc927a062017-05-02 15:02:37 -07001/*
2 * Copyright 2017-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.net.intent.impl;
18
19import com.google.common.collect.ImmutableMap;
20import com.google.common.collect.Maps;
21import org.onosproject.net.intent.Intent;
22import org.onosproject.net.intent.IntentInstaller;
23
24import java.util.Map;
25
26/**
27 * The local registry for Intent installer.
28 */
29public class InstallerRegistry {
30 private final Map<Class<? extends Intent>, IntentInstaller<? extends Intent>> installers;
31
32 public InstallerRegistry() {
33 installers = Maps.newConcurrentMap();
34 }
35
36 /**
37 * Registers the specific installer for the given intent class.
38 *
39 * @param cls intent class
40 * @param installer intent installer
41 * @param <T> the type of intent
42 */
43 public <T extends Intent> void registerInstaller(Class<T> cls, IntentInstaller<T> installer) {
44 installers.put(cls, installer);
45 }
46
47 /**
48 * Unregisters the installer for the specific intent class.
49 *
50 * @param cls intent class
51 * @param <T> the type of intent
52 */
53 public <T extends Intent> void unregisterInstaller(Class<T> cls) {
54 installers.remove(cls);
55 }
56
57 /**
58 * Returns immutable set of binding of currently registered intent installers.
59 *
60 * @return the set of installer bindings
61 */
62 public Map<Class<? extends Intent>, IntentInstaller<? extends Intent>> getInstallers() {
63 return ImmutableMap.copyOf(installers);
64 }
65
66 /**
67 * Get an Intent installer by given Intent type.
68 *
69 * @param cls the Intent type
70 * @param <T> the Intent type
71 * @return the Intent installer of the Intent type if exists; null otherwise
72 */
73 public <T extends Intent> IntentInstaller<T> getInstaller(Class<T> cls) {
74 return (IntentInstaller<T>) installers.get(cls);
75 }
76}