Java Code Examples for javax.management.ObjectName#getKeyProperty()

The following examples show how to use javax.management.ObjectName#getKeyProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GfxdMBeanAggregator.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
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);
  }
}
 
Example 2
Source File: BaseTool.java    From zooadmin with MIT License 6 votes vote down vote up
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 "";
    }
}
 
Example 3
Source File: SystemMemberCacheJmxImpl.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source File: DistributedSystemBridge.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
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());
  }
}
 
Example 5
Source File: KafkaProducerMetricsBinder.java    From summerframework with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 6
Source File: BackupService.java    From odo with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 7
Source File: MBeanFactory.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
        }
    }

}
 
Example 8
Source File: QueueMbeanRestartTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 9
Source File: GfxdDistributedSystemBridge.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
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();
  }
}
 
Example 10
Source File: DataSource.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 11
Source File: NodeProbe.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 12
Source File: NodeProbe.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 13
Source File: KafkaConsumerMetrics.java    From summerframework with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 14
Source File: GfxdMBeanAggregator.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 15
Source File: MBeanListener.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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);
            }
        }
    }
}
 
Example 16
Source File: StatusTransformer.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * 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
    }

}
 
Example 17
Source File: MBeans.java    From javamelody with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 18
Source File: MBeanTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
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+">");
    }
  }
}
 
Example 19
Source File: MBeanFactory.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * 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();

}
 
Example 20
Source File: StatusTransformer.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * 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
    }

}