1 8 9 package mx4j.tools.remote; 10 11 import java.io.IOException ; 12 import java.util.Set ; 13 import javax.management.AttributeList ; 14 import javax.management.AttributeNotFoundException ; 15 import javax.management.InstanceAlreadyExistsException ; 16 import javax.management.InstanceNotFoundException ; 17 import javax.management.IntrospectionException ; 18 import javax.management.InvalidAttributeValueException ; 19 import javax.management.ListenerNotFoundException ; 20 import javax.management.MBeanException ; 21 import javax.management.MBeanInfo ; 22 import javax.management.MBeanRegistrationException ; 23 import javax.management.NotCompliantMBeanException ; 24 import javax.management.ObjectInstance ; 25 import javax.management.ObjectName ; 26 import javax.management.ReflectionException ; 27 import javax.security.auth.Subject ; 28 29 38 public abstract class JMXConnectionHandler extends AbstractConnection implements JMXConnection 39 { 40 private final JMXConnection connection; 41 private volatile boolean closed; 42 43 public JMXConnectionHandler(JMXConnection connection, ConnectionManager manager, String connectionId) 44 { 45 super(connectionId, manager); 46 this.connection = connection; 47 } 48 49 53 public void close() throws IOException 54 { 55 if (isClosed()) return; 56 closed = true; 57 getConnection().close(); 58 super.close(); 59 } 60 61 protected boolean isClosed() 62 { 63 return closed; 64 } 65 66 protected JMXConnection getConnection() 67 { 68 return connection; 69 } 70 71 public ObjectInstance createMBean(String className, ObjectName name, Object params, String [] signature, Subject delegate) throws ReflectionException , InstanceAlreadyExistsException , MBeanRegistrationException , MBeanException , NotCompliantMBeanException , IOException 72 { 73 if (isClosed()) throw new IOException ("Connection has been closed"); 74 return getConnection().createMBean(className, name, params, signature, delegate); 75 } 76 77 public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName, Object params, String [] signature, Subject delegate) throws ReflectionException , InstanceAlreadyExistsException , MBeanRegistrationException , MBeanException , NotCompliantMBeanException , InstanceNotFoundException , IOException 78 { 79 if (isClosed()) throw new IOException ("Connection has been closed"); 80 return getConnection().createMBean(className, name, loaderName, params, signature, delegate); 81 } 82 83 public void unregisterMBean(ObjectName name, Subject delegate) throws InstanceNotFoundException , MBeanRegistrationException , IOException 84 { 85 if (isClosed()) throw new IOException ("Connection has been closed"); 86 getConnection().unregisterMBean(name, delegate); 87 } 88 89 public ObjectInstance getObjectInstance(ObjectName name, Subject delegate) throws InstanceNotFoundException , IOException 90 { 91 if (isClosed()) throw new IOException ("Connection has been closed"); 92 return getConnection().getObjectInstance(name, delegate); 93 } 94 95 public Set queryMBeans(ObjectName name, Object query, Subject delegate) throws IOException 96 { 97 if (isClosed()) throw new IOException ("Connection has been closed"); 98 return getConnection().queryMBeans(name, query, delegate); 99 } 100 101 public Set queryNames(ObjectName name, Object query, Subject delegate) throws IOException 102 { 103 if (isClosed()) throw new IOException ("Connection has been closed"); 104 return getConnection().queryNames(name, query, delegate); 105 } 106 107 public boolean isRegistered(ObjectName name, Subject delegate) throws IOException 108 { 109 if (isClosed()) throw new IOException ("Connection has been closed"); 110 return getConnection().isRegistered(name, delegate); 111 } 112 113 public Integer getMBeanCount(Subject delegate) throws IOException 114 { 115 if (isClosed()) throw new IOException ("Connection has been closed"); 116 return getConnection().getMBeanCount(delegate); 117 } 118 119 public Object getAttribute(ObjectName name, String attribute, Subject delegate) throws MBeanException , AttributeNotFoundException , InstanceNotFoundException , ReflectionException , IOException 120 { 121 if (isClosed()) throw new IOException ("Connection has been closed"); 122 return getConnection().getAttribute(name, attribute, delegate); 123 } 124 125 public AttributeList getAttributes(ObjectName name, String [] attributes, Subject delegate) throws InstanceNotFoundException , ReflectionException , IOException 126 { 127 if (isClosed()) throw new IOException ("Connection has been closed"); 128 return getConnection().getAttributes(name, attributes, delegate); 129 } 130 131 public void setAttribute(ObjectName name, Object attribute, Subject delegate) throws InstanceNotFoundException , AttributeNotFoundException , InvalidAttributeValueException , MBeanException , ReflectionException , IOException 132 { 133 if (isClosed()) throw new IOException ("Connection has been closed"); 134 getConnection().setAttribute(name, attribute, delegate); 135 } 136 137 public AttributeList setAttributes(ObjectName name, Object attributes, Subject delegate) throws InstanceNotFoundException , ReflectionException , IOException 138 { 139 if (isClosed()) throw new IOException ("Connection has been closed"); 140 return getConnection().setAttributes(name, attributes, delegate); 141 } 142 143 public Object invoke(ObjectName name, String operationName, Object params, String [] signature, Subject delegate) throws InstanceNotFoundException , MBeanException , ReflectionException , IOException 144 { 145 if (isClosed()) throw new IOException ("Connection has been closed"); 146 return getConnection().invoke(name, operationName, params, signature, delegate); 147 } 148 149 public String getDefaultDomain(Subject delegate) throws IOException 150 { 151 if (isClosed()) throw new IOException ("Connection has been closed"); 152 return getConnection().getDefaultDomain(delegate); 153 } 154 155 public String [] getDomains(Subject delegate) throws IOException 156 { 157 if (isClosed()) throw new IOException ("Connection has been closed"); 158 return getConnection().getDomains(delegate); 159 } 160 161 public MBeanInfo getMBeanInfo(ObjectName name, Subject delegate) throws InstanceNotFoundException , IntrospectionException , ReflectionException , IOException 162 { 163 if (isClosed()) throw new IOException ("Connection has been closed"); 164 return getConnection().getMBeanInfo(name, delegate); 165 } 166 167 public boolean isInstanceOf(ObjectName name, String className, Subject delegate) throws InstanceNotFoundException , IOException 168 { 169 if (isClosed()) throw new IOException ("Connection has been closed"); 170 return getConnection().isInstanceOf(name, className, delegate); 171 } 172 173 public void addNotificationListener(ObjectName name, ObjectName listener, Object filter, Object handback, Subject delegate) throws InstanceNotFoundException , IOException 174 { 175 if (isClosed()) throw new IOException ("Connection has been closed"); 176 getConnection().addNotificationListener(name, listener, filter, handback, delegate); 177 } 178 179 public void removeNotificationListener(ObjectName name, ObjectName listener, Subject delegate) throws InstanceNotFoundException , ListenerNotFoundException , IOException 180 { 181 if (isClosed()) throw new IOException ("Connection has been closed"); 182 getConnection().removeNotificationListener(name, listener, delegate); 183 } 184 185 public void removeNotificationListener(ObjectName name, ObjectName listener, Object filter, Object handback, Subject delegate) throws InstanceNotFoundException , ListenerNotFoundException , IOException 186 { 187 if (isClosed()) throw new IOException ("Connection has been closed"); 188 getConnection().removeNotificationListener(name, listener, filter, handback, delegate); 189 } 190 } 191 | Popular Tags |