Search in sources :

Example 1 with Configuration

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);
    }
}
Also used : LogRecord(java.util.logging.LogRecord) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) JMException(javax.management.JMException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Configuration(org.apache.sis.util.Configuration)

Aggregations

LogRecord (java.util.logging.LogRecord)1 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 JMException (javax.management.JMException)1 MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1 Configuration (org.apache.sis.util.Configuration)1