use of org.apache.sis.util.Configuration 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);
}
}
Aggregations