1 9 package org.jboss.mx.remoting; 10 11 import java.io.Serializable ; 12 import javax.management.MBeanServer ; 13 import javax.management.ObjectName ; 14 import org.jboss.remoting.ConnectionFailedException; 15 import org.jboss.remoting.ident.Identity; 16 import org.jboss.remoting.loading.ClassUtil; 17 18 25 public class MBeanLocator implements Serializable 26 { 27 static final long serialVersionUID = -95280512054710509L; 28 29 private final Identity identity; 30 private final ObjectName objectName; 31 private final MBeanServerLocator locator; 32 33 public MBeanLocator(MBeanServerLocator sl, ObjectName obj) 34 { 35 this.identity = sl.getIdentity(); 36 this.locator = sl; 37 this.objectName = obj; 38 } 39 40 public boolean equals(Object o) 41 { 42 if(this == o) 43 { 44 return true; 45 } 46 if(!(o instanceof MBeanLocator)) 47 { 48 return false; 49 } 50 51 final MBeanLocator mBeanLocator = (MBeanLocator) o; 52 53 if(identity != null ? !identity.equals(mBeanLocator.identity) : mBeanLocator.identity != null) 54 { 55 return false; 56 } 57 if(locator != null ? !locator.equals(mBeanLocator.locator) : mBeanLocator.locator != null) 58 { 59 return false; 60 } 61 if(objectName != null ? !objectName.equals(mBeanLocator.objectName) : mBeanLocator.objectName != null) 62 { 63 return false; 64 } 65 66 return true; 67 } 68 69 public int hashCode() 70 { 71 int result; 72 result = (identity != null ? identity.hashCode() : 0); 73 result = 29 * result + (objectName != null ? objectName.hashCode() : 0); 74 result = 29 * result + (locator != null ? locator.hashCode() : 0); 75 return result; 76 } 77 78 83 public MBeanServerLocator getServerLocator() 84 { 85 return this.locator; 86 } 87 88 93 public final Identity getIdentity() 94 { 95 return this.identity; 96 } 97 98 103 public final ObjectName getObjectName() 104 { 105 return objectName; 106 } 107 108 113 public String toString() 114 { 115 return "MBeanLocator [server:" + locator + ",mbean:" + objectName + "]"; 116 } 117 118 124 public boolean isSameJVM(MBeanLocator locator) 125 { 126 return locator != null && locator.locator.equals(this.locator); 127 } 128 129 130 136 public Object narrow(Class interfaceCl) 137 { 138 Class cl[] = ClassUtil.getInterfacesFor(interfaceCl); 139 return narrow(cl); 140 } 141 142 148 public MBeanServer getMBeanServer() 149 throws ConnectionFailedException 150 { 151 return locator.getMBeanServer(); 152 } 153 154 160 public Object narrow(Class interfaces[]) 161 { 162 return MoveableMBean.create(this, interfaces); 163 } 164 } 165 | Popular Tags |