use of javax.management.InstanceAlreadyExistsException in project atlasdb by palantir.
the class JMXUtils method registerMBeanCatchAndLogExceptions.
/**
* Simple method to register a bean with the server. The server used is the
* one returned by {@code ManagementFactory.getPlatformMBeanServer()}.
* <p>
* This bean will remain registered until manually unregistered. If you want
* life-cycle management, use
* {@link #registerMBeanWeakRefPlusCatchAndLogExceptions(Object, Class, String)}
*/
public static void registerMBeanCatchAndLogExceptions(final Object mbean, final String objectName) {
final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
try {
final ObjectName on = new ObjectName(objectName);
try {
// throws exception if bean doesn't exist
server.getMBeanInfo(on);
server.unregisterMBean(on);
} catch (final InstanceNotFoundException e) {
// if the bean wasn't already there.
}
server.registerMBean(mbean, on);
} catch (InstanceAlreadyExistsException e) {
// The bean was registered concurrently; log an error, but don't fail tests
log.error("Failed to register mbean for name {}", objectName, e);
} catch (Exception e) {
AssertUtils.assertAndLogWithException(log, false, "Failed to register mbean for name " + objectName, e);
}
}
use of javax.management.InstanceAlreadyExistsException in project wicket by apache.
the class Initializer method init.
@Override
public void init(final org.apache.wicket.Application application) {
try {
String name = application.getName();
String agentId = null;
try {
agentId = System.getProperty("wicket.mbean.server.agentid");
} catch (SecurityException e) {
// Ignore - we're not allowed to read this property.
log.warn("not allowed to read property wicket.mbean.server.agentid due to security settings; ignoring");
}
if (agentId != null) {
ArrayList<MBeanServer> mbeanServers = MBeanServerFactory.findMBeanServer(agentId);
if (!mbeanServers.isEmpty()) {
// get first
mbeanServer = mbeanServers.get(0);
} else {
log.error("unable to find mbean server with agent id " + agentId);
}
}
if (mbeanServer == null) {
String impl = null;
try {
impl = System.getProperty("wicket.mbean.server.class");
} catch (SecurityException e) {
// Ignore - we're not allowed to read this property.
log.warn("not allowed to read property wicket.mbean.server.class due to security settings; ignoring");
}
if (impl != null) {
ArrayList<MBeanServer> mbeanServers = MBeanServerFactory.findMBeanServer(null);
if (!mbeanServers.isEmpty()) {
for (MBeanServer mbs : mbeanServers) {
if (mbs.getClass().getName().equals(impl)) {
mbeanServer = mbs;
break;
}
}
}
if (mbeanServer == null) {
log.error("unable to find mbean server of type '{}'", impl);
}
}
}
if (mbeanServer == null) {
mbeanServer = ManagementFactory.getPlatformMBeanServer();
// never null
}
log.info("registering Wicket mbeans with server '{}'", mbeanServer);
// register top level application object, but first check whether
// multiple instances of the same application (name) are running and
// if so adjust the name
String domain = "org.apache.wicket.app." + name;
ObjectName appBeanName = new ObjectName(domain + ":type=Application");
String tempDomain = domain;
int i = 0;
while (mbeanServer.isRegistered(appBeanName)) {
tempDomain = name + "-" + i++;
appBeanName = new ObjectName(tempDomain + ":type=Application");
}
domain = tempDomain;
Application appBean = new Application(application);
register(application, appBean, appBeanName);
register(application, new ApplicationSettings(application), new ObjectName(domain + ":type=Application,name=ApplicationSettings"));
register(application, new DebugSettings(application), new ObjectName(domain + ":type=Application,name=DebugSettings"));
register(application, new MarkupSettings(application), new ObjectName(domain + ":type=Application,name=MarkupSettings"));
register(application, new ResourceSettings(application), new ObjectName(domain + ":type=Application,name=ResourceSettings"));
register(application, new PageSettings(application), new ObjectName(domain + ":type=Application,name=PageSettings"));
register(application, new RequestCycleSettings(application), new ObjectName(domain + ":type=Application,name=RequestCycleSettings"));
register(application, new SecuritySettings(application), new ObjectName(domain + ":type=Application,name=SecuritySettings"));
register(application, new SessionSettings(application), new ObjectName(domain + ":type=Application,name=SessionSettings"));
register(application, new StoreSettings(application), new ObjectName(domain + ":type=Application,name=StoreSettings"));
RequestLogger sessionsBean = new RequestLogger(application);
ObjectName sessionsBeanName = new ObjectName(domain + ":type=RequestLogger");
register(application, sessionsBean, sessionsBeanName);
} catch (MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) {
throw new WicketRuntimeException(e);
}
}
use of javax.management.InstanceAlreadyExistsException in project herddb by diennea.
the class JMXUtils method registerTableSpaceManagerStatsMXBean.
public static void registerTableSpaceManagerStatsMXBean(String tableSpaceName, TableSpaceManagerStatsMXBean bean) {
if (platformMBeanServer == null) {
throw new HerdDBInternalException("PlatformMBeanServer not available", mBeanServerLookupError);
}
String safeTableSpaceName = safeName(tableSpaceName);
try {
ObjectName name = new ObjectName("herddb.server:type=TableSpace,Name=" + safeTableSpaceName);
LOG.log(Level.FINE, "Publishing stats for table {0} at {1}", new Object[] { tableSpaceName, name });
if (platformMBeanServer.isRegistered(name)) {
try {
platformMBeanServer.unregisterMBean(name);
} catch (InstanceNotFoundException noProblem) {
}
}
platformMBeanServer.registerMBean(bean, name);
} catch (MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) {
throw new HerdDBInternalException("Could not register MXBean " + e);
}
}
use of javax.management.InstanceAlreadyExistsException in project wikidata-query-rdf by wikimedia.
the class MonitoredFilter method init.
/**
* Register a Filter as an MBean.
*
* On successful registration, the {@link ObjectName} used for registration
* is stored into an instance field so that the MBean can be released on
* {@link Filter#destroy()}.
*/
@Override
public void init(FilterConfig filterConfig) throws ServletException {
String filterName = filterConfig.getFilterName();
ObjectName name = null;
try {
name = new ObjectName(this.getClass().getName(), "filterName", filterName);
MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
platformMBeanServer.registerMBean(this, name);
log.info("ThrottlingFilter MBean registered as {}.", name);
} catch (MalformedObjectNameException e) {
log.error("filter name {} is invalid as an MBean property.", filterName, e);
} catch (InstanceAlreadyExistsException e) {
log.error("MBean for {}} has already been registered.", filterName, e);
} catch (NotCompliantMBeanException | MBeanRegistrationException e) {
log.error("Could not register MBean for Filter {}.", filterName, e);
}
objectName = name;
}
use of javax.management.InstanceAlreadyExistsException in project quasar by puniverse.
the class JMXActorsMonitor method registerMBean.
@SuppressWarnings({ "CallToPrintStackTrace", "CallToThreadDumpStack" })
private void registerMBean() {
try {
final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
final ObjectName mxbeanName = new ObjectName(mbeanName);
mbs.registerMBean(this, mxbeanName);
this.registered = true;
} catch (InstanceAlreadyExistsException ex) {
throw new RuntimeException(ex);
} catch (MBeanRegistrationException ex) {
ex.printStackTrace();
} catch (NotCompliantMBeanException ex) {
throw new AssertionError(ex);
} catch (MalformedObjectNameException ex) {
throw new AssertionError(ex);
}
MonitoringServices.getInstance().addPerfNotificationListener(this, mbeanName);
}
Aggregations