use of javax.management.ObjectInstance in project spring-framework by spring-projects.
the class MBeanExporterTests method testRegisterReplaceExisting.
@Test
public void testRegisterReplaceExisting() throws Exception {
ObjectName objectName = ObjectNameManager.getInstance(OBJECT_NAME);
Person preRegistered = new Person();
preRegistered.setName("Rob Harrop");
server.registerMBean(preRegistered, objectName);
Person springRegistered = new Person();
springRegistered.setName("Sally Greenwood");
Map<String, Object> beans = new HashMap<>();
beans.put(objectName.toString(), springRegistered);
MBeanExporter exporter = new MBeanExporter();
exporter.setServer(server);
exporter.setBeans(beans);
exporter.setRegistrationPolicy(RegistrationPolicy.REPLACE_EXISTING);
start(exporter);
ObjectInstance instance = server.getObjectInstance(objectName);
assertNotNull(instance);
// should still be the new bean with name Sally Greenwood
assertEquals("Sally Greenwood", server.getAttribute(objectName, "Name"));
}
use of javax.management.ObjectInstance in project spring-framework by spring-projects.
the class MBeanExporterTests method testAutodetectWithExclude.
@Test
public void testAutodetectWithExclude() throws Exception {
ConfigurableApplicationContext ctx = load("autodetectMBeans.xml");
try {
ctx.getBean("exporter");
MBeanServer server = ctx.getBean("server", MBeanServer.class);
ObjectInstance instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=true"));
assertNotNull(instance);
thrown.expect(InstanceNotFoundException.class);
server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=false"));
} finally {
ctx.close();
}
}
use of javax.management.ObjectInstance in project spring-framework by spring-projects.
the class AbstractJmxAssemblerTests method testMBeanRegistration.
@Test
public void testMBeanRegistration() throws Exception {
// beans are registered at this point - just grab them from the server
ObjectInstance instance = getObjectInstance();
assertNotNull("Bean should not be null", instance);
}
use of javax.management.ObjectInstance in project opennms by OpenNMS.
the class Invoker method invokeMethods.
/**
* <p>invokeMethods</p>
*
* @return a {@link java.util.List} object.
*/
public List<InvokerResult> invokeMethods() {
List<InvokerService> invokerServicesOrdered;
if (isReverse()) {
invokerServicesOrdered = new ArrayList<InvokerService>(getServices());
Collections.reverse(invokerServicesOrdered);
} else {
// We can use the original list
invokerServicesOrdered = getServices();
}
List<InvokerResult> resultInfo = new ArrayList<InvokerResult>(invokerServicesOrdered.size());
for (int pass = 0, end = getLastPass(); pass <= end; pass++) {
LOG.debug("starting pass {}", pass);
for (InvokerService invokerService : invokerServicesOrdered) {
Service service = invokerService.getService();
String name = invokerService.getService().getName();
ObjectInstance mbean = invokerService.getMbean();
if (invokerService.isBadService()) {
resultInfo.add(new InvokerResult(service, mbean, null, invokerService.getBadThrowable()));
if (isFailFast()) {
return resultInfo;
}
}
for (final Invoke invoke : invokerService.getService().getInvokes()) {
if (invoke.getPass() != pass || !getAtType().equals(invoke.getAt())) {
continue;
}
LOG.debug("pass {} on service {} will invoke method \"{}\"", pass, name, invoke.getMethod());
try {
Object result = invoke(invoke, mbean);
resultInfo.add(new InvokerResult(service, mbean, result, null));
} catch (Throwable t) {
resultInfo.add(new InvokerResult(service, mbean, null, t));
if (isFailFast()) {
return resultInfo;
}
}
}
}
LOG.debug("completed pass {}", pass);
}
return resultInfo;
}
use of javax.management.ObjectInstance in project wildfly by wildfly.
the class LogStoreProbeHandler method addTransactions.
private void addTransactions(final Resource parent, Set<ObjectInstance> transactions, MBeanServer mbs) throws IntrospectionException, InstanceNotFoundException, IOException, ReflectionException, MalformedObjectNameException {
for (ObjectInstance oi : transactions) {
String transactionId = oi.getObjectName().getCanonicalName();
if (!transactionId.contains("puid") && transactionId.contains("itype")) {
final Resource transaction = new LogStoreResource.LogStoreRuntimeResource(oi.getObjectName());
final ModelNode model = transaction.getModel();
Map<String, String> tAttributes = getMBeanValues(mbs, oi.getObjectName(), LogStoreConstants.TXN_JMX_NAMES);
String txnId = tAttributes.get("Id");
addAttributes(model, LogStoreConstants.MODEL_TO_JMX_TXN_NAMES, tAttributes);
// model.get(LogStoreConstants.JMX_ON_ATTRIBUTE).set(transactionId);
String participantQuery = transactionId + ",puid=*";
Set<ObjectInstance> participants = mbs.queryMBeans(new ObjectName(participantQuery), null);
addParticipants(transaction, participants, mbs);
final PathElement element = PathElement.pathElement(LogStoreConstants.TRANSACTIONS, txnId);
parent.registerChild(element, transaction);
}
}
}
Aggregations