Shravan Ambati | bb6b445 | 2016-05-04 13:25:28 -0700 | [diff] [blame] | 1 | /** |
| 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 | */ |
| 15 | package org.onosproject.kafkaintegration.converter; |
| 16 | |
Sanjana Agarwal | cb4a3db | 2016-07-14 11:42:48 -0700 | [diff] [blame] | 17 | import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type; |
Shravan Ambati | bb6b445 | 2016-05-04 13:25:28 -0700 | [diff] [blame] | 18 | |
| 19 | import java.util.HashMap; |
| 20 | import java.util.Map; |
| 21 | |
Sanjana Agarwal | cb4a3db | 2016-07-14 11:42:48 -0700 | [diff] [blame] | 22 | import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.DEVICE; |
| 23 | import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.LINK; |
Shravan Ambati | bb6b445 | 2016-05-04 13:25:28 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * Returns the appropriate converter object based on the ONOS event type. |
| 27 | * |
| 28 | */ |
| 29 | public 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 | } |