jetty-9 improved mbean names

This commit is contained in:
Greg Wilkins 2012-09-21 17:15:29 +10:00
parent 9ee8ef7423
commit 950249932d
3 changed files with 43 additions and 44 deletions

View File

@ -169,33 +169,21 @@ public class MBeanContainer implements Container.InheritedListener, Dumpable
if (dot >= 0)
type = type.substring(dot + 1);
String context = (mbean instanceof ObjectMBean)?makeName(((ObjectMBean)mbean).getObjectContextBasis()):null;
String name = (mbean instanceof ObjectMBean)?makeName(((ObjectMBean)mbean).getObjectNameBasis()):null;
StringBuffer buf = new StringBuffer();
if (pname!=null)
{
buf.append("parent=")
.append(pname.getKeyProperty("type"))
.append("-");
if (pname.getKeyProperty("context")!=null)
buf.append(pname.getKeyProperty("context")).append("-");
buf.append(pname.getKeyProperty("id"))
.append(",");
}
buf.append("type=").append(type);
String context = (mbean instanceof ObjectMBean)?makeName(((ObjectMBean)mbean).getObjectContextBasis()):null;
if (context==null && pname!=null)
context=pname.getKeyProperty("context");
if (context != null && context.length()>1)
{
buf.append(buf.length()>0 ? ",":"");
buf.append("context=").append(context);
}
buf.append("context=").append(context).append(",");
buf.append("type=").append(type);
String name = (mbean instanceof ObjectMBean)?makeName(((ObjectMBean)mbean).getObjectNameBasis()):context;
if (name != null && name.length()>1)
{
buf.append(buf.length()>0 ? ",":"");
buf.append("name=").append(name);
}
buf.append(",").append("name=").append(name);
String basis = buf.toString();
Integer count = _unique.get(basis);

View File

@ -47,7 +47,12 @@ public class AbstractHandlerMBean extends ObjectMBean
String basis = null;
if (_managed instanceof ContextHandler)
{
return null;
ContextHandler handler = (ContextHandler)_managed;
String context = getContextName(handler);
if (context==null)
context=handler.getDisplayName();
if (context!=null)
return context;
}
else if (_managed instanceof AbstractHandler)
{
@ -68,26 +73,6 @@ public class AbstractHandlerMBean extends ObjectMBean
}
return super.getObjectContextBasis();
}
/* ------------------------------------------------------------ */
@Override
public String getObjectNameBasis()
{
if (_managed != null )
{
String name = null;
if (_managed instanceof ContextHandler)
{
ContextHandler context = (ContextHandler)_managed;
name = getContextName(context);
}
if (name != null)
return name;
}
return super.getObjectNameBasis();
}
/* ------------------------------------------------------------ */
protected String getContextName(ContextHandler context)
@ -116,6 +101,9 @@ public class AbstractHandlerMBean extends ObjectMBean
}
}
if (context.getVirtualHosts()!=null && context.getVirtualHosts().length>0)
name='"'+name+"@"+context.getVirtualHosts()[0]+'"';
return name;
}
}

View File

@ -0,0 +1,23 @@
package org.eclipse.jetty.server.jmx;
import org.eclipse.jetty.jmx.ObjectMBean;
import org.eclipse.jetty.server.AbstractConnector;
import org.eclipse.jetty.util.annotation.ManagedObject;
@ManagedObject("MBean Wrapper for Connectors")
public class AbstractConnectorMBean extends ObjectMBean
{
final AbstractConnector _connector;
public AbstractConnectorMBean(Object managedObject)
{
super(managedObject);
_connector=(AbstractConnector)managedObject;
}
@Override
public String getObjectContextBasis()
{
return String.format("%s@%x",_connector.getDefaultProtocol(),_connector.hashCode());
}
}