1 22 package org.jboss.test.cluster.drm; 23 24 import java.io.Serializable ; 25 import java.util.List ; 26 import javax.management.Notification ; 27 import javax.naming.InitialContext ; 28 29 import org.jboss.ha.framework.interfaces.DistributedReplicantManager; 30 import org.jboss.ha.framework.interfaces.DistributedReplicantManager.ReplicantListener; 31 import org.jboss.ha.framework.interfaces.HAPartition; 32 import org.jboss.logging.Logger; 33 import org.jboss.mx.util.JBossNotificationBroadcasterSupport; 34 35 40 public class DRMUser extends JBossNotificationBroadcasterSupport 41 implements IReplicants, ReplicantListener 42 { 43 protected static Logger log = Logger.getLogger(DRMUser.class); 44 45 protected DistributedReplicantManager drm; 46 protected String category = "DRMUser"; 47 protected String partitionName = "DefaultPartition"; 48 protected long sequence; 49 50 public String getPartitionName() 51 { 52 return partitionName; 53 } 54 public void setPartitionName(String partitionName) 55 { 56 this.partitionName = partitionName; 57 } 58 59 public String getCategory() 60 { 61 return category; 62 } 63 public void setCategory(String category) 64 { 65 this.category = category; 66 } 67 68 public void start() throws Exception 69 { 70 InitialContext ctx = new InitialContext (); 72 String jndiName = "/HAPartition/" + partitionName; 73 HAPartition partition = (HAPartition) ctx.lookup(jndiName); 74 drm = partition.getDistributedReplicantManager(); 75 log.debug("Obtained DistributedReplicantManager from partition="+partitionName); 76 drm.registerListener(category, this); 77 String address = System.getProperty("jboss.bind.address"); 79 drm.add(category, address); 80 log.info("Added: "+address+" under key: "+category); 81 } 82 public void stop() throws Exception 83 { 84 drm.remove(category); 85 drm.unregisterListener(category, this); 86 } 87 88 public Serializable lookupLocalReplicant() 89 { 90 return drm.lookupLocalReplicant(category); 91 } 92 public Serializable lookupLocalReplicant(String key) 93 { 94 return drm.lookupLocalReplicant(key); 95 } 96 97 public List lookupReplicants() 98 { 99 return drm.lookupReplicants(category); 100 } 101 public List lookupReplicants(String key) 102 { 103 return drm.lookupReplicants(key); 104 } 105 public void add(String key, Serializable data) 106 throws Exception 107 { 108 drm.add(key, data); 109 } 110 public void remove(String key) 111 throws Exception 112 { 113 drm.remove(key); 114 } 115 private synchronized long nextSequence() 116 { 117 return sequence ++; 118 } 119 120 public void replicantsChanged(String key, List newReplicants, int newReplicantsViewId) 121 { 122 NotifyData data = new NotifyData(); 123 data.key = key; 124 data.newReplicants = newReplicants; 125 data.newReplicantsViewId = newReplicantsViewId; 126 String address = System.getProperty("jboss.bind.address"); 127 long id = nextSequence(); 128 Notification msg = new Notification ("replicantsChanged", this, id, address); 129 msg.setUserData(data); 130 log.info("replicantsChanged, "+msg); 131 super.sendNotification(msg); 132 } 133 } 134 | Popular Tags |