The role of ObjectName this class in Tomcat source code

Source: Internet
Author: User
Tags comments list of attributes valid tomcat

When we study the Tomcat source, we will find that there are many classes in the Tomcat code used in the ObjectName class to construct an object, because the Tomcat source code objectname This class comments are in English, now the comments of this class is translated into Chinese. This class, in a nutshell, stores a number of attributes in a domain, where the storage of attributes is stored in a key-value way, and one of the best things about this class is that Domian and attributes (key or value) support regular, such as: * means matching all,. Represents a match for one character.

one, objectname annotation translation

ObjectName represents an Mbean object name, or a regular that can match several mbean, and all instances of ObjectName are immutable.

That is, an instance of the ObjectName class can be used to represent an object name, or a regular object, which can be queried by a regular context.

The objectname consists of two parts, including domain and attribute (properties). A field is a string that does not contain a colon, and we also recommend that a domain should not contain "//" because the two characters are reserved for future use. If a wildcard character (* number) or a question mark is present in the field (. ), then the ObjectName object is a regular object. The wildcard character (*) matches 0 or more arbitrary sequences, while the question mark (. ) refers to matching one character.

If the domain is empty, then the domain of the ObjectName object is replaced with the default domain of the Mbean in some environments, so that the objectname can be used by the Mbean.

ObjectName the properties of an object when an unordered keys and values, a key corresponds to a values. Each key is a non-empty string that does not contain commas, equals, colons, asterisks, and question marks, and the same key does not appear in the same ObjectName object. The value associated with key, which is either without quotation marks or with quotation marks. A value without quotation marks may be an empty string that does not contain a comma, an equal sign, a colon, or a quotation mark. If the value without quotation marks contains a wildcard * number or a question mark, then the objectname is a regular value. The wildcard * Number matches 0 or more character sequences, and the question mark matches one character. The value with quotation marks consists of double quotation marks, which can be either an empty string or another double quotation mark. In this string, the backslash has a special meaning. The backslash must be followed by the character below:

"1" If it is followed by another backslash, the second backslash has no special meaning, so these two backslashes represent a backslash, because the first backslash is an escape character.

"2" If it is followed by a character ' n ', then these two characters represent a line break, meaning "/n" in Java

"3" if a double quotation mark is followed, the two characters represent a double quote, noting that the double quotation mark does not represent the end of the previous double quotation mark. A closed double quotation mark must represent a valid double-quote value.

"4" If it is followed by a question mark or wildcard (*), then the two characters here simply represent a question mark and an asterisk, which is no longer a regular matching symbol.

A quotation mark can only appear behind an odd number of backslashes, otherwise there is no double quotation mark in the value of a quotation mark. Double quotation marks enclose the value with double quotation marks, and any backslash in this value is considered to be the partition of this value.

If a value with double quotation marks contains a wildcard character (*) or a question mark, and the two symbols are not preprocessed by backslashes, then they are considered a wildcard character. An asterisk matches 0 or more string sequences, and the question mark matches a string.

A ObjectName object may be a property list match. In this case, objectname may not have or have multiple keys and associated values. This objectname can match an ObjectName object with no regular, no regular objectname fields with regular objectname fields, and they contain the same keys and associated values, They may also contain the same other keys and values.

When a ObjectName object contains a double quotation mark, or if there is no quotation mark containing the wildcard character described above, then this objectname is considered to be a pattern matching object for a list of attributes. In this case, the objectname contains one or more keys and associated values, with at least one value containing the wildcard character. He matches a ObjectName object with no pattern matching, because the two objectname fields match, and they contain the same keys that the values match, and if this property value pattern match is a property list match, A non-pattern-matching object can also contain other keys and values.

When the key of an object is a pattern match, or if a value is a pattern match, or if both key and value are pattern matches, then the object is a property pattern match.

If a ObjectName object's field contains a wildcard character, the ObjectName object is a pattern match. If a objectname is not a pattern-matching object, it must contain at least one key and the value associated with the key.

Examples of objectname pattern matching:

"1" *:type=foo,name=bar

Matches a collection of keys under any domain. Keys are: Type=foo,name=bar

"2" d:type=foo,name=bar,*

The match field "D" has the Keys "Type=foo,name=bar" plus 0 or more keys.

"3" *:type=foo,name=bar,*

Match any of the fields with the keys "Type=foo,name=bar" plus 0 or more keys.

"4" D:type=f?o,name=bar

Consistent with "D:type=foo,name=bar" and "D:type=fro,name=bar" matches

"5" D:type=f*o,name=bar

Consistent with "D:type=fo,name=bar" and "D:type=frodo,name=bar" matches

"6" d:type=foo,name= "b*"

Consistent with D:type=foo,name= "Bling", wildcards are enclosed in quotation marks, and we can use a backslash "/" to convert a special character to a normal character.

A objectname can be written in the following format: Domain: Key property list. A list of key attributes can be written as a comma-separated string. Each comma-delimited string is either a wildcard character or a deterministic key value. A key property value consists of a key, an equal sign, and the associated value.

Most key attribute lists are wildcard characters, and if the key attribute list contains wildcards, then this objectname is a wildcard attribute. In a ObjectName object, spaces have no special meaning. such as the following string:

Domain:key1 = value1, Key2 = value2

The above string represents an object that consists of two keys. Each key consists of 6 characters, each of which starts with a space and ends with a space. In addition to the restrictions on the characters indicated above, no part of a objectname contains the newline character "/n", including: field, key, value, reference, or no quotation marks. But the newline character "/n" can appear inside a double-quote sequence. Regardless of which constructor we use to construct the ObjectName object, the above rules for special characters are applicable.

In order to avoid conflicts between different Mbean written by different people, a valid convention is that the name of the domain uses the reverse notation of the organization's DNS. For example: Sun Microsystems Inc's DNS name is sun.com, so I can define the domain as Com.sun.MyDomain, which is basically the same as the Java language's package name definition conventions.


second, the test of objectname

 

Package Org.apache.catalina.manager;

Import javax.management.MalformedObjectNameException;
Import Javax.management.ObjectName;

/**
* Test ObjectName Object
*
* @author Rey
*
*/
public class MyTest {

/**
* @param args
* @throws NullPointerException
* @throws malformedobjectnameexception
*/
public static void Main (string[] args) throws Malformedobjectnameexception,
NullPointerException {
String sanothername = "D:type=f*o,name=bar";
ObjectName currobjectname = new ObjectName (sanothername);
System.out.println (Currobjectname.tostring ());
}

}


Output Result: D:type=f*o,name=bar


Third, objectname source code can be viewed from the JDK

The package path is:javax.management.ObjectName


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.