1 17 18 package org.apache.catalina.ant.jmx; 19 20 import java.io.IOException ; 21 import java.net.MalformedURLException ; 22 23 import javax.management.MBeanServerConnection ; 24 import javax.management.ObjectName ; 25 26 import org.apache.tools.ant.BuildException; 27 import org.apache.tools.ant.ProjectComponent; 28 import org.apache.tools.ant.taskdefs.condition.Condition; 29 30 72 public class JMXAccessorEqualsCondition extends ProjectComponent implements Condition { 73 74 76 private String url = null; 77 private String host = "localhost"; 78 private String port = "8050"; 79 private String password = null; 80 private String username = null; 81 private String name = null; 82 private String attribute; 83 private String value; 84 private String ref = "jmx.server" ; 85 87 90 private static final String info = "org.apache.catalina.ant.JMXAccessorEqualsCondition/1.1"; 91 92 97 public String getInfo() { 98 99 return (info); 100 101 } 102 104 107 public String getAttribute() { 108 return attribute; 109 } 110 113 public void setAttribute(String attribute) { 114 this.attribute = attribute; 115 } 116 119 public String getHost() { 120 return host; 121 } 122 125 public void setHost(String host) { 126 this.host = host; 127 } 128 131 public String getName() { 132 return name; 133 } 134 137 public void setName(String objectName) { 138 this.name = objectName; 139 } 140 143 public String getPassword() { 144 return password; 145 } 146 149 public void setPassword(String password) { 150 this.password = password; 151 } 152 155 public String getPort() { 156 return port; 157 } 158 161 public void setPort(String port) { 162 this.port = port; 163 } 164 167 public String getUrl() { 168 return url; 169 } 170 173 public void setUrl(String url) { 174 this.url = url; 175 } 176 179 public String getUsername() { 180 return username; 181 } 182 185 public void setUsername(String username) { 186 this.username = username; 187 } 188 191 public String getValue() { 192 return value; 193 } 194 public void setValue(String value) { 196 this.value = value; 197 } 198 199 202 public String getRef() { 203 return ref; 204 } 205 208 public void setRef(String refId) { 209 this.ref = refId; 210 } 211 212 protected MBeanServerConnection getJMXConnection() 213 throws MalformedURLException , IOException { 214 return JMXAccessorTask.accessJMXConnection( 215 getProject(), 216 getUrl(), getHost(), 217 getPort(), getUsername(), getPassword(), ref); 218 } 219 220 223 protected String accessJMXValue() { 224 try { 225 Object result = getJMXConnection().getAttribute( 226 new ObjectName (name), attribute); 227 if(result != null) 228 return result.toString(); 229 } catch (Exception e) { 230 } 232 return null; 233 } 234 235 public boolean eval() { 237 if (value == null) { 238 throw new BuildException("value attribute is not set"); 239 } 240 if ((name == null || attribute == null)) { 241 throw new BuildException( 242 "Must specify a 'attribute', name for equals condition"); 243 } 244 String jmxValue = accessJMXValue(); 246 if(jmxValue != null) 247 return jmxValue.equals(value); 248 return false; 249 } 250 } 251 252 | Popular Tags |