use of javax.management.JMException in project opennms by OpenNMS.
the class DefaultJmxCollector method collect.
private void collect(MBeanServerConnection concreteConnection, JmxCollection jmxCollection, JmxSampleProcessor sampleProcessor) {
if (jmxCollection == null || jmxCollection.getMbeanCount() < 1) {
logger.info("No MBeans to collect.");
return;
}
try {
for (Mbean eachMbean : jmxCollection.getMbeans()) {
logger.debug("Collecting MBean (objectname={}, wildcard={})", eachMbean.getObjectname(), isWildcard(eachMbean.getObjectname()));
final Collection<ObjectName> objectNames = getObjectNames(concreteConnection, eachMbean.getObjectname());
for (ObjectName eachObjectName : objectNames) {
logger.debug("Collecting ObjectName {}", eachObjectName);
boolean collect = canBeCollected(concreteConnection, eachObjectName, eachMbean.getKeyfield(), eachMbean.getExclude());
if (collect) {
List<String> attributeNames = extractAttributeNames(eachMbean);
List<Attribute> attributes = getAttributes(concreteConnection, eachObjectName, attributeNames);
for (Attribute eachAttribute : attributes) {
if (eachAttribute.getValue() instanceof CompositeData) {
CompositeData compositeData = (CompositeData) eachAttribute.getValue();
for (CompMember eachCompositeMember : getCompositeMembers(eachMbean, eachAttribute.getName())) {
JmxCompositeSample sample = new JmxCompositeSample(eachMbean, eachAttribute, compositeData, eachCompositeMember);
logger.debug("Collected sample {}", sample);
sampleProcessor.process(sample, eachObjectName);
}
} else {
JmxAttributeSample sample = new JmxAttributeSample(eachMbean, eachAttribute);
logger.debug("Collected sample {}", sample);
sampleProcessor.process(sample, eachObjectName);
}
}
} else {
logger.debug("Skip ObjectName {}", eachObjectName);
}
}
}
} catch (JMException e) {
logger.error("Could not collect data", e);
} catch (IOException e) {
logger.error("Could not communicate with MBeanServer", e);
}
}
use of javax.management.JMException in project sis by apache.
the class Supervisor method register.
/**
* Registers the {@code Supervisor} instance, if not already done.
* If the supervisor has already been registered but has not yet been
* {@linkplain #unregister() unregistered}, then this method does nothing.
*
* <p>If the registration fails, then this method logs a message at the warning level
* and the MBean will not be registered. This method does not propagate the exception
* because the MBean is not a mandatory part of SIS library.</p>
*/
@Configuration
public static synchronized void register() {
if (name == null) {
// In case of failure.
name = ObjectName.WILDCARD;
final LogRecord record;
try {
final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
final ObjectName n = new ObjectName(NAME);
server.registerMBean(new Supervisor(), n);
// Store only on success.
name = n;
return;
} catch (InstanceAlreadyExistsException e) {
record = Messages.getResources(null).getLogRecord(Level.CONFIG, Messages.Keys.AlreadyRegistered_2, "MBean", NAME);
} catch (JMException e) {
record = new LogRecord(Level.WARNING, e.toString());
record.setThrown(e);
} catch (SecurityException e) {
record = new LogRecord(Level.CONFIG, e.toString());
}
record.setLoggerName(Loggers.SYSTEM);
Logging.log(Supervisor.class, "register", record);
}
}
use of javax.management.JMException in project derby by apache.
the class JMXManagementService method startManagement.
public synchronized void startManagement() {
// Has this service been shut down?
if (registeredMbeans == null)
return;
checkJMXControl();
// Already active?
if (isManagementActive())
return;
findServer();
// If we can't find the server then we can't register.
if (mbeanServer == null)
return;
for (ObjectName mbeanName : registeredMbeans.keySet()) {
// to be re-registered with JMX
if (mbeanName.equals(myManagementBean) && mbeanServer.isRegistered(myManagementBean))
continue;
try {
jmxRegister(registeredMbeans.get(mbeanName), mbeanName);
} catch (JMException e) {
// TODO - what to do here?
}
}
}
use of javax.management.JMException in project netvirt by opendaylight.
the class BgpAlarmBroadcaster method init.
@PostConstruct
public void init() {
// Set up the Infra for Posting BGP Alarms as JMX notifications.
try {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
mbs.registerMBean(this, objectName());
} catch (JMException e) {
LOG.error("Adding a NotificationBroadcaster failed.", e);
}
LOG.info("{} start", getClass().getSimpleName());
}
use of javax.management.JMException in project narayana by jbosstm.
the class StoreManagerProxy method registerBean.
/**
* MBean registration helper method
* @param name MBean object name
* @param bean MBean implementation
* @param register whether to register or unregister the MBean
* @return true if the bean was successfully registered or unregistered
*/
public static boolean registerBean(ObjectName name, Object bean, boolean register) {
try {
MBeanServer mbs = JMXServer.getAgent().getServer();
boolean isRegistered = mbs.isRegistered(name);
System.out.println((register ? "" : "un") + "registering bean " + name);
if (register && isRegistered) {
System.out.println(name + " is already registered");
return true;
} else if (!register && !isRegistered) {
System.out.println(name + " is not registered");
return true;
} else if (register) {
mbs.registerMBean(bean, name);
} else {
mbs.unregisterMBean(name);
}
return true;
} catch (JMException e) {
System.out.println("MBean registration error: " + e.getMessage());
return false;
}
}
Aggregations