blob: 65b7cf1ed70b41ce62ac0d4352e494eb0d25c4e4 [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
Sanjana Agarwalcb4a3db2016-07-14 11:42:48 -070017import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type;
Shravan Ambatibb6b4452016-05-04 13:25:28 -070018
19import java.util.HashMap;
20import java.util.Map;
21
Sanjana Agarwalcb4a3db2016-07-14 11:42:48 -070022import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.DEVICE;
23import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.LINK;
Shravan Ambatibb6b4452016-05-04 13:25:28 -070024
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}