blob: e0e8d760868a0019ae0c19710805d109f6c432ec [file] [log] [blame]
Ray Milkey2d572dd2017-04-14 10:01:24 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Ray Milkey2d572dd2017-04-14 10:01:24 -07003 *
Shravan Ambatibb6b4452016-05-04 13:25:28 -07004 * 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
Ray Milkey2d572dd2017-04-14 10:01:24 -07007 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
Shravan Ambatibb6b4452016-05-04 13:25:28 -070010 * 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 */
16package org.onosproject.kafkaintegration.converter;
17
Sanjana Agarwalcb4a3db2016-07-14 11:42:48 -070018import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type;
Shravan Ambatibb6b4452016-05-04 13:25:28 -070019
20import java.util.HashMap;
21import java.util.Map;
22
Sanjana Agarwalcb4a3db2016-07-14 11:42:48 -070023import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.DEVICE;
24import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.LINK;
Shravan Ambatibb6b4452016-05-04 13:25:28 -070025
26/**
27 * Returns the appropriate converter object based on the ONOS event type.
28 *
29 */
30public final class ConversionFactory {
31
32 // Store converters for all supported events
33 private Map<Type, EventConverter> converters =
34 new HashMap<Type, EventConverter>() {
35 {
36 put(DEVICE, new DeviceEventConverter());
37 put(LINK, new LinkEventConverter());
38 }
39 };
40
41 // Exists to defeat instantiation
42 private ConversionFactory() {
43 }
44
45 private static class SingletonHolder {
46 private static final ConversionFactory INSTANCE =
47 new ConversionFactory();
48 }
49
50 /**
51 * Returns a static reference to the Conversion Factory.
52 *
53 * @return singleton object
54 */
55 public static ConversionFactory getInstance() {
56 return SingletonHolder.INSTANCE;
57 }
58
59 /**
60 * Returns an Event converter object for the specified ONOS event type.
61 *
62 * @param event ONOS event type
63 * @return Event Converter object
64 */
65 public EventConverter getConverter(Type event) {
66 return converters.get(event);
67 }
68
69}