BUG 2302 : odl-clustering-test-app should not be part of the odl-restconf-all feature set
[controller.git] / opendaylight / clustering / services_implementation / src / main / java / org / opendaylight / controller / clustering / services_implementation / internal / CacheListenerContainer.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.controller.clustering.services_implementation.internal;
11
12 import org.infinispan.notifications.Listener;
13 import org.infinispan.notifications.cachelistener.annotation.CacheEntryCreated;
14 import org.infinispan.notifications.cachelistener.annotation.CacheEntryModified;
15 import org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved;
16 import org.infinispan.notifications.cachelistener.event.CacheEntryCreatedEvent;
17 import org.infinispan.notifications.cachelistener.event.CacheEntryModifiedEvent;
18 import org.infinispan.notifications.cachelistener.event.CacheEntryRemovedEvent;
19 import org.opendaylight.controller.clustering.services.IGetUpdates;
20
21 @Listener
22 public class CacheListenerContainer {
23     private IGetUpdates toBeUpdated;
24     private String containerName;
25     private String cacheName;
26
27     public CacheListenerContainer(IGetUpdates i, String containerName,
28             String cacheName) {
29         this.toBeUpdated = i;
30         this.containerName = containerName;
31         this.cacheName = cacheName;
32     }
33
34     public IGetUpdates whichListener() {
35         return this.toBeUpdated;
36     }
37
38     @CacheEntryCreated
39     public void observeCreate(CacheEntryCreatedEvent<Object, Object> event) {
40         if (event.isPre()) {
41             return;
42         }
43
44         if (this.toBeUpdated != null) {
45             this.toBeUpdated.entryCreated(event.getKey(), this.containerName,
46                     this.cacheName, event.isOriginLocal());
47         }
48     }
49
50     @CacheEntryModified
51     public void observeModify(CacheEntryModifiedEvent<Object, Object> event) {
52         if (event.isPre()) {
53             return;
54         }
55
56         if (this.toBeUpdated != null) {
57             this.toBeUpdated.entryUpdated(event.getKey(), event.getValue(),
58                     this.containerName, this.cacheName, event.isOriginLocal());
59         }
60     }
61
62     @CacheEntryRemoved
63     public void observeRemove(CacheEntryRemovedEvent<Object, Object> event) {
64         if (event.isPre()) {
65             return;
66         }
67
68         if (this.toBeUpdated != null) {
69             this.toBeUpdated.entryDeleted(event.getKey(), this.containerName,
70                     this.cacheName, event.isOriginLocal());
71         }
72     }
73 }