use of javax.management.Attribute in project tomcat by apache.
the class JMXAccessorSetTask method jmxSet.
/**
* Set property value.
*
* @param jmxServerConnection Connection to the JMX server
* @param name The MBean name
* @return null (no error message to report other than exception)
* @throws Exception An error occurred
*/
protected String jmxSet(MBeanServerConnection jmxServerConnection, String name) throws Exception {
Object realValue;
if (type != null) {
realValue = convertStringToType(value, type);
} else {
if (isConvert()) {
String mType = getMBeanAttributeType(jmxServerConnection, name, attribute);
realValue = convertStringToType(value, mType);
} else
realValue = value;
}
jmxServerConnection.setAttribute(new ObjectName(name), new Attribute(attribute, realValue));
return null;
}
use of javax.management.Attribute in project jvm-tools by aragozin.
the class MBeanHelper method set.
public void set(ObjectName bean, String attr, String value) throws Exception {
MBeanInfo mbinfo = mserver.getMBeanInfo(bean);
MBeanAttributeInfo ai = attrInfo(mbinfo, attr);
if (ai == null) {
throw new IllegalArgumentException("No such attribute '" + attr + "'");
}
if (!ai.isWritable()) {
throw new IllegalArgumentException("Attribute '" + attr + "' is not writeable");
}
String type = ai.getType();
Object ov = convert(value, type);
mserver.setAttribute(bean, new Attribute(attr, ov));
}
use of javax.management.Attribute in project jetty.project by eclipse.
the class ObjectMBeanUtilTest method getAttributes.
private AttributeList getAttributes(String name, String value) {
Attribute attribute = new Attribute(name, value);
AttributeList attributes = new AttributeList();
attributes.add(attribute);
return attributes;
}
use of javax.management.Attribute in project jetty.project by eclipse.
the class ObjectMBeanUtilTest method setUpGetAttribute.
private void setUpGetAttribute(String property, String value) throws Exception {
Attribute attribute = new Attribute(property, value);
objectMBean.setAttribute(attribute);
}
use of javax.management.Attribute in project jetty.project by eclipse.
the class DoSFilterJMXTest method testDoSFilterJMX.
@Test
public void testDoSFilterJMX() throws Exception {
Server server = new Server();
Connector connector = new ServerConnector(server);
server.addConnector(connector);
ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
DoSFilter filter = new DoSFilter();
FilterHolder holder = new FilterHolder(filter);
String name = "dos";
holder.setName(name);
holder.setInitParameter(DoSFilter.MANAGED_ATTR_INIT_PARAM, "true");
context.addFilter(holder, "/*", EnumSet.of(DispatcherType.REQUEST));
context.setInitParameter(ServletContextHandler.MANAGED_ATTRIBUTES, name);
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
MBeanContainer mbeanContainer = new MBeanContainer(mbeanServer);
server.addBean(mbeanContainer);
server.start();
String domain = DoSFilter.class.getPackage().getName();
Set<ObjectName> mbeanNames = mbeanServer.queryNames(ObjectName.getInstance(domain + ":*"), null);
Assert.assertEquals(1, mbeanNames.size());
ObjectName objectName = mbeanNames.iterator().next();
boolean value = (Boolean) mbeanServer.getAttribute(objectName, "enabled");
mbeanServer.setAttribute(objectName, new Attribute("enabled", !value));
Assert.assertEquals(!value, filter.isEnabled());
String whitelist = (String) mbeanServer.getAttribute(objectName, "whitelist");
String address = "127.0.0.1";
Assert.assertFalse(whitelist.contains(address));
boolean result = (Boolean) mbeanServer.invoke(objectName, "addWhitelistAddress", new Object[] { address }, new String[] { String.class.getName() });
Assert.assertTrue(result);
whitelist = (String) mbeanServer.getAttribute(objectName, "whitelist");
Assert.assertTrue(whitelist.contains(address));
result = (Boolean) mbeanServer.invoke(objectName, "removeWhitelistAddress", new Object[] { address }, new String[] { String.class.getName() });
Assert.assertTrue(result);
whitelist = (String) mbeanServer.getAttribute(objectName, "whitelist");
Assert.assertFalse(whitelist.contains(address));
server.stop();
}
Aggregations