List of usage examples for java.lang.management ManagementFactory getPlatformMBeanServer
public static synchronized MBeanServer getPlatformMBeanServer()
From source file:org.apache.solr.cloud.api.collections.CollectionsAPIDistributedZkTest.java
private void checkNoTwoShardsUseTheSameIndexDir() throws Exception { Map<String, Set<String>> indexDirToShardNamesMap = new HashMap<>(); List<MBeanServer> servers = new LinkedList<>(); servers.add(ManagementFactory.getPlatformMBeanServer()); servers.addAll(MBeanServerFactory.findMBeanServer(null)); for (final MBeanServer server : servers) { Set<ObjectName> mbeans = new HashSet<>(); mbeans.addAll(server.queryNames(null, null)); for (final ObjectName mbean : mbeans) { try { Map<String, String> props = mbean.getKeyPropertyList(); String category = props.get("category"); String name = props.get("name"); if ((category != null && category.toString().equals(Category.CORE.toString())) && (name != null && name.equals("indexDir"))) { String indexDir = server.getAttribute(mbean, "Value").toString(); String key = props.get("dom2") + "." + props.get("dom3") + "." + props.get("dom4"); if (!indexDirToShardNamesMap.containsKey(indexDir)) { indexDirToShardNamesMap.put(indexDir.toString(), new HashSet<>()); }/*from w ww .j ava 2 s. c om*/ indexDirToShardNamesMap.get(indexDir.toString()).add(key); } } catch (Exception e) { // ignore, just continue - probably a "Value" attribute // not found } } } assertTrue( "Something is broken in the assert for no shards using the same indexDir - probably something was changed in the attributes published in the MBean of " + SolrCore.class.getSimpleName() + " : " + indexDirToShardNamesMap, indexDirToShardNamesMap.size() > 0); for (Entry<String, Set<String>> entry : indexDirToShardNamesMap.entrySet()) { if (entry.getValue().size() > 1) { fail("We have shards using the same indexDir. E.g. shards " + entry.getValue().toString() + " all use indexDir " + entry.getKey()); } } }
From source file:org.apache.geode.management.internal.ManagementAgent.java
private void registerAccessControlMBean() { try {/*from w w w.j av a 2 s. c o m*/ AccessControlMBean acc = new AccessControlMBean(this.securityService); ObjectName accessControlMBeanON = new ObjectName(ResourceConstants.OBJECT_NAME_ACCESSCONTROL); MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer(); Set<ObjectName> names = platformMBeanServer.queryNames(accessControlMBeanON, null); if (names.isEmpty()) { try { platformMBeanServer.registerMBean(acc, accessControlMBeanON); logger.info("Registered AccessControlMBean on " + accessControlMBeanON); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) { throw new GemFireConfigException("Error while configuring access control for jmx resource", e); } } } catch (MalformedObjectNameException e) { throw new GemFireConfigException("Error while configuring access control for jmx resource", e); } }
From source file:ddf.metrics.collector.rrd4j.RrdJmxCollector.java
/** * @return local MBean server/* w ww. j av a 2 s . c o m*/ */ private MBeanServer getLocalMBeanServer() { if (localMBeanServer == null) { localMBeanServer = ManagementFactory.getPlatformMBeanServer(); } return localMBeanServer; }
From source file:org.springframework.ldap.config.LdapTemplateNamespaceHandlerTest.java
@Test public void verifyParsePool2SizeSet() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( "/ldap-namespace-config-pool2-configured-poolsize.xml"); ContextSource outerContextSource = ctx.getBean(ContextSource.class); assertThat(outerContextSource).isNotNull(); ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); assertThat(pooledContextSource).isNotNull(); org.apache.commons.pool2.impl.GenericKeyedObjectPool objectPool = (org.apache.commons.pool2.impl.GenericKeyedObjectPool) getInternalState( pooledContextSource, "keyedObjectPool"); assertThat(objectPool.getMaxTotal()).isEqualTo(12); assertThat(objectPool.getMaxIdlePerKey()).isEqualTo(20); assertThat(objectPool.getMaxTotalPerKey()).isEqualTo(10); assertThat(objectPool.getMaxWaitMillis()).isEqualTo(13); assertThat(objectPool.getMinIdlePerKey()).isEqualTo(14); assertThat(objectPool.getBlockWhenExhausted()).isEqualTo(true); assertThat(objectPool.getEvictionPolicyClassName()) .isEqualTo("org.springframework.ldap.pool2.DummyEvictionPolicy"); assertThat(objectPool.getFairness()).isEqualTo(true); assertThat(objectPool.getLifo()).isEqualTo(false); // ensures the pool is registered ObjectName oname = objectPool.getJmxName(); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); Set<ObjectName> result = mbs.queryNames(oname, null); assertThat(result).hasSize(1);//from w ww .j a v a 2 s .co m assertThat(oname.toString()).isEqualTo("org.springframework.ldap.pool2:type=ldap-pool,name=test-pool"); }
From source file:org.wso2.carbon.andes.core.QueueManagerServiceImpl.java
/** * {@inheritDoc}/*from w ww . ja va 2 s. c o m*/ */ @Override public long getNumberOfMessagesInDLCForQueue(String queueName) throws QueueManagerException { long messageCount = 0; MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); try { ObjectName objectName = new ObjectName( "org.wso2.andes:type=QueueManagementInformation,name=QueueManagementInformation"); String operationName = "getNumberOfMessagesInDLCForQueue"; Object[] parameters = new Object[] { queueName }; String[] signature = new String[] { String.class.getName() }; Object result = mBeanServer.invoke(objectName, operationName, parameters, signature); if (result != null) { messageCount = (Long) result; } return messageCount; } catch (MalformedObjectNameException | ReflectionException | MBeanException | InstanceNotFoundException e) { throw new QueueManagerException( "Cannot access mBean operations for message count in " + "DLC for a queue:" + queueName, e); } }
From source file:org.wso2.carbon.andes.core.QueueManagerServiceImpl.java
/** * {@inheritDoc}//w ww.j a v a2s .c om */ @Override public Message[] getMessageInDLCForQueue(String queueName, long nextMessageIdToRead, int maxMessageCount) throws QueueManagerException { List<Message> messageList = new ArrayList<>(); try { MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); ObjectName objectName = new ObjectName( "org.wso2.andes:type=QueueManagementInformation,name=QueueManagementInformation"); String operationName = "getMessageInDLCForQueue"; Object[] parameters = new Object[] { queueName, nextMessageIdToRead, maxMessageCount }; String[] signature = new String[] { String.class.getName(), long.class.getName(), int.class.getName() }; Object result = mBeanServer.invoke(objectName, operationName, parameters, signature); if (result != null) { CompositeData[] messageDataList = (CompositeData[]) result; for (CompositeData messageData : messageDataList) { Message message = new Message(); message.setMsgProperties((String) messageData.get(QueueManagementInformation.JMS_PROPERTIES)); message.setContentType((String) messageData.get(QueueManagementInformation.CONTENT_TYPE)); message.setMessageContent((String[]) messageData.get(QueueManagementInformation.CONTENT)); message.setJMSMessageId((String) messageData.get(QueueManagementInformation.JMS_MESSAGE_ID)); message.setJMSReDelivered( (Boolean) messageData.get(QueueManagementInformation.JMS_REDELIVERED)); message.setJMSDeliveredMode( (Integer) messageData.get(QueueManagementInformation.JMS_DELIVERY_MODE)); message.setJMSTimeStamp((Long) messageData.get(QueueManagementInformation.TIME_STAMP)); message.setDlcMsgDestination( (String) messageData.get(QueueManagementInformation.MSG_DESTINATION)); message.setAndesMsgMetadataId( (Long) messageData.get(QueueManagementInformation.ANDES_MSG_METADATA_ID)); messageList.add(message); } } } catch (InstanceNotFoundException | MBeanException | ReflectionException | MalformedObjectNameException e) { throw new QueueManagerException("Cannot get message in DLC for a queue : " + queueName, e); } return messageList.toArray(new org.wso2.carbon.andes.core.types.Message[messageList.size()]); }
From source file:org.codice.ddf.registry.federationadmin.impl.FederationAdmin.java
private void configureMBean() { mbeanServer = ManagementFactory.getPlatformMBeanServer(); try {//from w w w. j a v a2s .c om objectName = new ObjectName(FederationAdminMBean.OBJECT_NAME); } catch (MalformedObjectNameException e) { LOGGER.info("Exception while creating object name: {}", FederationAdminMBean.OBJECT_NAME, e); } try { try { mbeanServer.registerMBean(new StandardMBean(this, FederationAdminMBean.class), objectName); } catch (InstanceAlreadyExistsException e) { mbeanServer.unregisterMBean(objectName); mbeanServer.registerMBean(new StandardMBean(this, FederationAdminMBean.class), objectName); } } catch (Exception e) { LOGGER.info("Could not register mbean.", e); } }
From source file:org.jahia.bin.errors.ErrorFileDumper.java
public static boolean isHeapDumpSupported() throws MalformedObjectNameException { MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); ObjectName hotSpotDiagnostic = new ObjectName("com.sun.management:type=HotSpotDiagnostic"); return mBeanServer.isRegistered(hotSpotDiagnostic); }
From source file:org.jahia.bin.errors.ErrorFileDumper.java
public static File performHeapDump() throws MalformedObjectNameException, InstanceNotFoundException, ReflectionException, MBeanException { MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); ObjectName hotSpotDiagnostic = new ObjectName("com.sun.management:type=HotSpotDiagnostic"); if (!mBeanServer.isRegistered(hotSpotDiagnostic)) { throw new UnsupportedOperationException("Unable to find the " + "'com.sun.management:type=HotSpotDiagnostic'" + " managed bean to perform heap dump"); }/*from w w w . j a v a 2 s . co m*/ File hprofFilePath = getNextHeapDumpFile(); mBeanServer.invoke(hotSpotDiagnostic, "dumpHeap", new Object[] { hprofFilePath.getPath(), Boolean.TRUE }, new String[] { String.class.getName(), boolean.class.getName() }); return hprofFilePath; }
From source file:com.alibaba.jstorm.utils.JStormUtils.java
/** * @return//from ww w.ja va 2 s . c om * @@@ Todo */ public static Long getPhysicMemorySize() { Object object; try { object = ManagementFactory.getPlatformMBeanServer().getAttribute( new ObjectName("java.lang", "type", "OperatingSystem"), "TotalPhysicalMemorySize"); } catch (Exception e) { LOG.warn("Failed to get system physical memory size,", e); return null; } Long ret = (Long) object; return ret; }