下面列出了javax.management.MBeanOperationInfo#INFO 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private boolean isOperationReadOnly(ObjectName name, String operationName, String[] signature) {
MBeanInfo info;
try {
info = getMBeanInfo(name, false, true);
} catch (Exception e) {
//This should not happen, just in case say it is not RO
return false;
}
if (info == null) {
//Default to not RO
return false;
}
for (MBeanOperationInfo op : info.getOperations()) {
if (op.getName().equals(operationName)) {
MBeanParameterInfo[] params = op.getSignature();
if (params.length != signature.length) {
continue;
}
boolean same = true;
for (int i = 0 ; i < params.length ; i++) {
if (!params[i].getType().equals(signature[i])) {
same = false;
break;
}
}
if (same) {
return op.getImpact() == MBeanOperationInfo.INFO;
}
}
}
//Default to not RO
return false;
}
/**
* Initialize the open mbean metadata
*/
private void initOpenMBeanInfo() {
OpenMBeanAttributeInfoSupport[] attributes = new OpenMBeanAttributeInfoSupport[4];
OpenMBeanConstructorInfoSupport[] constructors = new OpenMBeanConstructorInfoSupport[1];
OpenMBeanOperationInfoSupport[] operations = new OpenMBeanOperationInfoSupport[2];
MBeanNotificationInfo[] notifications = new MBeanNotificationInfo[0];
try {
// Define the attributes
attributes[0] = new OpenMBeanAttributeInfoSupport(ATTR_ID,
"Knowledge Base Id",
SimpleType.STRING,
true,
false,
false);
attributes[1] = new OpenMBeanAttributeInfoSupport(ATTR_SESSION_COUNT,
"Number of created sessions for this Knowledge Base",
SimpleType.LONG,
true,
false,
false);
attributes[2] = new OpenMBeanAttributeInfoSupport(ATTR_GLOBALS,
"List of globals",
globalsTableType,
true,
false,
false );
attributes[3] = new OpenMBeanAttributeInfoSupport( ATTR_PACKAGES,
"List of Packages",
new ArrayType( 1,
SimpleType.STRING ),
true,
false,
false );
//No arg constructor
constructors[0] = new OpenMBeanConstructorInfoSupport( "KnowledgeBaseMonitoringMXBean",
"Constructs a KnowledgeBaseMonitoringMXBean instance.",
new OpenMBeanParameterInfoSupport[0] );
//Operations
OpenMBeanParameterInfo[] params = new OpenMBeanParameterInfoSupport[0];
operations[0] = new OpenMBeanOperationInfoSupport( OP_START_INTERNAL_MBEANS,
"Creates, registers and starts all the dependent MBeans that allow monitor all the details in this KnowledgeBase.",
params,
SimpleType.VOID,
MBeanOperationInfo.INFO );
operations[1] = new OpenMBeanOperationInfoSupport( OP_STOP_INTERNAL_MBEANS,
"Stops and disposes all the dependent MBeans that allow monitor all the details in this KnowledgeBase.",
params,
SimpleType.VOID,
MBeanOperationInfo.INFO );
//Build the info
info = new OpenMBeanInfoSupport( this.getClass().getName(),
"Knowledge Base Monitor MXBean",
attributes,
constructors,
operations,
notifications );
} catch ( Exception e ) {
e.printStackTrace();
}
}
@Override
public LineRenderer renderer(Iterator<MBeanInfo> stream) {
List<LineRenderer> renderers = new ArrayList<LineRenderer>();
while (stream.hasNext()) {
MBeanInfo info = stream.next();
//
TreeElement root = new TreeElement(info.getClassName());
// Descriptor
TableElement descriptor = new TableElement().
overflow(Overflow.HIDDEN).
rightCellPadding(1);
Descriptor descriptorInfo = info.getDescriptor();
if (descriptorInfo != null) {
for (String fieldName : descriptorInfo.getFieldNames()) {
String fieldValue = String.valueOf(descriptorInfo.getFieldValue(fieldName));
descriptor.row(fieldName, fieldValue);
}
}
// Attributes
TableElement attributes = new TableElement().
overflow(Overflow.HIDDEN).
rightCellPadding(1).
add(new RowElement().style(Decoration.bold.fg(Color.black).bg(Color.white)).add("NAME", "TYPE", "DESCRIPTION"));
for (MBeanAttributeInfo attributeInfo : info.getAttributes()) {
attributes.row(attributeInfo.getName(), attributeInfo.getType(), attributeInfo.getDescription());
}
// Operations
TreeElement operations = new TreeElement("Operations");
for (MBeanOperationInfo operationInfo : info.getOperations()) {
TableElement signature = new TableElement().
overflow(Overflow.HIDDEN).
rightCellPadding(1);
MBeanParameterInfo[] parameterInfos = operationInfo.getSignature();
for (MBeanParameterInfo parameterInfo : parameterInfos) {
signature.row(parameterInfo.getName(), parameterInfo.getType(), parameterInfo.getDescription());
}
TreeElement operation = new TreeElement(operationInfo.getName());
String impact;
switch (operationInfo.getImpact()) {
case MBeanOperationInfo.ACTION:
impact = "ACTION";
break;
case MBeanOperationInfo.INFO:
impact = "INFO";
break;
case MBeanOperationInfo.ACTION_INFO:
impact = "ACTION_INFO";
break;
default:
impact = "UNKNOWN";
}
operation.addChild(new TableElement().
add(
new RowElement().add("Type: ", operationInfo.getReturnType()),
new RowElement().add("Description: ", operationInfo.getDescription()),
new RowElement().add("Impact: ", impact),
new RowElement().add(new LabelElement("Signature: "), signature)
)
);
operations.addChild(operation);
}
//
root.addChild(
new TableElement().leftCellPadding(1).overflow(Overflow.HIDDEN).
row("ClassName", info.getClassName()).
row("Description", info.getDescription()
)
);
root.addChild(new TreeElement("Descriptor").addChild(descriptor));
root.addChild(new TreeElement("Attributes").addChild(attributes));
root.addChild(operations);
//
renderers.add(root.renderer());
}
return LineRenderer.vertical(renderers);
}
@Operation(desc = "Returns the number of the messages in the queue", impact = MBeanOperationInfo.INFO)
long countMessages() throws Exception;
/**
* Closes the consumer with the given id.
*/
@Operation(desc = "Closes the consumer with the id", impact = MBeanOperationInfo.INFO)
boolean closeConsumerWithID(@Parameter(desc = "The session ID", name = "sessionID") String sessionID,
@Parameter(desc = "The consumer ID", name = "ID") String ID) throws Exception;
@Operation(desc = "Search for Addresses", impact = MBeanOperationInfo.INFO)
String listAddresses(@Parameter(name = "options", desc = "Options") String options,
@Parameter(name = "pageNumber", desc = "Page Number") int page,
@Parameter(name = "pageSize", desc = "Page Size") int pageSize) throws Exception;
@Operation(desc = "Get a list of bindings associated with an address", impact = MBeanOperationInfo.INFO)
String listBindingsForAddress(@Parameter(name = "address", desc = "The address") String address) throws Exception;
@Operation(desc = "Search for Consumers", impact = MBeanOperationInfo.INFO)
String listConsumers(@Parameter(name = "options", desc = "Options") String options,
@Parameter(name = "pageNumber", desc = "Page Number") int page,
@Parameter(name = "pageSize", desc = "Page Size") int pageSize) throws Exception;
@Operation(desc = "Get roles for a specific address match", impact = MBeanOperationInfo.INFO)
Object[] getRoles(@Parameter(desc = "an address match", name = "addressMatch") String addressMatch) throws Exception;
@Operation(desc = "Get roles (as a JSON string) for a specific address match", impact = MBeanOperationInfo.INFO)
String getRolesAsJSON(@Parameter(desc = "an address match", name = "addressMatch") String addressMatch) throws Exception;
/**
* Jon plugin doesn't recognize an Operation whose name is in
* form getXXXX(), so add this one.
*/
@Operation(desc = "names of the diverts deployed on this server", impact = MBeanOperationInfo.INFO)
default String[] listDivertNames() {
return getDivertNames();
}
/**
* Lists the addresses of all the clients connected to this address.
*/
@Operation(desc = "List the client addresses", impact = MBeanOperationInfo.INFO)
String[] listRemoteAddresses() throws Exception;
/**
* Lists the addresses of the clients connected to this address which matches the specified IP address.
*/
@Operation(desc = "List the client addresses which match the given IP Address", impact = MBeanOperationInfo.INFO)
String[] listRemoteAddresses(@Parameter(desc = "an IP address", name = "ipAddress") String ipAddress) throws Exception;
/**
* Returns the names of the cluster-connections deployed on this server.
*/
@Operation(desc = "Names of the cluster-connections deployed on this server", impact = MBeanOperationInfo.INFO)
String[] getClusterConnectionNames();
/**
* Closes all the connections of clients connected to this server which matches the specified IP address.
*/
@Operation(desc = "Closes all the consumer connections for the given messaging address", impact = MBeanOperationInfo.INFO)
boolean closeConsumerConnectionsForAddress(@Parameter(desc = "a messaging address", name = "address") String address) throws Exception;
/**
* Lists the message counter for this queue as a HTML table.
*/
@Operation(desc = "List the message counters as HTML", impact = MBeanOperationInfo.INFO)
String listMessageCounterAsHTML() throws Exception;
/**
* Lists the message counter for this queue.
*/
@Operation(desc = "List the message counters", impact = MBeanOperationInfo.INFO)
String listMessageCounter() throws Exception;
/**
* Returns the operations impact, which is {@code INFO}.
*
* @return {@code INFO}.
*/
@Override
protected int getImpact(final MBeanOperationInfo info) {
return MBeanOperationInfo.INFO;
}
/**
* Lists details about all sessions.
* The returned String is a JSON string containing details about each and every session, e.g.:
* <pre>
* [
* {
* "sessionID":"e71d61d7-2176-11e8-9057-a0afbd82eaba",
* "creationTime":1520365520212,
* "consumerCount":1,
* "principal":"myUser"
* },
* {
* "sessionID":"e718a6e6-2176-11e8-9057-a0afbd82eaba",
* "creationTime":1520365520191,
* "consumerCount":0,
* "principal":"guest"
* }
* ]
* </pre>
*/
@Operation(desc = "List all sessions as a JSON string", impact = MBeanOperationInfo.INFO)
String listAllSessionsAsJSON() throws Exception;
/**
* Counts the number of messages in this queue matching the specified filter, grouped by the given property field.
* In case of null property will be grouped in "null"
* <br>
* Using {@code null} or an empty filter will count <em>all</em> messages from this queue.
*/
@Operation(desc = "Returns the number of the messages in the queue matching the given filter, grouped by the given property field", impact = MBeanOperationInfo.INFO)
String countMessages(@Parameter(name = "filter", desc = "This filter separate account messages") String filter, @Parameter(name = "groupByProperty", desc = "This property to group by") String groupByProperty) throws Exception;