blob: 8f69a201e7368af8da0d12c96ec53fa3379d7e64 [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.converter;
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 converter object based on the ONOS event type.
27 *
28 */
29public final class ConversionFactory {
30
31 // Store converters for all supported events
32 private Map<Type, EventConverter> converters =
33 new HashMap<Type, EventConverter>() {
34 {
35 put(DEVICE, new DeviceEventConverter());
36 put(LINK, new LinkEventConverter());
37 }
38 };
39
40 // Exists to defeat instantiation
41 private ConversionFactory() {
42 }
43
44 private static class SingletonHolder {
45 private static final ConversionFactory INSTANCE =
46 new ConversionFactory();
47 }
48
49 /**
50 * Returns a static reference to the Conversion Factory.
51 *
52 * @return singleton object
53 */
54 public static ConversionFactory getInstance() {
55 return SingletonHolder.INSTANCE;
56 }
57
58 /**
59 * Returns an Event converter object for the specified ONOS event type.
60 *
61 * @param event ONOS event type
62 * @return Event Converter object
63 */
64 public EventConverter getConverter(Type event) {
65 return converters.get(event);
66 }
67
68}