blob: 496ba2b1fe3331be1fe14d940266df040287e38d [file] [log] [blame]
Shravan Ambatibb6b4452016-05-04 13:25:28 -07001/**
2 * Copyright 2016 Open Networking Laboratory
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6
7 * http://www.apache.org/licenses/LICENSE-2.0
8
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15package org.onosproject.kafkaintegration.listener;
16
17import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.DEVICE;
18import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.LINK;
19
20import java.util.HashMap;
21import java.util.Map;
22
23import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type;
24
25/**
26 * Returns the appropriate listener object based on the ONOS event type.
27 *
28 */
29public final class ListenerFactory {
30
31 // Store listeners for all supported events
32 private Map<Type, OnosEventListener> listeners =
33 new HashMap<Type, OnosEventListener>() {
34 {
35 put(DEVICE, DeviceEventsListener.getInstance());
36 put(LINK, LinkEventsListener.getInstance());
37 }
38 };
39
40 // Exists to defeat instantiation
41 private ListenerFactory() {
42 }
43
44 private static class SingletonHolder {
45 private static final ListenerFactory INSTANCE = new ListenerFactory();
46 }
47
48 /**
49 * Returns a static reference to the Listener Factory.
50 *
51 * @return singleton object
52 */
53 public static ListenerFactory getInstance() {
54 return SingletonHolder.INSTANCE;
55 }
56
57 /**
58 * Returns the listener object for the specified ONOS event type.
59 *
60 * @param event ONOS Event type
61 * @return return listener object
62 */
63 public OnosEventListener getListener(Type event) {
64 return listeners.get(event);
65 }
66
67}