Ray Milkey | 2d572dd | 2017-04-14 10:01:24 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | ce2a03d | 2017-08-03 19:21:03 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Ray Milkey | 2d572dd | 2017-04-14 10:01:24 -0700 | [diff] [blame] | 3 | * |
Shravan Ambati | bb6b445 | 2016-05-04 13:25:28 -0700 | [diff] [blame] | 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 |
Ray Milkey | 2d572dd | 2017-04-14 10:01:24 -0700 | [diff] [blame] | 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
Shravan Ambati | bb6b445 | 2016-05-04 13:25:28 -0700 | [diff] [blame] | 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 | package org.onosproject.kafkaintegration.converter; |
| 17 | |
Sanjana Agarwal | cb4a3db | 2016-07-14 11:42:48 -0700 | [diff] [blame] | 18 | import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type; |
Shravan Ambati | bb6b445 | 2016-05-04 13:25:28 -0700 | [diff] [blame] | 19 | |
| 20 | import java.util.HashMap; |
| 21 | import java.util.Map; |
| 22 | |
Sanjana Agarwal | cb4a3db | 2016-07-14 11:42:48 -0700 | [diff] [blame] | 23 | import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.DEVICE; |
| 24 | import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.LINK; |
Shravan Ambati | bb6b445 | 2016-05-04 13:25:28 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Returns the appropriate converter object based on the ONOS event type. |
| 28 | * |
| 29 | */ |
| 30 | public 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 | } |