Merge "Introduce ASYNC caches and use them in FRM"
[controller.git] / opendaylight / clustering / services_implementation / src / main / java / org / opendaylight / controller / clustering / services_implementation / internal / ClusterManager.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 java.net.InetAddress;
13 import java.net.NetworkInterface;
14 import java.net.SocketException;
15 import java.net.UnknownHostException;
16 import java.util.ArrayList;
17 import java.util.EnumSet;
18 import java.util.Enumeration;
19 import java.util.HashSet;
20 import java.util.List;
21 import java.util.Properties;
22 import java.util.Set;
23 import java.util.StringTokenizer;
24 import java.util.concurrent.ConcurrentMap;
25
26 import javax.transaction.HeuristicMixedException;
27 import javax.transaction.HeuristicRollbackException;
28 import javax.transaction.NotSupportedException;
29 import javax.transaction.RollbackException;
30 import javax.transaction.SystemException;
31 import javax.transaction.Transaction;
32 import javax.transaction.TransactionManager;
33
34 import org.infinispan.Cache;
35 import org.infinispan.configuration.cache.Configuration;
36 import org.infinispan.configuration.cache.ConfigurationBuilder;
37 import org.infinispan.configuration.global.GlobalConfigurationBuilder;
38 import org.infinispan.configuration.parsing.ConfigurationBuilderHolder;
39 import org.infinispan.configuration.parsing.ParserRegistry;
40 import org.infinispan.manager.DefaultCacheManager;
41 import org.infinispan.manager.EmbeddedCacheManager;
42 import org.infinispan.notifications.Listener;
43 import org.infinispan.notifications.cachemanagerlistener.annotation.ViewChanged;
44 import org.infinispan.notifications.cachemanagerlistener.event.ViewChangedEvent;
45 import org.infinispan.remoting.transport.Address;
46 import org.infinispan.remoting.transport.Transport;
47 import org.infinispan.remoting.transport.jgroups.JGroupsAddress;
48 import org.infinispan.remoting.transport.jgroups.JGroupsTransport;
49 import org.jgroups.Channel;
50 import org.jgroups.Event;
51 import org.jgroups.stack.GossipRouter;
52 import org.opendaylight.controller.clustering.services.CacheConfigException;
53 import org.opendaylight.controller.clustering.services.CacheExistException;
54 import org.opendaylight.controller.clustering.services.CacheListenerAddException;
55 import org.opendaylight.controller.clustering.services.IClusterServices;
56 import org.opendaylight.controller.clustering.services.IGetUpdates;
57 import org.opendaylight.controller.clustering.services.IListenRoleChange;
58 import org.opendaylight.controller.clustering.services.ListenRoleChangeAddException;
59 import org.slf4j.Logger;
60 import org.slf4j.LoggerFactory;
61
62 public class ClusterManager implements IClusterServices {
63     protected static final Logger logger = LoggerFactory
64             .getLogger(ClusterManager.class);
65     private DefaultCacheManager cm;
66     GossipRouter gossiper;
67     private HashSet<IListenRoleChange> roleChangeListeners;
68     private ViewChangedListener cacheManagerListener;
69
70     private static String loopbackAddress = "127.0.0.1";
71
72     /**
73      * Start a JGroups GossipRouter if we are a supernode. The
74      * GosispRouter is nothing more than a simple
75      * rendevouz-pointer. All the nodes that wants to join the cluster
76      * will come to any of the rendevouz point and they introduce the
77      * nodes to all the others. Once the meet and greet phase if over,
78      * the nodes will open a full-mesh with the remaining n-1 nodes,
79      * so even if the GossipRouter goes down nothing is lost.
80      * NOTE: This function has the side effect to set some of the
81      * JGROUPS configurations, this because in this function already
82      * we try to retrieve some of the network capabilities of the
83      * device and so it's better not to do that again
84      *
85      *
86      * @return GossipRouter
87      */
88     private GossipRouter startGossiper() {
89         boolean amIGossipRouter = false;
90         Integer gossipRouterPortDefault = 12001;
91         Integer gossipRouterPort = gossipRouterPortDefault;
92         InetAddress gossipRouterAddress = null;
93         String supernodes_list = System.getProperty("supernodes",
94                 loopbackAddress);
95         StringBuffer sanitized_supernodes_list = new StringBuffer();
96         List<InetAddress> myAddresses = new ArrayList<InetAddress>();
97
98         StringTokenizer supernodes = new StringTokenizer(supernodes_list, ":");
99         if (supernodes.hasMoreTokens()) {
100             // Populate the list of my addresses
101             try {
102                 Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
103                 while (e.hasMoreElements()) {
104                     NetworkInterface n = e.nextElement();
105                     Enumeration<InetAddress> ee = n.getInetAddresses();
106                     while (ee.hasMoreElements()) {
107                         InetAddress i = ee.nextElement();
108                         myAddresses.add(i);
109                     }
110                 }
111             } catch (SocketException se) {
112                 logger.error("Cannot get the list of network interfaces");
113                 return null;
114             }
115         }
116         while (supernodes.hasMoreTokens()) {
117             String curr_supernode = supernodes.nextToken();
118             logger.debug("Examining supernode {}", curr_supernode);
119             StringTokenizer host_port = new StringTokenizer(curr_supernode,
120                     "[]");
121             String host;
122             String port;
123             Integer port_num = gossipRouterPortDefault;
124             if (host_port.countTokens() > 2) {
125                 logger.error("Error parsing supernode {} proceed to the next one",
126                         curr_supernode);
127                 continue;
128             }
129             host = host_port.nextToken();
130             InetAddress hostAddr;
131             try {
132                 hostAddr = InetAddress.getByName(host);
133             } catch (UnknownHostException ue) {
134                 logger.error("Host not known");
135                 continue;
136             }
137             if (host_port.hasMoreTokens()) {
138                 port = host_port.nextToken();
139                 try {
140                     port_num = Integer.valueOf(port);
141                 } catch (NumberFormatException ne) {
142                     logger
143                             .error("Supplied supernode gossiepr port is not recognized, using standard gossipport");
144                     port_num = gossipRouterPortDefault;
145                 }
146                 if ((port_num > 65535) || (port_num < 0)) {
147                     logger
148                             .error("Supplied supernode gossip port is outside a valid TCP port range");
149                     port_num = gossipRouterPortDefault;
150                 }
151             }
152             if (!amIGossipRouter) {
153                 if (host != null) {
154                     for (InetAddress myAddr : myAddresses) {
155                         if (myAddr.equals(hostAddr)) {
156                             amIGossipRouter = true;
157                             gossipRouterAddress = hostAddr;
158                             gossipRouterPort = port_num;
159                             break;
160                         }
161                     }
162                 }
163             }
164             if (!sanitized_supernodes_list.toString().equals("")) {
165                 sanitized_supernodes_list.append(",");
166             }
167             sanitized_supernodes_list.append(hostAddr.getHostAddress() + "["
168                     + port_num + "]");
169         }
170
171         if (amIGossipRouter) {
172             // Set the Jgroups binding interface to the one we got
173             // from the supernodes attribute
174             if (gossipRouterAddress != null) {
175                 System.setProperty("jgroups.tcp.address", gossipRouterAddress
176                         .getHostAddress());
177             }
178         } else {
179             // Set the Jgroup binding interface to the one we are well
180             // known outside or else to the first with non-local
181             // scope.
182             try {
183                 String myBind = InetAddress.getLocalHost().getHostAddress();
184                 if (myBind == null
185                         || InetAddress.getLocalHost().isLoopbackAddress()) {
186                     for (InetAddress myAddr : myAddresses) {
187                         if (myAddr.isLoopbackAddress()
188                                 || myAddr.isLinkLocalAddress()) {
189                             logger.debug("Skipping local address {}",
190                                          myAddr.getHostAddress());
191                             continue;
192                         } else {
193                             // First non-local address
194                             myBind = myAddr.getHostAddress();
195                             logger.debug("First non-local address {}", myBind);
196                             break;
197                         }
198                     }
199                 }
200                 String jgroupAddress = System
201                         .getProperty("jgroups.tcp.address");
202                 if (jgroupAddress == null) {
203                     if (myBind != null) {
204                         logger.debug("Set bind address to be {}", myBind);
205                         System.setProperty("jgroups.tcp.address", myBind);
206                     } else {
207                         logger
208                                 .debug("Set bind address to be LOCALHOST=127.0.0.1");
209                         System.setProperty("jgroups.tcp.address", "127.0.0.1");
210                     }
211                 } else {
212                     logger.debug("jgroup.tcp.address already set to be {}",
213                             jgroupAddress);
214                 }
215             } catch (UnknownHostException uhe) {
216                 logger
217                         .error("Met UnknownHostException while trying to get binding address for jgroups");
218             }
219         }
220
221         // The supernodes list constitute also the tcpgossip initial
222         // host list
223         System.setProperty("jgroups.tcpgossip.initial_hosts",
224                 sanitized_supernodes_list.toString());
225         logger.debug("jgroups.tcp.address set to {}",
226                 System.getProperty("jgroups.tcp.address"));
227         logger.debug("jgroups.tcpgossip.initial_hosts set to {}",
228                 System.getProperty("jgroups.tcpgossip.initial_hosts"));
229         GossipRouter res = null;
230         if (amIGossipRouter) {
231             logger.info("I'm a GossipRouter will listen on port {}",
232                     gossipRouterPort);
233             // Start a GossipRouter with JMX support
234             res = new GossipRouter(gossipRouterPort, null, true);
235         }
236         return res;
237     }
238
239     public void start() {
240         this.gossiper = startGossiper();
241         if (this.gossiper != null) {
242             logger.debug("Trying to start Gossiper");
243             try {
244                 this.gossiper.start();
245                 logger.info("Started GossipRouter");
246             } catch (Exception e) {
247                 logger.error("GossipRouter didn't start. Exception Stack Trace",
248                              e);
249             }
250         }
251         logger.info("Starting the ClusterManager");
252         try {
253             ParserRegistry parser = new ParserRegistry(this.getClass()
254                     .getClassLoader());
255             String infinispanConfigFile =
256                     System.getProperty("org.infinispan.config.file", "config/infinispan-config.xml");
257             logger.debug("Using configuration file:{}", infinispanConfigFile);
258             ConfigurationBuilderHolder holder = parser.parseFile(infinispanConfigFile);
259             GlobalConfigurationBuilder globalBuilder = holder.getGlobalConfigurationBuilder();
260             globalBuilder.serialization()
261                     .classResolver(new ClassResolver())
262                     .build();
263             this.cm = new DefaultCacheManager(holder, false);
264             logger.debug("Allocated ClusterManager");
265             if (this.cm != null) {
266                 this.cm.start();
267                 this.cm.startCache();
268                 logger.debug("Started the ClusterManager");
269             }
270         } catch (Exception ioe) {
271             logger.error("Cannot configure infinispan .. bailing out ");
272             logger.error("Stack Trace that raised th exception");
273             logger.error("",ioe);
274             this.cm = null;
275             this.stop();
276         }
277         logger.debug("Cache Manager has value {}", this.cm);
278     }
279
280     public void stop() {
281         logger.info("Stopping the ClusterManager");
282         if (this.cm != null) {
283             logger.info("Found a valid ClusterManager, now let it be stopped");
284             this.cm.stop();
285             this.cm = null;
286         }
287         if (this.gossiper != null) {
288             this.gossiper.stop();
289             this.gossiper = null;
290         }
291     }
292
293     @Override
294     public ConcurrentMap<?, ?> createCache(String containerName,
295             String cacheName, Set<cacheMode> cMode) throws CacheExistException,
296             CacheConfigException {
297         EmbeddedCacheManager manager = this.cm;
298         Cache<Object,Object> c;
299         String realCacheName = "{" + containerName + "}_{" + cacheName + "}";
300         if (manager == null) {
301             return null;
302         }
303
304         if (manager.cacheExists(realCacheName)) {
305             throw new CacheExistException();
306         }
307
308         // Sanity check to avoid contrasting parameters between transactional
309         // and not
310         if (cMode.containsAll(EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL,
311                 IClusterServices.cacheMode.TRANSACTIONAL))) {
312             throw new CacheConfigException();
313         }
314
315         // Sanity check to avoid contrasting parameters between sync and async
316         if (cMode.containsAll(EnumSet.of(IClusterServices.cacheMode.SYNC, IClusterServices.cacheMode.ASYNC))) {
317             throw new CacheConfigException();
318         }
319
320         Configuration fromTemplateConfig = null;
321         /*
322          * Fetch transactional/non-transactional templates
323          */
324         // Check if transactional
325         if (cMode.contains(IClusterServices.cacheMode.TRANSACTIONAL)) {
326             fromTemplateConfig = manager.getCacheConfiguration("transactional-type");
327         } else if (cMode.contains(IClusterServices.cacheMode.NON_TRANSACTIONAL)) {
328             fromTemplateConfig = manager.getDefaultCacheConfiguration();
329         }
330
331         // If none set the transactional property then just return null
332         if (fromTemplateConfig == null) {
333             return null;
334         }
335
336         ConfigurationBuilder builder = new ConfigurationBuilder();
337         builder.read(fromTemplateConfig);
338         /*
339          * Now evaluate async/sync
340          */
341         if (cMode.contains(IClusterServices.cacheMode.ASYNC)) {
342             builder.clustering()
343                     .cacheMode(fromTemplateConfig.clustering()
344                             .cacheMode()
345                             .toAsync());
346         } else if (cMode.contains(IClusterServices.cacheMode.SYNC)) {
347             builder.clustering()
348                     .cacheMode(fromTemplateConfig.clustering()
349                             .cacheMode()
350                             .toSync());
351         }
352
353         manager.defineConfiguration(realCacheName, builder.build());
354         c = manager.getCache(realCacheName);
355         return c;
356     }
357
358     @Override
359     public ConcurrentMap<?, ?> getCache(String containerName, String cacheName) {
360         EmbeddedCacheManager manager = this.cm;
361         Cache<Object,Object> c;
362         String realCacheName = "{" + containerName + "}_{" + cacheName + "}";
363         if (manager == null) {
364             return null;
365         }
366
367         if (manager.cacheExists(realCacheName)) {
368             c = manager.getCache(realCacheName);
369             return c;
370         }
371         return null;
372     }
373
374     @Override
375     public void destroyCache(String containerName, String cacheName) {
376         EmbeddedCacheManager manager = this.cm;
377         String realCacheName = "{" + containerName + "}_{" + cacheName + "}";
378         if (manager == null) {
379             return;
380         }
381         if (manager.cacheExists(realCacheName)) {
382             manager.removeCache(realCacheName);
383         }
384     }
385
386     @Override
387     public boolean existCache(String containerName, String cacheName) {
388         EmbeddedCacheManager manager = this.cm;
389         String realCacheName = "{" + containerName + "}_{" + cacheName + "}";
390         if (manager == null) {
391             return false;
392         }
393         return manager.cacheExists(realCacheName);
394     }
395
396     @Override
397     public Set<String> getCacheList(String containerName) {
398         Set<String> perContainerCaches = new HashSet<String>();
399         EmbeddedCacheManager manager = this.cm;
400         if (manager == null) {
401             return null;
402         }
403         for (String cacheName : manager.getCacheNames()) {
404             if (!manager.isRunning(cacheName)) continue;
405             if (cacheName.startsWith("{" + containerName + "}_")) {
406                 String[] res = cacheName.split("[{}]");
407                 if (res.length >= 4 && res[1].equals(containerName)
408                         && res[2].equals("_")) {
409                     perContainerCaches.add(res[3]);
410                 }
411             }
412         }
413
414         return (perContainerCaches);
415     }
416
417     @Override
418     public Properties getCacheProperties(String containerName, String cacheName) {
419         EmbeddedCacheManager manager = this.cm;
420         if (manager == null) {
421             return null;
422         }
423         String realCacheName = "{" + containerName + "}_{" + cacheName + "}";
424         if (!manager.cacheExists(realCacheName)) {
425             return null;
426         }
427         Configuration conf = manager.getCache(realCacheName).getAdvancedCache()
428                 .getCacheConfiguration();
429         Properties p = new Properties();
430         p.setProperty(IClusterServices.cacheProps.TRANSACTION_PROP.toString(),
431                 conf.transaction().toString());
432         p.setProperty(IClusterServices.cacheProps.CLUSTERING_PROP.toString(),
433                 conf.clustering().toString());
434         p.setProperty(IClusterServices.cacheProps.LOCKING_PROP.toString(), conf
435                 .locking().toString());
436         return p;
437     }
438
439     @Override
440     public void addListener(String containerName, String cacheName,
441             IGetUpdates<?, ?> u) throws CacheListenerAddException {
442         EmbeddedCacheManager manager = this.cm;
443         Cache<Object,Object> c;
444         String realCacheName = "{" + containerName + "}_{" + cacheName + "}";
445         if (manager == null) {
446             return;
447         }
448
449         if (!manager.cacheExists(realCacheName)) {
450             throw new CacheListenerAddException();
451         }
452         c = manager.getCache(realCacheName);
453         CacheListenerContainer cl = new CacheListenerContainer(u,
454                 containerName, cacheName);
455         c.addListener(cl);
456     }
457
458     @Override
459     public Set<IGetUpdates<?, ?>> getListeners(String containerName,
460             String cacheName) {
461         EmbeddedCacheManager manager = this.cm;
462         Cache<Object,Object> c;
463         String realCacheName = "{" + containerName + "}_{" + cacheName + "}";
464         if (manager == null) {
465             return null;
466         }
467
468         if (!manager.cacheExists(realCacheName)) {
469             return null;
470         }
471         c = manager.getCache(realCacheName);
472
473         Set<IGetUpdates<?, ?>> res = new HashSet<IGetUpdates<?, ?>>();
474         Set<Object> listeners = c.getListeners();
475         for (Object listener : listeners) {
476             if (listener instanceof CacheListenerContainer) {
477                 CacheListenerContainer cl = (CacheListenerContainer) listener;
478                 res.add(cl.whichListener());
479             }
480         }
481
482         return res;
483     }
484
485     @Override
486     public void removeListener(String containerName, String cacheName,
487             IGetUpdates<?, ?> u) {
488         EmbeddedCacheManager manager = this.cm;
489         Cache<Object,Object> c;
490         String realCacheName = "{" + containerName + "}_{" + cacheName + "}";
491         if (manager == null) {
492             return;
493         }
494
495         if (!manager.cacheExists(realCacheName)) {
496             return;
497         }
498         c = manager.getCache(realCacheName);
499
500         Set<Object> listeners = c.getListeners();
501         for (Object listener : listeners) {
502             if (listener instanceof CacheListenerContainer) {
503                 CacheListenerContainer cl = (CacheListenerContainer) listener;
504                 if (cl.whichListener() == u) {
505                     c.removeListener(listener);
506                     return;
507                 }
508             }
509         }
510     }
511
512     @Override
513     public void tbegin() throws NotSupportedException, SystemException {
514         EmbeddedCacheManager manager = this.cm;
515         if (manager == null) {
516             throw new IllegalStateException();
517         }
518         TransactionManager tm = manager.getCache("transactional-type")
519                 .getAdvancedCache().getTransactionManager();
520         if (tm == null) {
521             throw new IllegalStateException();
522         }
523         tm.begin();
524     }
525
526     @Override
527     public void tcommit() throws RollbackException, HeuristicMixedException,
528             HeuristicRollbackException, java.lang.SecurityException,
529             java.lang.IllegalStateException, SystemException {
530         EmbeddedCacheManager manager = this.cm;
531         if (manager == null) {
532             throw new IllegalStateException();
533         }
534         TransactionManager tm = manager.getCache("transactional-type")
535                 .getAdvancedCache().getTransactionManager();
536         if (tm == null) {
537             throw new IllegalStateException();
538         }
539         tm.commit();
540     }
541
542     @Override
543     public void trollback() throws java.lang.IllegalStateException,
544             java.lang.SecurityException, SystemException {
545         EmbeddedCacheManager manager = this.cm;
546         if (manager == null) {
547             throw new IllegalStateException();
548         }
549         TransactionManager tm = manager.getCache("transactional-type")
550                 .getAdvancedCache().getTransactionManager();
551         if (tm == null) {
552             throw new IllegalStateException();
553         }
554         tm.rollback();
555     }
556
557     @Override
558     public Transaction tgetTransaction() throws SystemException {
559         EmbeddedCacheManager manager = this.cm;
560         if (manager == null) {
561             throw new IllegalStateException();
562         }
563         TransactionManager tm = manager.getCache("transactional-type")
564                 .getAdvancedCache().getTransactionManager();
565         if (tm == null) {
566             return null;
567         }
568         return tm.getTransaction();
569     }
570
571     @Override
572     public boolean amIStandby() {
573         EmbeddedCacheManager manager = this.cm;
574         if (manager == null) {
575             // In case we cannot fetch the information, lets assume we
576             // are standby, so to have less responsibility.
577             return true;
578         }
579         return (!manager.isCoordinator());
580     }
581
582     private InetAddress addressToInetAddress(Address a) {
583         EmbeddedCacheManager manager = this.cm;
584         if ((manager == null) || (a == null)) {
585             // In case we cannot fetch the information, lets assume we
586             // are standby, so to have less responsibility.
587             return null;
588         }
589         Transport t = manager.getTransport();
590         if (t instanceof JGroupsTransport) {
591             JGroupsTransport jt = (JGroupsTransport) t;
592             Channel c = jt.getChannel();
593             if (a instanceof JGroupsAddress) {
594                 JGroupsAddress ja = (JGroupsAddress) a;
595                 org.jgroups.Address phys = (org.jgroups.Address) c
596                         .down(new Event(Event.GET_PHYSICAL_ADDRESS, ja
597                                 .getJGroupsAddress()));
598                 if (phys instanceof org.jgroups.stack.IpAddress) {
599                     InetAddress bindAddress = ((org.jgroups.stack.IpAddress) phys)
600                             .getIpAddress();
601                     return bindAddress;
602                 }
603             }
604         }
605         return null;
606     }
607
608     @Override
609     public List<InetAddress> getClusteredControllers() {
610         EmbeddedCacheManager manager = this.cm;
611         if (manager == null) {
612             return null;
613         }
614         List<Address> controllers = manager.getMembers();
615         if ((controllers == null) || controllers.size() == 0) {
616             return null;
617         }
618
619         List<InetAddress> clusteredControllers = new ArrayList<InetAddress>();
620         for (Address a : controllers) {
621             InetAddress inetAddress = addressToInetAddress(a);
622             if (inetAddress != null
623                     && !inetAddress.getHostAddress().equals(loopbackAddress)) {
624                 clusteredControllers.add(inetAddress);
625             }
626         }
627         return clusteredControllers;
628     }
629
630     @Override
631     public InetAddress getMyAddress() {
632         EmbeddedCacheManager manager = this.cm;
633         if (manager == null) {
634             return null;
635         }
636         return addressToInetAddress(manager.getAddress());
637     }
638
639     @Override
640     public InetAddress getActiveAddress() {
641         EmbeddedCacheManager manager = this.cm;
642         if (manager == null) {
643             // In case we cannot fetch the information, lets assume we
644             // are standby, so to have less responsibility.
645             return null;
646         }
647
648         return addressToInetAddress(manager.getCoordinator());
649     }
650
651     @Override
652     public void listenRoleChange(IListenRoleChange i)
653             throws ListenRoleChangeAddException {
654         EmbeddedCacheManager manager = this.cm;
655         if (manager == null) {
656             // In case we cannot fetch the information, lets assume we
657             // are standby, so to have less responsibility.
658             throw new ListenRoleChangeAddException();
659         }
660
661         if (this.roleChangeListeners == null) {
662             this.roleChangeListeners = new HashSet<IListenRoleChange>();
663             this.cacheManagerListener = new ViewChangedListener(
664                     this.roleChangeListeners);
665             manager.addListener(this.cacheManagerListener);
666         }
667
668         if (this.roleChangeListeners != null) {
669             this.roleChangeListeners.add(i);
670         }
671     }
672
673     @Override
674     public void unlistenRoleChange(IListenRoleChange i) {
675         EmbeddedCacheManager manager = this.cm;
676         if (manager == null) {
677             // In case we cannot fetch the information, lets assume we
678             // are standby, so to have less responsibility.
679             return;
680         }
681
682         if (this.roleChangeListeners != null) {
683             this.roleChangeListeners.remove(i);
684         }
685
686         if ((this.roleChangeListeners != null && this.roleChangeListeners
687                 .isEmpty())
688                 && (this.cacheManagerListener != null)) {
689             manager.removeListener(this.cacheManagerListener);
690             this.cacheManagerListener = null;
691             this.roleChangeListeners = null;
692         }
693     }
694
695     @Listener
696     public class ViewChangedListener {
697         Set<IListenRoleChange> roleListeners;
698
699         public ViewChangedListener(Set<IListenRoleChange> s) {
700             this.roleListeners = s;
701         }
702
703         @ViewChanged
704         public void viewChanged(ViewChangedEvent e) {
705             for (IListenRoleChange i : this.roleListeners) {
706                 i.newActiveAvailable();
707             }
708         }
709     }
710 }