下面列出了javax.management.ObjectName#getKeyProperty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void handleProxyRemoval(ObjectName objectName, Class interfaceClass, Object proxyObject,
FederationComponent oldVal) {
AggregateStatementMBean aggregateStmtBean = getAggregateStatementMBean(objectName,false);
if(aggregateStmtBean == null){
return;
}
String memberName = objectName.getKeyProperty("member");
aggregateStmtBean.getBridge().aggregate(memberName, null, oldVal);
if (aggregateStmtBean.getBridge().getMemberCount() == 0) {
String name = objectName.getKeyProperty("name");
ObjectName aggregateStatementName = ManagementUtils.getAggregateStatementMBeanName(name);
service.unregisterMBean(aggregateStatementName);
}
}
public ObjectName[] fetchRegionObjectNames(ObjectName memberMBeanName)
throws Exception {
List<ObjectName> list = new ArrayList<ObjectName>();
if (mapOfMembers.get(memberMBeanName) != null) {
MemberMXBean bean = mapOfMembers.get(memberMBeanName);
String member = memberMBeanName
.getKeyProperty(ManagementConstants.OBJECTNAME_MEMBER_APPENDER);
String[] regions = bean.listRegions();
for (String region : regions) {
ObjectName regionMBeanName = MBeanJMXAdapter.getRegionMBeanName(
member, region);
list.add(regionMBeanName);
}
ObjectName[] objNames = new ObjectName[list.size()];
return list.toArray(objNames);
} else {
throw new Exception(ManagementStrings.MEMBER_MBEAN_NOT_FOUND_IN_DS
.toString());
}
}
private Iterable<Tag> nameTag(ObjectName name) {
Tags tags = Tags.empty();
String clientId = name.getKeyProperty("client-id");
if (clientId != null) {
tags = Tags.concat(tags, "client.id", clientId);
}
String topic = name.getKeyProperty("topic");
if (topic != null) {
tags = Tags.concat(tags, "topic", topic);
}
String nodeId = name.getKeyProperty("node-id");
if (nodeId != null) {
tags = Tags.concat(tags, "node-id", nodeId);
}
return tags;
}
/**
* Get a list of strings(scheme + host + port) that the specified connector is running on
*
* @param name
* @return
*/
private ArrayList<String> getConnectorStrings(String name) {
ArrayList<String> connectorStrings = new ArrayList<String>();
try {
MBeanServer mbeanServer = getServerForName(name);
Set<ObjectName> objs = mbeanServer.queryNames(new ObjectName("*:type=Connector,*"), null);
String hostname = InetAddress.getLocalHost().getHostName();
InetAddress[] addresses = InetAddress.getAllByName(hostname);
for (Iterator<ObjectName> i = objs.iterator(); i.hasNext(); ) {
ObjectName obj = i.next();
String scheme = mbeanServer.getAttribute(obj, "scheme").toString();
String port = obj.getKeyProperty("port");
connectorStrings.add(scheme + "://localhost:" + port);
logger.info("Adding: {}", scheme + "://localhost:" + port);
}
} catch (Exception e) {
}
return connectorStrings;
}
/**
* Cleans up managed resources created for the region that was (created and)
* destroyed in a cache represented by this Managed Resource.
*
* @param regionPath
* path of the region that got destroyed
* @return a managed resource related to this region path
*/
public ManagedResource cleanupRegionResources(String regionPath) {
ManagedResource cleaned = null;
synchronized (this.managedRegionResourcesMap) {
Set<Entry<String, SystemMemberRegionJmxImpl>> entries = managedRegionResourcesMap.entrySet();
for (Iterator<Entry<String, SystemMemberRegionJmxImpl>> it = entries.iterator(); it.hasNext();) {
Entry<String, SystemMemberRegionJmxImpl> entry = it.next();
SystemMemberRegionJmxImpl managedResource = entry.getValue();
ObjectName objName = managedResource.getObjectName();
String pathProp = objName.getKeyProperty("path");
if (pathProp != null && pathProp.equals(regionPath)) {
cleaned = managedResource;
it.remove();
break;
}
}
}
return cleaned;
}
public static String getServer() {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ArrayList<String> endPoints = new ArrayList<String>();
try {
Set<ObjectName> objs = mbs.queryNames(new ObjectName("*:type=Connector,*"), Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")));
String hostname = InetAddress.getLocalHost().getHostName();
InetAddress[] addresses = InetAddress.getAllByName(hostname);
for (Iterator<ObjectName> i = objs.iterator(); i.hasNext(); ) {
ObjectName obj = i.next();
String scheme = mbs.getAttribute(obj, "scheme").toString();
String port = obj.getKeyProperty("port");
for (InetAddress addr : addresses) {
String host = addr.getHostAddress();
String ep = scheme + "://" + host + ":" + port;
endPoints.add(ep);
}
}
} catch (Exception e) {
return "";
}
if (endPoints.size() > 0) {
return endPoints.get(0);
} else {
return "";
}
}
/**
* Remove an existing Connector.
*
* @param name MBean Name of the component to remove
*
* @exception Exception if a component cannot be removed
*/
public void removeConnector(String name) throws Exception {
// Acquire a reference to the component to be removed
ObjectName oname = new ObjectName(name);
Service service = getService(oname);
String port = oname.getKeyProperty("port");
//String address = oname.getKeyProperty("address");
Connector conns[] = service.findConnectors();
for (int i = 0; i < conns.length; i++) {
String connAddress = String.valueOf(conns[i].getProperty("address"));
String connPort = ""+conns[i].getPort();
// if (((address.equals("null")) &&
if ((connAddress==null) && port.equals(connPort)) {
service.removeConnector(conns[i]);
conns[i].destroy();
break;
}
// } else if (address.equals(connAddress))
if (port.equals(connPort)) {
// Remove this component from its parent component
service.removeConnector(conns[i]);
conns[i].destroy();
break;
}
}
}
private void verifyPresenceOfQueueMbean() throws Exception {
for (ObjectName name : broker.getManagementContext().queryNames(null, null)) {
LOG.info("candidate :" + name);
String type = name.getKeyProperty("destinationType");
if (type != null && type.equals("Queue")) {
assertEquals(JMXSupport.encodeObjectNamePart(((ActiveMQQueue) createDestination()).getPhysicalName()), name.getKeyProperty("destinationName"));
LOG.info("found mbbean " + name);
return;
}
}
fail("expected to find matching queue mbean for: " + createDestination());
}
public void addTableToSystem(ObjectName objectName, TableMXBean memberProxy,
FederationComponent newVal) {
String fullPath = objectName.getKeyProperty("table");
ObjectName aggregateTableObjectName = ManagementUtils.getAggrgateTableMBeanName(fullPath);
try {
lock.lock();
if (!this.tableList.contains(fullPath)) {
AggregateTableMBeanBridge bridge = new AggregateTableMBeanBridge(
memberProxy.getName(), memberProxy.getParentSchema(),
memberProxy.getDefinition());
AggregateTableMXBean mbean = new AggregateTableMBean(bridge);
aggregateTableMBeanBridgeMap.put(aggregateTableObjectName, bridge);
service.registerInternalMBean(mbean, aggregateTableObjectName);
tableList.add(fullPath);
bridge.update(newVal, null, objectName);
}
if (mbeanCounterMap.containsKey(aggregateTableObjectName)) {
Long count = mbeanCounterMap.get(aggregateTableObjectName);
count++;
mbeanCounterMap.put(aggregateTableObjectName, count);
} else {
mbeanCounterMap.put(aggregateTableObjectName, (long) 1);
}
} catch(Exception e){
logger.warning(LocalizedStrings.DEBUG, "Exception in aggregate table mbean. Exception " + e);
}finally {
lock.unlock();
}
}
/**
* Creates the ObjectName for the ConnectionPoolMBean object to be registered
* @param original the ObjectName for the DataSource
* @return the ObjectName for the ConnectionPoolMBean
* @throws MalformedObjectNameException
*/
public ObjectName createObjectName(ObjectName original) throws MalformedObjectNameException {
String domain = ConnectionPool.POOL_JMX_DOMAIN;
Hashtable<String,String> properties = original.getKeyPropertyList();
String origDomain = original.getDomain();
properties.put("type", "ConnectionPool");
properties.put("class", this.getClass().getName());
if (original.getKeyProperty("path")!=null || properties.get("context")!=null) {
//this ensures that if the registration came from tomcat, we're not losing
//the unique domain, but putting that into as an engine attribute
properties.put("engine", origDomain);
}
ObjectName name = new ObjectName(domain,properties);
return name;
}
private List<Entry<String, ColumnFamilyStoreMBean>> getCFSMBeans(MBeanServerConnection mbeanServerConn, String type)
throws MalformedObjectNameException, IOException
{
ObjectName query = new ObjectName("org.apache.cassandra.db:type=" + type +",*");
Set<ObjectName> cfObjects = mbeanServerConn.queryNames(query, null);
List<Entry<String, ColumnFamilyStoreMBean>> mbeans = new ArrayList<Entry<String, ColumnFamilyStoreMBean>>(cfObjects.size());
for(ObjectName n : cfObjects)
{
String keyspaceName = n.getKeyProperty("keyspace");
ColumnFamilyStoreMBean cfsProxy = JMX.newMBeanProxy(mbeanServerConn, n, ColumnFamilyStoreMBean.class);
mbeans.add(new AbstractMap.SimpleImmutableEntry<String, ColumnFamilyStoreMBean>(keyspaceName, cfsProxy));
}
return mbeans;
}
private Iterable<Tag> nameTag(ObjectName name) {
Tags tags = Tags.empty();
String clientId = name.getKeyProperty("client-id");
if (clientId != null) {
tags = Tags.concat(tags, "client.id", clientId);
}
String topic = name.getKeyProperty("topic");
if (topic != null) {
tags = Tags.concat(tags, "topic", topic);
}
return tags;
}
@Override
public void handleProxyUpdate(ObjectName objectName, Class interfaceClass, Object proxyObject,
FederationComponent newVal, FederationComponent oldVal) {
AggregateStatementMBean aggregateStmtBean = getAggregateStatementMBean(objectName, false);
if(aggregateStmtBean == null){
return;
}
String memberName = objectName.getKeyProperty("member");
aggregateStmtBean.getBridge().aggregate(memberName, newVal, oldVal);
}
public void handleNotification(
final Notification notifIn,
final Object handback)
{
if (notifIn instanceof MBeanServerNotification)
{
final MBeanServerNotification notif = (MBeanServerNotification) notifIn;
final ObjectName objectName = notif.getMBeanName();
boolean match = false;
if ( mObjectName != null && mObjectName.equals(objectName) )
{
match = true;
}
else if ( objectName.getDomain().equals( mJMXDomain ) )
{
if ( mType != null && mType.equals(objectName.getKeyProperty(TYPE_KEY)) )
{
final String mbeanName = objectName.getKeyProperty(NAME_KEY);
if (mName != null && mName.equals(mbeanName))
{
match = true;
}
}
}
if ( match )
{
final String notifType = notif.getType();
if (MBeanServerNotification.REGISTRATION_NOTIFICATION.equals(notifType))
{
mCallback.mbeanRegistered(objectName, this);
}
else if (MBeanServerNotification.UNREGISTRATION_NOTIFICATION.equals(notifType))
{
mCallback.mbeanUnregistered(objectName, this);
}
}
}
}
public Map.Entry<String, JMXEnabledThreadPoolExecutorMBean> next()
{
ObjectName objectName = resIter.next();
String poolName = objectName.getKeyProperty("type");
JMXEnabledThreadPoolExecutorMBean threadPoolProxy = JMX.newMBeanProxy(mbeanServerConn, objectName, JMXEnabledThreadPoolExecutorMBean.class);
return new AbstractMap.SimpleImmutableEntry<String, JMXEnabledThreadPoolExecutorMBean>(poolName, threadPoolProxy);
}
/**
* Write detailed information about a wrapper.
* @param writer The output writer
* @param objectName The wrapper MBean names
* @param mBeanServer MBean server
* @param mode Mode <code>0</code> will generate HTML.
* Mode <code>1</code> will generate XML.
* @throws Exception Propagated JMX error
*/
public static void writeWrapper(PrintWriter writer, ObjectName objectName,
MBeanServer mBeanServer, int mode)
throws Exception {
if (mode == 0) {
String servletName = objectName.getKeyProperty("name");
String[] mappings = (String[])
mBeanServer.invoke(objectName, "findMappings", null, null);
writer.print("<h2>");
writer.print(Escape.htmlElementContext(servletName));
if ((mappings != null) && (mappings.length > 0)) {
writer.print(" [ ");
for (int i = 0; i < mappings.length; i++) {
writer.print(Escape.htmlElementContext(mappings[i]));
if (i < mappings.length - 1) {
writer.print(" , ");
}
}
writer.print(" ] ");
}
writer.print("</h2>");
writer.print("<p>");
writer.print(" Processing time: ");
writer.print(formatTime(mBeanServer.getAttribute
(objectName, "processingTime"), true));
writer.print(" Max time: ");
writer.print(formatTime(mBeanServer.getAttribute
(objectName, "maxTime"), false));
writer.print(" Request count: ");
writer.print(mBeanServer.getAttribute(objectName, "requestCount"));
writer.print(" Error count: ");
writer.print(mBeanServer.getAttribute(objectName, "errorCount"));
writer.print(" Load time: ");
writer.print(formatTime(mBeanServer.getAttribute
(objectName, "loadTime"), false));
writer.print(" Classloading time: ");
writer.print(formatTime(mBeanServer.getAttribute
(objectName, "classLoadTime"), false));
writer.print("</p>");
} else if (mode == 1){
// for now we don't write out the wrapper details
}
}
/**
* Create a new StandardContext.
*
* @param parent MBean Name of the associated parent component
* @param path The context path for this Context
* @param docBase Document base directory (or WAR) for this Context
* @param xmlValidation if XML descriptors should be validated
* @param xmlNamespaceAware if the XML processor should namespace aware
* @return the object name of the created context
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createStandardContext(String parent,
String path,
String docBase,
boolean xmlValidation,
boolean xmlNamespaceAware)
throws Exception {
// Create a new StandardContext instance
StandardContext context = new StandardContext();
path = getPathStr(path);
context.setPath(path);
context.setDocBase(docBase);
context.setXmlValidation(xmlValidation);
context.setXmlNamespaceAware(xmlNamespaceAware);
ContextConfig contextConfig = new ContextConfig();
context.addLifecycleListener(contextConfig);
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
ObjectName deployer = new ObjectName(pname.getDomain()+
":type=Deployer,host="+
pname.getKeyProperty("host"));
if(mserver.isRegistered(deployer)) {
String contextName = context.getName();
mserver.invoke(deployer, "addServiced",
new Object [] {contextName},
new String [] {"java.lang.String"});
String configPath = (String)mserver.getAttribute(deployer,
"configBaseName");
String baseName = context.getBaseName();
File configFile = new File(new File(configPath), baseName+".xml");
if (configFile.isFile()) {
context.setConfigFile(configFile.toURI().toURL());
}
mserver.invoke(deployer, "manageApp",
new Object[] {context},
new String[] {"org.apache.catalina.Context"});
mserver.invoke(deployer, "removeServiced",
new Object [] {contextName},
new String [] {"java.lang.String"});
} else {
log.warn("Deployer not found for "+pname.getKeyProperty("host"));
Service service = getService(pname);
Engine engine = service.getContainer();
Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
host.addChild(context);
}
// Return the corresponding MBean name
return context.getObjectName().toString();
}
private void verifyListIndexInfo(MBeanServerConnection mbeanServer,
String tableName, String memberId, String serverGroup,
boolean verifyMBean, ObjectName tableON, String m)
throws InstanceNotFoundException, MBeanException, ReflectionException,
IOException, AttributeNotFoundException {
Log.getLogWriter().info("Expected Index List : " + getAllIndex(tableName));
Object result = mbeanServer.invoke(tableON, m, null, null);
Log.getLogWriter().info(" Result list index Info" + result + "");
Log.getLogWriter().info("GFXD Table Op "+ m + " : " + HydraUtil.ObjectToString(result));
Log.getLogWriter().info("GFXD Table Op "+ m + " : " + result.getClass());
CompositeData[] data = (CompositeData[]) result;
Log.getLogWriter().info(" composite data length: " + data.length);
for(int i = 0; i < data.length; i++) {
Log.getLogWriter().info(" composite data : " + HydraUtil.ObjectToString(data[i]) + "");
}
String[] array = tableName.split("\\.");
Log.getLogWriter().info("#listIndexInfo schemaName " + array[0] + " tableName " + array[1]);
mbeanHelper.runQueryAndPrintValue("select * from SYS.INDEXES where SCHEMANAME='"+ array[0] +"' and TABLENAME='"+ array[1] + "'");
Number indexCount = (Number)mbeanHelper.runQueryAndGetValue("select COUNT(*) from SYS.INDEXES where SCHEMANAME='"+ array[0] +"' and TABLENAME='"+ array[1] + "'", OutputType.INT);
String[] tableServerGroups = (String[]) mbeanServer.getAttribute(tableON, "ServerGroups");
String memberName = tableON.getKeyProperty("member");
boolean isPartitionProxy = isPrProxyTableMBean(tableName, serverGroup, tableServerGroups, memberName);
if (!isPartitionProxy) {
Log.getLogWriter().info(
"Table is NOT partition proxy table hence matching indexinfo #listIndexInfo #isPartitionProxy");
match("Index count does not match for " + tableName, indexCount.intValue(), data.length);
} else {
Log.getLogWriter().info(
"Table is partition proxy table hence skipping matching indexinfo #listIndexInfo #isPartitionProxy");
}
if(data.length > 0 && verifyMBean){
result = mbeanServer.invoke(tableON, "listIndexStats", null, null);
Log.getLogWriter().info(" Result list index Info" + result + "");
Log.getLogWriter().info("GFXD Table Op listIndexStats : " + HydraUtil.ObjectToString(result));
Log.getLogWriter().info("GFXD Table Op listIndexStats : " + result.getClass());
CompositeData[] stats = (CompositeData[]) result;
Log.getLogWriter().info(" index length: " + stats.length);
for(int i = 0; i < stats.length; i++) {
Log.getLogWriter().info(" index stats : " + HydraUtil.ObjectToString(stats[i]) + "");
Number entrySize = (Number)stats[i].get("entrySize");
String indexName = (String) stats[i].get("indexName");
Number keySize = (Number) stats[i].get("keySize");
Number rowCount = (Number) stats[i].get("rowCount");
Number actualEntrySize = (Number)mbeanHelper.runQueryAndGetValue("select ENTRY_SIZE from sys.memoryanalytics WHERE TABLE_name = '"
+ tableName + "' and ID like '%" + memberId + "%' AND INDEX_NAME='" + indexName + "'", OutputType.FLOAT);
match("Validation failed for matching Index " + indexName + " on table " + tableName + " attribute ENTRY_SIZE" , entrySize, actualEntrySize);
Number actualKeySize = (Number)mbeanHelper.runQueryAndGetValue("select KEY_SIZE from sys.memoryanalytics WHERE TABLE_name = '"
+ tableName + "' and ID like '%" + memberId + "%' AND INDEX_NAME='" + indexName + "'", OutputType.FLOAT);
match("Validation failed for matching Index " + indexName + " on table " + tableName + " attribute KEY_SIZE" , keySize, actualKeySize);
Number actualRowCount = (Number)mbeanHelper.runQueryAndGetValue("select NUM_ROWS from sys.memoryanalytics WHERE TABLE_name = '"
+ tableName + "' and ID like '%" + memberId + "%' AND INDEX_NAME='" + indexName + "'", OutputType.LONG);
match("Validation failed for matching Index " + indexName + " on table " + tableName + " attribute ROW_COUNT" , rowCount, actualRowCount);
Log.getLogWriter().info("#listIndexStats IndexName <" + indexName +"> ES <" + entrySize +"> COUNT <" + rowCount
+ " KS <" + keySize+">");
Log.getLogWriter().info("#listIndexStatsFromMemAnalytics IndexName <" + indexName +"> ES <" + actualEntrySize +"> COUNT <" + actualRowCount
+ " KS <" + actualKeySize+">");
}
}
}
private List<MBeanNode> getMBeanNodes() throws JMException {
final List<MBeanNode> result = new ArrayList<MBeanNode>();
final Set<ObjectName> names = mbeanServer.queryNames(null, null);
for (final ObjectName name : names) {
final String domain = name.getDomain();
if ("jboss.deployment".equals(domain)) {
// la partie "jboss.deployment" dans JBoss (5.0.x) est plutôt inutile et trop lourde
continue;
}
MBeanNode domainNode = getMBeanNodeFromList(result, domain);
if (domainNode == null) {
domainNode = new MBeanNode(domain);
result.add(domainNode);
}
final String keyPropertyListString = name.getKeyPropertyListString();
final String firstPropertyValue;
final int indexOf = keyPropertyListString.indexOf('=');
if (indexOf == -1) {
// n'arrive probablement pas, mais au cas où
firstPropertyValue = null;
} else {
firstPropertyValue = name
.getKeyProperty(keyPropertyListString.substring(0, indexOf));
}
MBeanNode firstPropertyNode = getMBeanNodeFromList(domainNode.getChildren(),
firstPropertyValue);
if (firstPropertyNode == null) {
firstPropertyNode = new MBeanNode(firstPropertyValue);
domainNode.getChildren().add(firstPropertyNode);
}
try {
final MBeanNode mbean = getMBeanNode(name);
firstPropertyNode.getChildren().add(mbean);
} catch (final IllegalStateException e) {
// for JBoss EAP 6 (#757)
continue;
}
}
sortMBeanNodes(result);
return result;
}
/**
* Write detailed information about a wrapper.
*/
public static void writeWrapper(PrintWriter writer, ObjectName objectName,
MBeanServer mBeanServer, int mode)
throws Exception {
if (mode == 0) {
String servletName = objectName.getKeyProperty("name");
String[] mappings = (String[])
mBeanServer.invoke(objectName, "findMappings", null, null);
writer.print("<h2>");
writer.print(filter(servletName));
if ((mappings != null) && (mappings.length > 0)) {
writer.print(" [ ");
for (int i = 0; i < mappings.length; i++) {
writer.print(filter(mappings[i]));
if (i < mappings.length - 1) {
writer.print(" , ");
}
}
writer.print(" ] ");
}
writer.print("</h2>");
writer.print("<p>");
writer.print(" Processing time: ");
writer.print(formatTime(mBeanServer.getAttribute
(objectName, "processingTime"), true));
writer.print(" Max time: ");
writer.print(formatTime(mBeanServer.getAttribute
(objectName, "maxTime"), false));
writer.print(" Request count: ");
writer.print(mBeanServer.getAttribute(objectName, "requestCount"));
writer.print(" Error count: ");
writer.print(mBeanServer.getAttribute(objectName, "errorCount"));
writer.print(" Load time: ");
writer.print(formatTime(mBeanServer.getAttribute
(objectName, "loadTime"), false));
writer.print(" Classloading time: ");
writer.print(formatTime(mBeanServer.getAttribute
(objectName, "classLoadTime"), false));
writer.print("</p>");
} else if (mode == 1){
// for now we don't write out the wrapper details
}
}