KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > shiftone > cache > decorator > cluster > ClusterConsumer


1 package org.shiftone.cache.decorator.cluster;
2
3
4
5 import org.jgroups.Address;
6 import org.jgroups.blocks.NotificationBus;
7 import org.shiftone.cache.util.Log;
8
9 import java.io.Serializable JavaDoc;
10
11
12 /**
13  * @version $Revision: 1.2 $
14  * @author $Author: jeffdrost $
15  */

16 public class ClusterConsumer implements NotificationBus.Consumer
17 {
18
19     private static final Log LOG = new Log(ClusterConsumer.class);
20     private final ClusterBus bus;
21     private final ClusterCacheFactory clusterCacheFactory;
22     private int members = 0;
23
24     public ClusterConsumer(ClusterBus bus)
25     {
26         this.bus = bus;
27         this.clusterCacheFactory = bus.getClusterCacheFactory();
28     }
29
30
31     public void handleNotification(Serializable JavaDoc serializable)
32     {
33
34         if (serializable instanceof Notification)
35         {
36             clusterCacheFactory.handleNotification((Notification) serializable);
37         }
38     }
39
40
41     public Serializable JavaDoc getCache()
42     {
43         return null;
44     }
45
46
47     public synchronized void memberJoined(Address address)
48     {
49
50         LOG.info("memberJoined " + address);
51
52         members++;
53
54         updateAlone();
55     }
56
57
58     public synchronized void memberLeft(Address address)
59     {
60
61         LOG.info("memberJoined " + address);
62
63         members--;
64
65         updateAlone();
66     }
67
68
69     private void updateAlone()
70     {
71         bus.setAloneInCluster(members == 1);
72     }
73 }
74
Popular Tags