Register the given mbean with the server

@param server The server to register with
@param mbean The mbean to register
@param name The name to register under
171382
public static void registerMbean(MBeanServer server, ModelMBean mbean, ObjectName name) {
        try {
            synchronized(LOCK) {
                if(server.isRegistered(name))
                    JmxUtils.unregisterMbean(server, name);
                server.registerMBean(mbean, name);
            }
        } catch(Exception e) {
            logger.error("Error registering mbean:", e);
        }
    }
274405
public void register(BundleContext bndCtx) {
        final String methodName = "register()";
        final boolean trace = TraceComponent.isAnyTracingEnabled();
        if (trace && tc.isEntryEnabled())
            Tr.entry(tc, methodName, this);
        Hashtable<String, String> props = new Hashtable<String, String>();
        props.put("jmx.objectname", this.obn.toString());

        if (IS_DEBUGGING)
            // Extra Check: Does this MBean exist already?
            MBeanHelper.isMbeanExist(objectName.toString() + "*", className, methodName);

        // Register the MBean
        if (trace && tc.isDebugEnabled())
            Tr.debug(tc, "activateMBean started for " + this.obn.toString());
        this.reg = bndCtx.registerService(JCAConnectionFactoryMBeanImpl.class.getName(), this, props);
        if (trace && tc.isEntryEnabled())
            Tr.exit(tc, methodName, this);
    }
1337505
private void initMBean()  {
        try {
            registerMBean(this,getObjectName());
        } catch (InstanceAlreadyExistsException exp) {
            // This is no problem, since this MBeanServerHandlerMBean holds only global information
            // with no special state (so all instances of this MBean behave similar)
            // This exception can happen, when multiple servlets get registered within the same JVM
        } catch (MalformedObjectNameException e) {
            // Cannot happen, otherwise this is a bug. We should be always provide our own name in correct
            // form.
            throw new IllegalStateException("Internal Error: Own ObjectName " + getObjectName() + " is malformed",e);
        } catch (NotCompliantMBeanException e) {
            // Same here
            throw new IllegalStateException("Internal Error: " + this.getClass().getName() + " is not a compliant MBean",e);
        }
    }
44527
private MBeanServer getServerForName(String name) {
        try {
            MBeanServer mbeanServer = null;
            final ObjectName objectNameQuery = new ObjectName(name + ":type=Service,*");

            for (final MBeanServer server : MBeanServerFactory.findMBeanServer(null)) {
                if (server.queryNames(objectNameQuery, null).size() > 0) {
                    mbeanServer = server;
                    // we found it, bail out
                    break;
                }
            }

            return mbeanServer;
        } catch (Exception e) {
        }

        return null;
    }
952935
public <A> A register(final String name, final Class<? extends A> clazz, final A rs) {
        return register(true, name, clazz, rs);
    }
1051122
private void registerJMXStuff() {
    LOG.info("registering InApplicationMonitorDynamicMBean on JMX server");

    try {
      jmxBeanRegistrationHelper.registerMBeanOnJMX(this, "InApplicationMonitor", null);
    } catch (Exception e) {
      LOG.error("could not register MBean server : ", e);
    }
  }
856393
public void registerSingleton(String name, Class<?> clazz, MutablePropertyValues pvs) throws BeansException {
        GenericBeanDefinition bd = new GenericBeanDefinition();
        bd.setBeanClass(clazz);
        bd.setPropertyValues(pvs);
        getDefaultListableBeanFactory().registerBeanDefinition(name, bd);
    }
1222434
private MBeanServer lookupJolokiaMBeanServer() {
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        try {
            return server.isRegistered(JOLOKIA_MBEAN_SERVER_ONAME) ?
                    (MBeanServer) server.getAttribute(JOLOKIA_MBEAN_SERVER_ONAME, "JolokiaMBeanServer") :
                    null;
        } catch (JMException e) {
            throw new IllegalStateException("Internal: Cannot get Jolokia MBeanServer via JMX lookup: " + e, e);
        }
    }
1268044
public static final void serverName(String name)
    {
        if (tc.isEntryEnabled())
            Tr.entry(tc, "serverName", name);

        _serverName = name;

        if (tc.isEntryEnabled())
            Tr.exit(tc, "serverName");
    }
508991
@Override
    public void startServer(String name, int port, String messageOfTheDay)
    {
        for (final ClientListener listener : listeners)
        {
            network.addListener(listener);
        }
        network.addListener(this);
        network.setMessageOfTheDay(messageOfTheDay);
        network.start(name, port);
    }
1048455
private void initialize(NameNode nn, Configuration conf) throws IOException {
    // Register MBean first since pedingReplication refers to myFSMetrics
    this.registerMBean(conf); // register the MBean for the FSNamesystemStutus
    // This needs to be initialized first, since it is referenced by other
    // operations in the initialization.
    
    // Validate the Namespace Directory policy before loading them
    // get the location map (mounts/shared dirs/etc
    Map<URI, NNStorageLocation> locationMap = 
        ValidateNamespaceDirPolicy.validate(conf);
    
    pendingReplications = new PendingReplicationBlocks(
        conf.getInt("dfs.replication.pending.timeout.sec",
          -1) * 1000L, myFSMetrics);
    this.systemStart = now();
    this.fsLock = new ReentrantReadWriteLock(); // non-fair
    configManager = new ConfigManager(this, conf);
    setConfigurationParameters(conf);

    // This can be null if two ports are running. Should not rely on the value.
    // The getter for this is deprecated
    this.nameNodeAddress = nn.getNameNodeAddress();
    
    // Creating root for name node
    this.dir = new FSDirectory(this, conf, 
        NNStorageConfiguration.getNamespaceDirs(conf), 
        NNStorageConfiguration.getNamespaceEditsDirs(conf),
        locationMap);
    StartupOption startOpt = NameNode.getStartupOption(conf);
    
    this.dir.loadFSImage(startOpt, conf);
    long timeTakenToLoadFSImage = now() - systemStart;
    LOG.info("Finished loading FSImage in " + timeTakenToLoadFSImage + " msecs");
    LOG.info("Total number of inodes : " + getFilesAndDirectoriesTotal());
    NameNode.getNameNodeMetrics().fsImageLoadTime.set(
      (int) timeTakenToLoadFSImage);
    
    // load directories that enabled permission checking
    loadEnabledPermissionCheckingDirs(conf);
    
    // fast RQ and BR prcessing
    // make sure we have at least one thread, by default 1
    this.parallelProcessingThreads = Math.max(1,
        getConf().getInt("dfs.safemode.processing.threads", 16));
    this.parallelRQblocksPerShard = getConf().getInt(
        "dfs.safemode.fast.rq.blocks", 1000000);
    this.parallelBRblocksPerShard = getConf().getInt(
        "dfs.safemode.fast.br.blocks", 10000);
    this.parallelBRenabled = getConf().getBoolean("dfs.safemode.fast.br.enabled", true);
    
    this.safeMode = SafeModeUtil.getInstance(conf, this);
    this.safeMode.checkMode();
    if ("true".equals(conf.get("dfs.namenode.initialize.counting"))) {
      LOG.info("Start counting items in the file tree");
      dir.rootDir.countItems();
      LOG.info("Finish counting items in the file tree");
      INodeDirectory.ItemCounts counts = dir.rootDir.getItemCounts();
      LOG.info("Counting result: " +
        counts.numDirectories + " directories, " +
        counts.numFiles + " files, and " +
        counts.numBlocks + " blocks in file tree. " +
        blocksMap.size() + " blocks in block map.");
    } else {
      LOG.info("Skip counting items in the file tree");
    }

    // initialize heartbeat & leasemanager threads
    this.hbthread = new Daemon(new HeartbeatMonitor(conf));
    this.lmmonitor = leaseManager.new Monitor();
    this.lmthread = new Daemon(lmmonitor);

    // start heartbeat & leasemanager threads
    hbthread.start();
    lmthread.start();

    // initialize replication threads
    this.underreplthread = new Daemon(new UnderReplicationMonitor());
    this.overreplthread = new Daemon(new OverReplicationMonitor());
    this.raidEncodingTaskThread = new Daemon(new RaidEncodingTaskMonitor());

    // start replication threds
    underreplthread.start();
    overreplthread.start();
    raidEncodingTaskThread.start();
    

    this.hostsReader =
      new HostsFileReader(
        conf.get(FSConstants.DFS_HOSTS, ""),
        conf.get("dfs.hosts.exclude", ""),
        !conf.getBoolean("dfs.hosts.ignoremissing", false));

    this.dnthread = new Daemon(new DecommissionManager(this).new Monitor(
      conf.getInt("dfs.namenode.decommission.interval", 30),
      conf.getInt("dfs.namenode.decommission.nodes.per.interval", 5)));
    dnthread.start();
    
    if (this.automaticEditsRollingThread != null) {
      LOG.info("Starting Automatic Edits Rolling Thread...");
      this.automaticEditsRollingThread.start();
    }

    this.dnsToSwitchMapping = ReflectionUtils.newInstance(
      conf.getClass("topology.node.switch.mapping.impl", ScriptBasedMapping.class,
        DNSToSwitchMapping.class), conf);

    /* If the dns to swith mapping supports cache, resolve network
    * locations of those hosts in the include list,
    * and store the mapping in the cache; so future calls to resolve
    * will be fast.
    */
    if (dnsToSwitchMapping instanceof CachedDNSToSwitchMapping) {
      dnsToSwitchMapping.resolve(new ArrayList<String>(hostsReader.getHostNames()));
    }

    this.replicator = BlockPlacementPolicy.getInstance(
        conf,
        this,
        this.clusterMap,
        this.hostsReader,
        this.dnsToSwitchMapping,
        this);
    this.registerMXBean();
    // Whether or not to sync each addBlock() operation to the edit log.
    this.syncAddBlock = conf.getBoolean("dfs.sync.on.every.addblock", false);
    this.isInitialized = true;
  }
345598
public void register(ZKMBeanInfo bean, ZKMBeanInfo parent)
        throws JMException
    {
        assert bean != null;
        String path = null;
        if (parent != null) {
            path = mapBean2Path.get(parent);
            assert path != null;
        }
        path = makeFullPath(path, parent);
        mapBean2Path.put(bean, path);
        mapName2Bean.put(bean.getName(), bean);
        if(bean.isHidden())
            return;
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName oname = makeObjectName(path, bean);
        try {
            mbs.registerMBean(bean, oname);
        } catch (JMException e) {
            LOG.warn("Failed to register MBean " + bean.getName());
            throw e;
        }
    }
1186863
private ObjectName registerMXBean(MBeanServer pServer, Object pObject, Class pManagementInterface, String pName) throws MalformedObjectNameException, NotCompliantMBeanException, InstanceAlreadyExistsException, MBeanRegistrationException {
        ObjectName objectName = new ObjectName(pName);
        final StandardMBean mxBean = new StandardMBean(pObject, pManagementInterface, true /* MXBean */);
        pServer.registerMBean(mxBean, objectName);
        System.out.println("Registered MXBean " + objectName);
        return objectName;
    }
284049
public void registerSingleton(String name, Class<?> clazz) throws BeansException {
        GenericBeanDefinition bd = new GenericBeanDefinition();
        bd.setBeanClass(clazz);
        getDefaultListableBeanFactory().registerBeanDefinition(name, bd);
    }
586042
public MBeanInfo getMBeanInfo(final ObjectName name) {
    try {
      return getMbeanServer().getMBeanInfo(name);
    } catch (final Exception e) {
      logger.error("Load MBean Information Failure", e);
      return null;
    }
  }
321033
public static void unregister(String name) {
    try {
      ManagementFactory.getPlatformMBeanServer().unregisterMBean(new ObjectName(name));
    } catch (Exception e) {
      LoggerFactory.getLogger(Jmx.class).warn("Can not unregister MBean [{}]", name, e);
    }
  }
734895
public void registerMBeans(Collection<ResourceDMBean> resourceDMBeans) throws CacheException {
      try {
         for (ResourceDMBean resource : resourceDMBeans)
            JmxUtil.registerMBean(resource, getObjectName(resource), mBeanServer);
      }
      catch (Exception e) {
         throw new CacheException("Failure while registering mbeans", e);
      }
   }