Add timeout to subscriber data
[lispflowmapping.git] / mappingservice / implementation / src / main / java / org / opendaylight / lispflowmapping / implementation / util / MSNotificationInputUtil.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.lispflowmapping.implementation.util;
10
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.Set;
14 import org.opendaylight.lispflowmapping.interfaces.dao.Subscriber;
15 import org.opendaylight.lispflowmapping.lisp.type.MappingData;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingChange;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingChanged;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingChangedBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.Mapping;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.changed.SubscriberItem;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.changed.SubscriberItemBuilder;
22
23 /**
24  * Utility class to convert a mapping change into a notification.
25  *
26  * @author Florin Coras
27  *
28  */
29 public final class MSNotificationInputUtil {
30     // Utility class, should not be instantiated
31     private MSNotificationInputUtil() {
32     }
33
34     public static MappingChanged toMappingChanged(Mapping input, MappingChange change) {
35         return new MappingChangedBuilder().setMappingRecord(input.getMappingRecord())
36                 .setChangeType(change).build();
37     }
38
39     public static MappingChanged toMappingChanged(MappingData mapping, Set<Subscriber> subscribers,
40             MappingChange change) {
41         List<SubscriberItem> subscriberList = new ArrayList<SubscriberItem>();
42         for (Subscriber subscriber : subscribers) {
43             subscriberList.add(new SubscriberItemBuilder().setSubscriberData(
44                     subscriber.getSubscriberData()).build());
45         }
46         return new MappingChangedBuilder().setMappingRecord(mapping.getRecord()).setSubscriberItem(subscriberList)
47                 .setChangeType(change).build();
48     }
49 }