CommandMapperpublic class CommandMapper extends Object Maps commands to Command objects. The command objects encapsulate monitoring
functionality exposed to the user interface. |
Fields Summary |
---|
private static HashMap | instanceMapA map to track instance name and corresponding command mapper | private String | instanceNameName of the instance | private static com.sun.enterprise.util.i18n.StringManager | localStrings | public static final String | CLI_COMMAND_GETConstant to denote CLI get command | public static final String | CLI_COMMAND_LISTConstant to denote CLI list command | public static final String | CLI_COMMAND_SETConstant to denote CLI set command |
Constructors Summary |
---|
private CommandMapper()Private constructor. Use factory method to get an instance.
|
Methods Summary |
---|
public static synchronized com.sun.enterprise.admin.monitor.CommandMapper | getInstance(java.lang.String instanceName)Get command mapper for specified server instance. This is the factory
method to be used to obtain instances of command mapper.
CommandMapper cm = (CommandMapper)instanceMap.get(instanceName);
if (cm == null) {
cm = new CommandMapper();
cm.instanceName = instanceName;
instanceMap.put(instanceName, cm);
}
return cm;
| public MonitorCommand | mapCliCommand(java.lang.String command, java.lang.String dottedName)Map CLI command and dotted name to a command object.
MonitorCommand monitorCommand = null;
if (CLI_COMMAND_GET.equalsIgnoreCase(command)) {
monitorCommand = mapGetCommand(dottedName);
} else if (CLI_COMMAND_LIST.equalsIgnoreCase(command)) {
monitorCommand = mapListCommand(dottedName);
} else {
String msg = localStrings.getString( "admin.monitor.unknown_cli_command", command );
throw new IllegalArgumentException( msg );
}
return monitorCommand;
| public MonitorGetCommand | mapGetCommand(java.lang.String dottedName)Map CLI get command to a command object.
A dotted name for get command is of the form
instanceName([.type[.name])*.(star|attrName) where,
instanceName is name of server instance, type is derived from
MonitoredObjectType, name is monitored component name, star is
the character * (denotes all attributes) and attrName is
the name of the attribute to get.
ParsedDottedName result = parseDottedName(dottedName, CLI_COMMAND_GET);
MonitorGetCommand command;
if (result.monitoredObjectType != null) {
command = new MonitorGetCommand(result.objectName,
result.monitoredObjectType, result.attributeName);
} else {
command = new MonitorGetCommand(result.objectName,
result.attributeName);
}
return command;
| public MonitorListCommand | mapListCommand(java.lang.String dottedName)Map CLI list command to a command object.
A dotted name for list command is of the form
instanceName([.type[.name])* where, instanceName is name
of server instance, type is derived from MonitoredObjectType, name is
monitored component name.
ParsedDottedName result = parseDottedName(dottedName, CLI_COMMAND_LIST);
MonitorListCommand command;
if (result.monitoredObjectType != null) {
command = new MonitorListCommand(result.objectName,
result.monitoredObjectType);
} else {
command = new MonitorListCommand(result.objectName);
}
return command;
| public MonitorSetCommand | mapSetCommand(java.lang.String dottedName, java.lang.Object args)
ParsedDottedName result = parseDottedName(dottedName, CLI_COMMAND_SET);
MonitorSetCommand command = null;
String argsStr = (String)args;
StringTokenizer st = new StringTokenizer(argsStr, ",");
String[] commandArgs = new String[st.countTokens()];
int i = 0;
while (st.hasMoreTokens()){
commandArgs[i] = st.nextToken();
i++;
}
command = new MonitorSetCommand(result.objectName,
result.monitoredObjectType, result.operationName,
commandArgs);
return command;
| private com.sun.enterprise.admin.monitor.ParsedDottedName | parseDottedName(java.lang.String dottedString, java.lang.String command)Parse dotted name for the specified command. This method splits the
dotted string into tokens and then invokes parseTokens().
ArrayList tokenList = new ArrayList();
Name dottedName = new Name(dottedString);
int nTokens = dottedName.getNumParts();
if (nTokens < 1) {
String msg = localStrings.getString( "admin.monitor.name_does_not_contain_any_tokens", dottedString );
throw new MalformedNameException( msg );
}
for (int j = 0; j < nTokens; j++) {
tokenList.add(dottedName.getNamePart(j).toString());
}
return parseTokens(tokenList, command, dottedString);
| private com.sun.enterprise.admin.monitor.ParsedDottedName | parseTokens(java.util.ArrayList tokenList, java.lang.String command, java.lang.String dottedName)Parse tokens derived from the dotted name for specified CLI command. This
method tries to derive MBean object name and other parameters for the
specified command.
Properties props = new Properties();
props.put(ObjectNames.kTypeKeyName, ObjectNames.kMonitoringType);
props.put(ObjectNames.kNameKeyName, ObjectNames.kMonitoringRootClass);
props.put(ObjectNames.kMonitoringClassName,
ObjectNames.kMonitoringRootClass);
props.put(ObjectNames.kServerInstanceKeyName, instanceName);
int count = tokenList.size();
MonitoredObjectType type = null;
// 1st token is name of the instance, ignore.
// Process 2nd token onwards - either singleton-type or type.name. The
// last token is a special case because it can be a wildcard or
// attribute name for get command, a type or name for list command
int tokenCount = count;
if (command.equals(CLI_COMMAND_GET) || command.equals(CLI_COMMAND_SET)) {
tokenCount = count - 1;
}
boolean processType = true;
for (int i = 1; i < tokenCount; i++) {
String token = (String)tokenList.get(i);
if (processType) {
type = MonitoredObjectType.getMonitoredObjectTypeOrNull(token);
if (type == null) {
String msg = localStrings.getString( "admin.monitor.invalid_entry", dottedName, token );
throw new MalformedNameException( msg );
}
String typeName = type.getTypeName();
if (type.isSingleton()) {
swapNameType(props, typeName, typeName);
processType = true;
type = null;
} else {
processType = false;
}
} else {
swapNameType(props, type.getTypeName(), token);
processType = true;
type = null;
}
}
ParsedDottedName result = new ParsedDottedName();
try {
result.objectName = new ObjectName(ObjectNames.kDefaultIASDomainName,
props);
} catch (MalformedObjectNameException ione) {
throw new MalformedNameException(ione.getMessage());
}
// type != null -- Means that a name was expected in parsing. For
// LIST command implies list of objects of this type. For GET command
// implies all specified attribute(or wildcard) of on specified type of
// objects.
if (type != null) {
result.monitoredObjectType = type;
}
if (command.equals(CLI_COMMAND_GET)) {
result.attributeName = (String)tokenList.get(count -1);
} else if (command.equals(CLI_COMMAND_SET))
result.operationName = (String)tokenList.get(count -1);
return result;
| private void | swapNameType(java.util.Properties props, java.lang.String newType, java.lang.String newName)Apply a transform to specified properties. The transform is to extract
properties "name" and "type" and put the value of type as key and
value of name as correponding value and then replacing values of "name"
and "type" by specified new values (newName and newType).
String oldType = props.getProperty(ObjectNames.kMonitoringClassName);
String oldName = props.getProperty(ObjectNames.kNameKeyName);
props.put(ObjectNames.kMonitoringClassName, newType);
props.put(ObjectNames.kNameKeyName, newName);
props.put(oldType, oldName);
|
|