Java 类javax.management.JMException 实例源码

项目:alfresco-repository    文件:DynamicMBeanExporter.java   
@SuppressWarnings("unchecked")
public ObjectName registerMBean(Object managedResource, ObjectName objectName)
{
    Object mbean;
    if (isMBean(managedResource.getClass()))
    {
        mbean = managedResource;
    }
    else
    {
        mbean = createAndConfigureMBean(managedResource, managedResource.getClass().getName());
    }
    ObjectName actualObjectName = objectName;
    try
    {
        doRegister(mbean, actualObjectName);
    }
    catch (JMException e)
    {
        throw new RuntimeException(e);
    }
    return actualObjectName;
}
项目:fuck_zookeeper    文件:MBeanRegistry.java   
/**
 * Registers a new MBean with the platform MBean server. 
 * @param bean the bean being registered
 * @param parent if not null, the new bean will be registered as a child
 * node of this parent.
 */
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);
    if(bean.isHidden())
        return;
    ObjectName oname = makeObjectName(path, bean);
    try {
        mBeanServer.registerMBean(bean, oname);
        mapBean2Path.put(bean, path);
        mapName2Bean.put(bean.getName(), bean);
    } catch (JMException e) {
        LOG.warn("Failed to register MBean " + bean.getName());
        throw e;
    }
}
项目:fuck_zookeeper    文件:ZooKeeperServerMain.java   
protected void initializeAndRun(String[] args)
    throws ConfigException, IOException
{
    try {
        ManagedUtil.registerLog4jMBeans();
    } catch (JMException e) {
        LOG.warn("Unable to register log4j JMX control", e);
    }
    //再次解析配置文件(我也是醉了呀,又解析一遍!!!,写这段的人你出来我保证不打你)
    ServerConfig config = new ServerConfig();
    if (args.length == 1) {
        config.parse(args[0]);
    } else {
        config.parse(args);
    }

    runFromConfig(config);
}
项目:lams    文件:MBeanClientInterceptor.java   
/**
 * Routes a method invocation (not a property get/set) to the corresponding
 * operation on the managed resource.
 * @param method the method corresponding to operation on the managed resource.
 * @param args the invocation arguments
 * @return the value returned by the method invocation.
 */
private Object invokeOperation(Method method, Object[] args) throws JMException, IOException {
    MethodCacheKey key = new MethodCacheKey(method.getName(), method.getParameterTypes());
    MBeanOperationInfo info = this.allowedOperations.get(key);
    if (info == null) {
        throw new InvalidInvocationException("Operation '" + method.getName() +
                "' is not exposed on the management interface");
    }
    String[] signature = null;
    synchronized (this.signatureCache) {
        signature = this.signatureCache.get(method);
        if (signature == null) {
            signature = JmxUtils.getMethodSignature(method);
            this.signatureCache.put(method, signature);
        }
    }
    return this.serverToUse.invoke(this.objectName, method.getName(), args, signature);
}
项目:lams    文件:MBeanExporter.java   
@Override
public void registerManagedResource(Object managedResource, ObjectName objectName) throws MBeanExportException {
    Assert.notNull(managedResource, "Managed resource must not be null");
    Assert.notNull(objectName, "ObjectName must not be null");
    try {
        if (isMBean(managedResource.getClass())) {
            doRegister(managedResource, objectName);
        }
        else {
            ModelMBean mbean = createAndConfigureMBean(managedResource, managedResource.getClass().getName());
            doRegister(mbean, objectName);
            injectNotificationPublisherIfNecessary(managedResource, mbean, objectName);
        }
    }
    catch (JMException ex) {
        throw new UnableToRegisterMBeanException(
                "Unable to register MBean [" + managedResource + "] with object name [" + objectName + "]", ex);
    }
}
项目:lams    文件:MBeanExporter.java   
/**
 * Build an adapted MBean for the given bean instance, if possible.
 * <p>The default implementation builds a JMX 1.2 StandardMBean
 * for the target's MBean/MXBean interface in case of an AOP proxy,
 * delegating the interface's management operations to the proxy.
 * @param bean the original bean instance
 * @return the adapted MBean, or {@code null} if not possible
 */
@SuppressWarnings("unchecked")
protected DynamicMBean adaptMBeanIfPossible(Object bean) throws JMException {
    Class<?> targetClass = AopUtils.getTargetClass(bean);
    if (targetClass != bean.getClass()) {
        Class<?> ifc = JmxUtils.getMXBeanInterface(targetClass);
        if (ifc != null) {
            if (!ifc.isInstance(bean)) {
                throw new NotCompliantMBeanException("Managed bean [" + bean +
                        "] has a target class with an MXBean interface but does not expose it in the proxy");
            }
            return new StandardMBean(bean, ((Class<Object>) ifc), true);
        }
        else {
            ifc = JmxUtils.getMBeanInterface(targetClass);
            if (ifc != null) {
                if (!ifc.isInstance(bean)) {
                    throw new NotCompliantMBeanException("Managed bean [" + bean +
                            "] has a target class with an MBean interface but does not expose it in the proxy");
                }
                return new StandardMBean(bean, ((Class<Object>) ifc));
            }
        }
    }
    return null;
}
项目:Gather-Platform    文件:CommonSpider.java   
/**
     * 测试爬虫模板
     *
     * @param info
     * @return
     */
    public List<Webpage> testSpiderInfo(SpiderInfo info) throws JMException {
        final ResultItemsCollectorPipeline resultItemsCollectorPipeline = new ResultItemsCollectorPipeline();
        final String uuid = UUID.randomUUID().toString();
        Task task = taskManager.initTask(uuid, info.getDomain(), info.getCallbackURL(), "spiderInfoId=" + info.getId() + "&spiderUUID=" + uuid);
        task.addExtraInfo("spiderInfo", info);
        QueueScheduler queueScheduler = new QueueScheduler();
        MySpider spider = (MySpider) makeSpider(info, task)
                .addPipeline(resultItemsCollectorPipeline)
                .setScheduler(queueScheduler);
        spider.startUrls(info.getStartURL());
        //慎用爬虫监控,可能导致内存泄露
//        spiderMonitor.register(spider);
        spiderMap.put(uuid, spider);
        taskManager.getTaskById(uuid).setState(State.RUNNING);
        spider.run();
        List<Webpage> webpageList = Lists.newLinkedList();
        resultItemsCollectorPipeline.getCollected().forEach(resultItems -> webpageList.add(CommonWebpagePipeline.convertResultItems2Webpage(resultItems)));
        return webpageList;
    }
项目:https-github.com-apache-zookeeper    文件:MBeanRegistry.java   
/**
 * Registers a new MBean with the platform MBean server. 
 * @param bean the bean being registered
 * @param parent if not null, the new bean will be registered as a child
 * node of this parent.
 */
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);
    if(bean.isHidden())
        return;
    ObjectName oname = makeObjectName(path, bean);
    try {
        synchronized (LOCK) {
            mBeanServer.registerMBean(bean, oname);
            mapBean2Path.put(bean, path);
        }
    } catch (JMException e) {
        LOG.warn("Failed to register MBean " + bean.getName());
        throw e;
    }
}
项目:https-github.com-apache-zookeeper    文件:ZooKeeperServerMain.java   
protected void initializeAndRun(String[] args)
    throws ConfigException, IOException, AdminServerException
{
    try {
        ManagedUtil.registerLog4jMBeans();
    } catch (JMException e) {
        LOG.warn("Unable to register log4j JMX control", e);
    }

    ServerConfig config = new ServerConfig();
    if (args.length == 1) {
        config.parse(args[0]);
    } else {
        config.parse(args);
    }

    runFromConfig(config);
}
项目:monarch    文件:CacheManagementDUnitTest.java   
public static void startManager() {
  MemberMXBean bean = getManagementService().getMemberMXBean();
  // When the cache is created if jmx-manager is true then we create the manager.
  // So it may already exist when we get here.
  if (!bean.isManagerCreated()) {
    if (!bean.createManager()) {
      fail("Could not create Manager");
    } else if (!bean.isManagerCreated()) {
      fail("Should have been a manager after createManager returned true.");
    }
  }
  ManagerMXBean mngrBean = getManagementService().getManagerMXBean();
  try {
    mngrBean.start();
  } catch (JMException e) {
    fail("Could not start Manager " + e);
  }
  assertTrue(mngrBean.isRunning());
  assertTrue(getManagementService().isManager());
  assertTrue(bean.isManager());
}
项目:jdk8u-jdk    文件:ScanManager.java   
private void applyConfiguration(ScanManagerConfig bean)
    throws IOException, JMException {
    if (bean == null) return;
    if (!sequencer.tryAcquire()) {
        throw new IllegalStateException("Can't acquire lock");
    }
    try {
        unregisterScanners();
        final DirectoryScannerConfig[] scans = bean.getScanList();
        if (scans == null) return;
        for (DirectoryScannerConfig scan : scans) {
            addDirectoryScanner(scan);
        }
        log.setConfig(bean.getInitialResultLogConfig());
    } finally {
        sequencer.release();
    }
}
项目:ZooKeeper    文件:MBeanRegistry.java   
/**
 * Registers a new MBean with the platform MBean server. 
 * @param bean the bean being registered
 * @param parent if not null, the new bean will be registered as a child
 * node of this parent.
 */
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);
    if(bean.isHidden())
        return;
    ObjectName oname = makeObjectName(path, bean);
    try {
        mBeanServer.registerMBean(bean, oname);
        mapBean2Path.put(bean, path);
        mapName2Bean.put(bean.getName(), bean);
    } catch (JMException e) {
        LOG.warn("Failed to register MBean " + bean.getName());
        throw e;
    }
}
项目:ZooKeeper    文件:ZooKeeperServerMain.java   
protected void initializeAndRun(String[] args)
    throws ConfigException, IOException
{
    try {
        ManagedUtil.registerLog4jMBeans();
    } catch (JMException e) {
        LOG.warn("Unable to register log4j JMX control", e);
    }

    ServerConfig config = new ServerConfig();
    if (args.length == 1) {
        config.parse(args[0]);
    } else {
        config.parse(args);
    }

    runFromConfig(config);
}
项目:metrics-tomcat    文件:AnnotatedStandardMBean.java   
@SuppressWarnings({
        "unchecked", "rawtypes"
})
public static String registerMBean(final Object object) throws JMException {
    final ObjectName objectName = generateMBeanName(object.getClass());
    final MBeanServer context = ManagementFactory.getPlatformMBeanServer();
    final String mbeanName = object.getClass().getName() + "MBean";
    for (final Class c : object.getClass().getInterfaces()) {
        if (mbeanName.equals(c.getName())) {
            context.registerMBean(new AnnotatedStandardMBean(object, c), objectName);
            return objectName.getCanonicalName();
        }
    }
    context.registerMBean(object, objectName);
    return objectName.getCanonicalName();
}
项目:cassandra-reaper    文件:SegmentRunner.java   
private void handlePotentialStuckRepairs(LazyInitializer<Set<String>> busyHosts, String hostName)
    throws ConcurrentException {

  if (!busyHosts.get().contains(hostName) && context.storage instanceof IDistributedStorage) {
    try (JmxProxy hostProxy
        = context.jmxConnectionFactory.connect(hostName, context.config.getJmxConnectionTimeoutInSeconds())) {
      // We double check that repair is still running there before actually canceling repairs
      if (hostProxy.isRepairRunning()) {
        LOG.warn(
            "A host ({}) reported that it is involved in a repair, but there is no record "
                + "of any ongoing repair involving the host. Sending command to abort all repairs "
                + "on the host.",
            hostName);
        hostProxy.cancelAllRepairs();
        hostProxy.close();
      }
    } catch (ReaperException | RuntimeException | InterruptedException | JMException e) {
      LOG.debug("failed to cancel repairs on host {}", hostName, e);
    }
  }
}
项目:zookeeper    文件:MBeanRegistry.java   
/**
 * Registers a new MBean with the platform MBean server. 
 * @param bean the bean being registered
 * @param parent if not null, the new bean will be registered as a child
 * node of this parent.
 */
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);
    if(bean.isHidden())
        return;
    ObjectName oname = makeObjectName(path, bean);
    try {
        mBeanServer.registerMBean(bean, oname);
        mapBean2Path.put(bean, path);
        mapName2Bean.put(bean.getName(), bean);
    } catch (JMException e) {
        LOG.warn("Failed to register MBean " + bean.getName());
        throw e;
    }
}
项目:spider    文件:CommonsSpiderService.java   
/**
 * 根据爬虫模板ID批量启动任务
 *
 * @param spiderInfoIdList 爬虫模板ID列表
 * @return 任务id列表
 */
public ResultListBundle<String> startAll(List<String> spiderInfoIdList) {
    return bundleBuilder.listBundle(spiderInfoIdList.toString(), () -> {
        List<String> taskIdList = Lists.newArrayList();
        for (String id : spiderInfoIdList) {
            try {
                SpiderInfo info = spiderInfoService.getById(id).getResult();
                String taskId = commonSpider.start(info);
                taskIdList.add(taskId);
            } catch (JMException e) {
                LOG.error("启动任务ID{}出错,{}", id, e);
            }
        }
        return taskIdList;
    });
}
项目:SecureKeeper    文件:ZooKeeperServerMain.java   
protected void initializeAndRun(String[] args)
    throws ConfigException, IOException, AdminServerException
{
    try {
        ManagedUtil.registerLog4jMBeans();
    } catch (JMException e) {
        LOG.warn("Unable to register log4j JMX control", e);
    }

    ServerConfig config = new ServerConfig();
    if (args.length == 1) {
        config.parse(args[0]);
    } else {
        config.parse(args);
    }

    runFromConfig(config);
}
项目:spring4-understanding    文件:MBeanClientInterceptor.java   
/**
 * Routes a method invocation (not a property get/set) to the corresponding
 * operation on the managed resource.
 * @param method the method corresponding to operation on the managed resource.
 * @param args the invocation arguments
 * @return the value returned by the method invocation.
 */
private Object invokeOperation(Method method, Object[] args) throws JMException, IOException {
    MethodCacheKey key = new MethodCacheKey(method.getName(), method.getParameterTypes());
    MBeanOperationInfo info = this.allowedOperations.get(key);
    if (info == null) {
        throw new InvalidInvocationException("Operation '" + method.getName() +
                "' is not exposed on the management interface");
    }
    String[] signature = null;
    synchronized (this.signatureCache) {
        signature = this.signatureCache.get(method);
        if (signature == null) {
            signature = JmxUtils.getMethodSignature(method);
            this.signatureCache.put(method, signature);
        }
    }
    return this.serverToUse.invoke(this.objectName, method.getName(), args, signature);
}
项目:spring4-understanding    文件:MBeanExporter.java   
@Override
public void registerManagedResource(Object managedResource, ObjectName objectName) throws MBeanExportException {
    Assert.notNull(managedResource, "Managed resource must not be null");
    Assert.notNull(objectName, "ObjectName must not be null");
    try {
        if (isMBean(managedResource.getClass())) {
            doRegister(managedResource, objectName);
        }
        else {
            ModelMBean mbean = createAndConfigureMBean(managedResource, managedResource.getClass().getName());
            doRegister(mbean, objectName);
            injectNotificationPublisherIfNecessary(managedResource, mbean, objectName);
        }
    }
    catch (JMException ex) {
        throw new UnableToRegisterMBeanException(
                "Unable to register MBean [" + managedResource + "] with object name [" + objectName + "]", ex);
    }
}
项目:zookeeper    文件:ZooKeeperServerMain.java   
protected void initializeAndRun(String[] args)
    throws ConfigException, IOException
{
    try {
        ManagedUtil.registerLog4jMBeans();
    } catch (JMException e) {
        LOG.warn("Unable to register log4j JMX control", e);
    }

    ServerConfig config = new ServerConfig();
    if (args.length == 1) {
        config.parse(args[0]);
    } else {
        config.parse(args);
    }

    runFromConfig(config);
}
项目:StreamProcessingInfrastructure    文件:MBeanRegistry.java   
/**
 * Registers a new MBean with the platform MBean server. 
 * @param bean the bean being registered
 * @param parent if not null, the new bean will be registered as a child
 * node of this parent.
 */
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);
    if(bean.isHidden())
        return;
    ObjectName oname = makeObjectName(path, bean);
    try {
        mBeanServer.registerMBean(bean, oname);
        mapBean2Path.put(bean, path);
        mapName2Bean.put(bean.getName(), bean);
    } catch (JMException e) {
        LOG.warn("Failed to register MBean " + bean.getName());
        throw e;
    }
}
项目:spring    文件:MBeanExporter.java   
/**
 * Build an adapted MBean for the given bean instance, if possible.
 * <p>The default implementation builds a JMX 1.2 StandardMBean
 * for the target's MBean/MXBean interface in case of an AOP proxy,
 * delegating the interface's management operations to the proxy.
 * @param bean the original bean instance
 * @return the adapted MBean, or {@code null} if not possible
 */
@SuppressWarnings("unchecked")
protected DynamicMBean adaptMBeanIfPossible(Object bean) throws JMException {
    Class<?> targetClass = AopUtils.getTargetClass(bean);
    if (targetClass != bean.getClass()) {
        Class<?> ifc = JmxUtils.getMXBeanInterface(targetClass);
        if (ifc != null) {
            if (!ifc.isInstance(bean)) {
                throw new NotCompliantMBeanException("Managed bean [" + bean +
                        "] has a target class with an MXBean interface but does not expose it in the proxy");
            }
            return new StandardMBean(bean, ((Class<Object>) ifc), true);
        }
        else {
            ifc = JmxUtils.getMBeanInterface(targetClass);
            if (ifc != null) {
                if (!ifc.isInstance(bean)) {
                    throw new NotCompliantMBeanException("Managed bean [" + bean +
                            "] has a target class with an MBean interface but does not expose it in the proxy");
                }
                return new StandardMBean(bean, ((Class<Object>) ifc));
            }
        }
    }
    return null;
}
项目:bigstreams    文件:MBeanRegistry.java   
/**
 * Registers a new MBean with the platform MBean server. 
 * @param bean the bean being registered
 * @param parent if not null, the new bean will be registered as a child
 * node of this parent.
 */
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;
    }
}
项目:Camel    文件:TestSupport.java   
public static QuickfixjEngine createEngine(boolean lazy) throws ConfigError, FieldConvertError, IOException, JMException {       
    SessionID sessionID = new SessionID("FIX.4.4:SENDER->TARGET");

    MessageStoreFactory mockMessageStoreFactory = Mockito.mock(MessageStoreFactory.class);
    MessageStore mockMessageStore = Mockito.mock(MessageStore.class);
    Mockito.when(mockMessageStore.getCreationTime()).thenReturn(new Date());
    Mockito.when(mockMessageStoreFactory.create(sessionID)).thenReturn(mockMessageStore);

    SessionSettings settings = new SessionSettings();

    settings.setLong(sessionID, Session.SETTING_HEARTBTINT, 10);
    settings.setString(sessionID, Session.SETTING_START_TIME, "00:00:00");
    settings.setString(sessionID, Session.SETTING_END_TIME, "00:00:00");
    settings.setString(sessionID, SessionFactory.SETTING_CONNECTION_TYPE, SessionFactory.ACCEPTOR_CONNECTION_TYPE);
    settings.setLong(sessionID, Acceptor.SETTING_SOCKET_ACCEPT_PORT, 8000);
    settings.setBool(sessionID, Session.SETTING_USE_DATA_DICTIONARY, false);

    return new QuickfixjEngine("", settings, 
        mockMessageStoreFactory, 
        Mockito.mock(LogFactory.class), 
        Mockito.mock(MessageFactory.class), lazy);
}
项目:bigstreams    文件:ZooKeeperServerMain.java   
protected void initializeAndRun(String[] args)
    throws ConfigException, IOException
{
    try {
        ManagedUtil.registerLog4jMBeans();
    } catch (JMException e) {
        LOG.warn("Unable to register log4j JMX control", e);
    }

    ServerConfig config = new ServerConfig();
    if (args.length == 1) {
        config.parse(args[0]);
    } else {
        config.parse(args);
    }

    runFromConfig(config);
}
项目:my-spring-cache-redis    文件:MBeanClientInterceptor.java   
/**
 * Routes a method invocation (not a property get/set) to the corresponding
 * operation on the managed resource.
 * @param method the method corresponding to operation on the managed resource.
 * @param args the invocation arguments
 * @return the value returned by the method invocation.
 */
private Object invokeOperation(Method method, Object[] args) throws JMException, IOException {
    MethodCacheKey key = new MethodCacheKey(method.getName(), method.getParameterTypes());
    MBeanOperationInfo info = this.allowedOperations.get(key);
    if (info == null) {
        throw new InvalidInvocationException("Operation '" + method.getName() +
                "' is not exposed on the management interface");
    }
    String[] signature = null;
    synchronized (this.signatureCache) {
        signature = this.signatureCache.get(method);
        if (signature == null) {
            signature = JmxUtils.getMethodSignature(method);
            this.signatureCache.put(method, signature);
        }
    }
    return this.serverToUse.invoke(this.objectName, method.getName(), args, signature);
}
项目:Pogamut3    文件:FolderMBean.java   
/**
 * Export this folder to a JMX MBeanServer.
 * @param mBeanServer MBeanServer where this folder will be registered
 * @param domain domain under which the folder will appear, eg. "MyDomain"
 * @throws javax.management.JMException
 */
public void registerFolderHierarchyInJMX(MBeanServer mBeanServer, String domain, String path) throws JMException, IntrospectionException {
    // register this folder
    ObjectName objectName = ObjectName.getInstance(domain + ":type=" + path + ",name=" + folder.getName());
    mBeanServer.registerMBean(this, objectName);

    // register all subfolders
    for (Folder f : folder.getFolders()) {
        new FolderMBean(f).registerFolderHierarchyInJMX(mBeanServer, domain, path + "." + folder.getName());
    }
}
项目:alfresco-repository    文件:JmxDumpUtil.java   
/**
 * Dumps a local or remote MBeanServer's entire object tree for support purposes. Nested arrays and CompositeData
 * objects in MBean attribute values are handled.
 * 
 * @param connection
 *            the server connection (or server itself)
 * @param out
 *            PrintWriter to write the output to
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public static void dumpConnection(MBeanServerConnection connection, PrintWriter out) throws IOException
{
    JmxDumpUtil.showStartBanner(out);

    // Get all the object names
    Set<ObjectName> objectNames = connection.queryNames(null, null);

    // Sort the names (don't assume ObjectName implements Comparable in JDK 1.5)
    Set<ObjectName> newObjectNames = new TreeSet<ObjectName>(new Comparator<ObjectName>()
    {
        public int compare(ObjectName o1, ObjectName o2)
        {
            return o1.toString().compareTo(o2.toString());
        }
    });
    newObjectNames.addAll(objectNames);
    objectNames = newObjectNames;


    // Dump each MBean
    for (ObjectName objectName : objectNames)
    {
        try
        {
            printMBeanInfo(connection, objectName, out);
        }
        catch (JMException e)
        {
            // Sometimes beans can disappear while we are examining them
        }
    }
}
项目:alfresco-repository    文件:JmxDumpUtil.java   
/**
 * Dumps the details of a single MBean.
 * 
 * @param connection
 *            the server connection (or server itself)
 * @param objectName
 *            the object name
 * @param out
 *            PrintWriter to write the output to
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 * @throws JMException
 *             Signals a JMX error
 */
private static void printMBeanInfo(MBeanServerConnection connection, ObjectName objectName, PrintWriter out)
        throws IOException, JMException
{
    Map<String, Object> attributes = new TreeMap<String, Object>();
    MBeanInfo info = connection.getMBeanInfo(objectName);
    attributes.put("** Object Name", objectName.toString());
    attributes.put("** Object Type", info.getClassName());
    for (MBeanAttributeInfo element : info.getAttributes())
    {
        Object value;
        if (element.isReadable())
        {
            try
            {
                value = connection.getAttribute(objectName, element.getName());
            }
            catch (Exception e)
            {
                value = JmxDumpUtil.PROTECTED_VALUE;
            }
        }
        else
        {
            value = JmxDumpUtil.PROTECTED_VALUE;
        }
        attributes.put(element.getName(), value);
    }
    if (objectName.getCanonicalName().equals("Alfresco:Name=SystemProperties"))
    {
        String osName = (String) attributes.get(OS_NAME);
        if (osName != null && osName.toLowerCase().startsWith("linux"))
        {
            attributes.put(OS_NAME, updateOSNameAttributeForLinux(osName));
        }
    }
    tabulate(JmxDumpUtil.NAME_HEADER, JmxDumpUtil.VALUE_HEADER, attributes, out, 0);
}
项目:fuck_zookeeper    文件:MBeanRegistry.java   
/**
 * Unregister the MBean identified by the path.
 * @param path
 * @param bean
 */
private void unregister(String path,ZKMBeanInfo bean) throws JMException {
    if(path==null)
        return;
    if (!bean.isHidden()) {
        try {
            mBeanServer.unregisterMBean(makeObjectName(path, bean));
        } catch (JMException e) {
            LOG.warn("Failed to unregister MBean " + bean.getName());
            throw e;
        }
    }        
}
项目:fuck_zookeeper    文件:MBeanRegistry.java   
/**
 * Unregister MBean.
 * @param bean
 */
public void unregister(ZKMBeanInfo bean) {
    if(bean==null)
        return;
    String path=mapBean2Path.get(bean);
    try {
        unregister(path,bean);
    } catch (JMException e) {
        LOG.warn("Error during unregister", e);
    }
    mapBean2Path.remove(bean);
    mapName2Bean.remove(bean.getName());
}
项目:fuck_zookeeper    文件:MBeanRegistry.java   
/**
 * Unregister all currently registered MBeans
 */
public void unregisterAll() {
    for(Map.Entry<ZKMBeanInfo,String> e: mapBean2Path.entrySet()) {
        try {
            unregister(e.getValue(), e.getKey());
        } catch (JMException e1) {
            LOG.warn("Error during unregister", e1);
        }
    }
    mapBean2Path.clear();
    mapName2Bean.clear();
}
项目:fuck_zookeeper    文件:ServerCnxnFactory.java   
public void registerConnection(ServerCnxn serverCnxn) {
    if (zkServer != null) {
        ConnectionBean jmxConnectionBean = new ConnectionBean(serverCnxn, zkServer);
        try {
            MBeanRegistry.getInstance().register(jmxConnectionBean, zkServer.jmxServerBean);
            connectionBeans.put(serverCnxn, jmxConnectionBean);
        } catch (JMException e) {
            LOG.warn("Could not register connection", e);
        }
    }

}
项目:incubator-ratis    文件:JmxRegister.java   
/** Un-register the previously registered mBean. */
public synchronized boolean unregister() throws JMException {
  if (registeredName == null) {
    return false;
  }
  ManagementFactory.getPlatformMBeanServer().unregisterMBean(registeredName);
  LOG.info("Successfully un-registered JMX Bean with object name " + registeredName);
  registeredName = null;
  return true;
}
项目:lams    文件:MBeanClientInterceptor.java   
private Object invokeAttribute(PropertyDescriptor pd, MethodInvocation invocation)
        throws JMException, IOException {

    String attributeName = JmxUtils.getAttributeName(pd, this.useStrictCasing);
    MBeanAttributeInfo inf = this.allowedAttributes.get(attributeName);
    // If no attribute is returned, we know that it is not defined in the
    // management interface.
    if (inf == null) {
        throw new InvalidInvocationException(
                "Attribute '" + pd.getName() + "' is not exposed on the management interface");
    }
    if (invocation.getMethod().equals(pd.getReadMethod())) {
        if (inf.isReadable()) {
            return this.serverToUse.getAttribute(this.objectName, attributeName);
        }
        else {
            throw new InvalidInvocationException("Attribute '" + attributeName + "' is not readable");
        }
    }
    else if (invocation.getMethod().equals(pd.getWriteMethod())) {
        if (inf.isWritable()) {
            this.serverToUse.setAttribute(this.objectName, new Attribute(attributeName, invocation.getArguments()[0]));
            return null;
        }
        else {
            throw new InvalidInvocationException("Attribute '" + attributeName + "' is not writable");
        }
    }
    else {
        throw new IllegalStateException(
                "Method [" + invocation.getMethod() + "] is neither a bean property getter nor a setter");
    }
}
项目:lams    文件:MBeanRegistrationSupport.java   
/**
 * Actually unregister the specified MBean from the server.
 * @param objectName the suggested ObjectName for the MBean
 */
protected void doUnregister(ObjectName objectName) {
    boolean actuallyUnregistered = false;

    synchronized (this.registeredBeans) {
        if (this.registeredBeans.remove(objectName)) {
            try {
                // MBean might already have been unregistered by an external process
                if (this.server.isRegistered(objectName)) {
                    this.server.unregisterMBean(objectName);
                    actuallyUnregistered = true;
                }
                else {
                    if (logger.isWarnEnabled()) {
                        logger.warn("Could not unregister MBean [" + objectName + "] as said MBean " +
                                "is not registered (perhaps already unregistered by an external process)");
                    }
                }
            }
            catch (JMException ex) {
                if (logger.isErrorEnabled()) {
                    logger.error("Could not unregister MBean [" + objectName + "]", ex);
                }
            }
        }
    }

    if (actuallyUnregistered) {
        onUnregister(objectName);
    }
}
项目:lams    文件:MBeanExporter.java   
/**
 * Registers an existing MBean or an MBean adapter for a plain bean
 * with the {@code MBeanServer}.
 * @param bean the bean to register, either an MBean or a plain bean
 * @param beanKey the key associated with this bean in the beans map
 * @return the {@code ObjectName} under which the bean was registered
 * with the {@code MBeanServer}
 */
private ObjectName registerBeanInstance(Object bean, String beanKey) throws JMException {
    ObjectName objectName = getObjectName(bean, beanKey);
    Object mbeanToExpose = null;
    if (isMBean(bean.getClass())) {
        mbeanToExpose = bean;
    }
    else {
        DynamicMBean adaptedBean = adaptMBeanIfPossible(bean);
        if (adaptedBean != null) {
            mbeanToExpose = adaptedBean;
        }
    }
    if (mbeanToExpose != null) {
        if (logger.isInfoEnabled()) {
            logger.info("Located MBean '" + beanKey + "': registering with JMX server as MBean [" +
                    objectName + "]");
        }
        doRegister(mbeanToExpose, objectName);
    }
    else {
        if (logger.isInfoEnabled()) {
            logger.info("Located managed bean '" + beanKey + "': registering with JMX server as MBean [" +
                    objectName + "]");
        }
        ModelMBean mbean = createAndConfigureMBean(bean, beanKey);
        doRegister(mbean, objectName);
        injectNotificationPublisherIfNecessary(bean, mbean, objectName);
    }
    return objectName;
}
项目:lams    文件:MBeanExporter.java   
/**
 * Gets the {@code ModelMBeanInfo} for the bean with the supplied key
 * and of the supplied type.
 */
private ModelMBeanInfo getMBeanInfo(Object managedBean, String beanKey) throws JMException {
    ModelMBeanInfo info = this.assembler.getMBeanInfo(managedBean, beanKey);
    if (logger.isWarnEnabled() && ObjectUtils.isEmpty(info.getAttributes()) &&
            ObjectUtils.isEmpty(info.getOperations())) {
        logger.warn("Bean with key '" + beanKey +
                "' has been registered as an MBean but has no exposed attributes or operations");
    }
    return info;
}
项目:quickfixj-spring-boot-starter    文件:QuickFixJClientAutoConfiguration.java   
@Bean
@ConditionalOnProperty(prefix = "quickfixj.client", name = "jmx-enabled", havingValue = "true")
@ConditionalOnClass(JmxExporter.class)
@ConditionalOnSingleCandidate(Initiator.class)
@ConditionalOnMissingBean(name = "clientInitiatorMBean")
public ObjectName clientInitiatorMBean(Initiator clientInitiator) {
    try {
        JmxExporter exporter = new JmxExporter();
        return exporter.register(clientInitiator);
    } catch (JMException e) {
        throw new ConfigurationException(e.getMessage(), e);
    }
}