String serverInfo = null;
try {
Set gbeans = kernel.listGBeans((AbstractNameQuery) null);
Map beanInfos = new HashMap(); // key = GBeanInfo, value = List (of attribute names)
for (Iterator it = gbeans.iterator(); it.hasNext();) {
AbstractName name = (AbstractName) it.next();
if (isApplicationModule(name)) {
apps.add(" " + decodeModule(name.getNameProperty("j2eeType")) + ": " + name.getNameProperty("name"));
}
if (isWebModule(name)) {
webs.add(kernel.getAttribute(name, "contextPath").toString());
}
int stateValue = kernel.getGBeanState(name);
if (stateValue != State.RUNNING_INDEX) {
GBeanData data = kernel.getGBeanData(name);
State state = State.fromInt(stateValue);
StringBuffer buf = new StringBuffer();
buf.append("(").append(state.getName());
// Since it's not unusual for a failure to be caused by a port binding failure
// we'll see if there's a likely looking port attribute in the config data
// for the GBean. It's a long shot, but hey.
if (data != null && data.getAttributes() != null) {
Map map = data.getAttributes();
for (Iterator it2 = map.keySet().iterator(); it2.hasNext();) {
String att = (String) it2.next();
if (att.equals("port") || att.indexOf("Port") > -1) {
buf.append(",").append(att).append("=").append(map.get(att));
}
}
}
buf.append(")");
failed.put(name, buf.toString());
continue;
}
// Check if this is ServerInfo
GBeanInfo info = kernel.getGBeanInfo(name);
if (info.getClassName().equals("org.apache.geronimo.system.serverinfo.ServerInfo")) {
serverInfo = (String) kernel.getAttribute(name, "version");
}
// Look for any SocketAddress properties
List list = (List) beanInfos.get(info);
if (list == null) {
list = new ArrayList(3);
beanInfos.put(info, list);
Set atts = info.getAttributes();
for (Iterator it2 = atts.iterator(); it2.hasNext();) {
GAttributeInfo att = (GAttributeInfo) it2.next();
if (att.getType().equals("java.net.InetSocketAddress")) {
list.add(att);
}
}
}
for (int i = 0; i < list.size(); i++) {
GAttributeInfo att = (GAttributeInfo) list.get(i);
try {
InetSocketAddress addr = (InetSocketAddress) kernel.getAttribute(name, att.getName());
if (addr == null) {
log.debug("No value for GBean " + name + " attribute " + att.getName());
continue;
} else if (addr.getAddress() == null || addr.getAddress().getHostAddress() == null) {
log.debug("Null address or host for GBean " + name + " " + att.getName() + ": " + addr.getAddress());
}
String attName = info.getName();
if (list.size() > 1) {
attName += " " + decamelize(att.getName());
} else if (info.getAttribute("name") != null) {
attName += " " + kernel.getAttribute(name, "name");
}
ports.add(new AddressHolder(attName, addr));
} catch (IllegalStateException e) {
// We weren't able to load a port for this service -- that's a bummer
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
Collections.sort(apps);
// Helpful output: list of ports we listen on
if (ports.size() > 0) {
Collections.sort(ports);
System.out.println(" Listening on Ports:");
int max = 0;
for (int i = 0; i < ports.size(); i++) {
AddressHolder holder = (AddressHolder) ports.get(i);
if (holder.getAddress().getAddress() != null && holder.getAddress().getAddress().getHostAddress() != null)
{
max = Math.max(max, holder.getAddress().getAddress().getHostAddress().length());
}
}
for (int i = 0; i < ports.size(); i++) {
AddressHolder holder = (AddressHolder) ports.get(i);
StringBuffer buf = new StringBuffer();
buf.append(" ");
if (holder.getAddress().getPort() < 10) {
buf.append(' ');
}
if (holder.getAddress().getPort() < 100) {
buf.append(' ');
}
if (holder.getAddress().getPort() < 1000) {
buf.append(' ');
}
if (holder.getAddress().getPort() < 10000) {
buf.append(' ');
}
buf.append(holder.getAddress().getPort()).append(' ');
String address = holder.getAddress().getAddress() == null || holder.getAddress().getAddress().getHostAddress() == null ? "" :
holder.getAddress().getAddress().getHostAddress();
buf.append(address);
for (int j = address.length(); j <= max; j++) {
buf.append(' ');
}
buf.append(holder.getName());
out.println(buf.toString());
}
out.println();
}
// Helpful output: list of applications started
if (apps.size() > 0) {
out.println(" Started Application Modules:");
for (int i = 0; i < apps.size(); i++) {
out.println((String) apps.get(i));
}
out.println();
}
// Helpful output: Web URLs
if (webs.size() > 0) {
Collections.sort(webs);
out.println(" Web Applications:");
for (int i = 0; i < webs.size(); i++) {
out.println(" " + webs.get(i));
}
out.println();
}
// Helpful output: list of GBeans that did not start
if (failed.size() > 0) {
out.println(" WARNING: Some GBeans were not started successfully:");
for (Iterator it = failed.keySet().iterator(); it.hasNext();) {
AbstractName name = (AbstractName) it.next();
String state = (String) failed.get(name);
if (name.getNameProperty("name") != null) {
log.debug("Unable to start " + name + " " + state);
out.println(" " + name.getNameProperty("name") + " " + state);
} else {
out.println(" " + name + " " + state);
}
}
out.println();