release version 1.10.0

This commit is contained in:
2024-10-07 18:42:55 +03:00
parent 2034182607
commit a5088587f7
1501 changed files with 28818 additions and 59966 deletions

View File

@ -3,7 +3,7 @@
<parent>
<groupId>ru.entaxy.esb.platform.runtime</groupId>
<artifactId>base</artifactId>
<version>1.9.0</version>
<version>1.10.0</version>
</parent>
<groupId>ru.entaxy.esb.platform.runtime.base</groupId>
<artifactId>management-core</artifactId>

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* management-core
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* Copyright (C) 2020 - 2024 EmDev LLC
* ==========
* You may not use this file except in accordance with the License Terms of the Copyright
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* management-core
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* Copyright (C) 2020 - 2024 EmDev LLC
* ==========
* You may not use this file except in accordance with the License Terms of the Copyright
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* management-core
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* Copyright (C) 2020 - 2024 EmDev LLC
* ==========
* You may not use this file except in accordance with the License Terms of the Copyright
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* management-core
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* Copyright (C) 2020 - 2024 EmDev LLC
* ==========
* You may not use this file except in accordance with the License Terms of the Copyright
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* management-core
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* Copyright (C) 2020 - 2024 EmDev LLC
* ==========
* You may not use this file except in accordance with the License Terms of the Copyright
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* management-core
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* Copyright (C) 2020 - 2024 EmDev LLC
* ==========
* You may not use this file except in accordance with the License Terms of the Copyright
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* management-core
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* Copyright (C) 2020 - 2024 EmDev LLC
* ==========
* You may not use this file except in accordance with the License Terms of the Copyright
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* management-core
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* Copyright (C) 2020 - 2024 EmDev LLC
* ==========
* You may not use this file except in accordance with the License Terms of the Copyright
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* management-core
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* Copyright (C) 2020 - 2024 EmDev LLC
* ==========
* You may not use this file except in accordance with the License Terms of the Copyright
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* management-core
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* Copyright (C) 2020 - 2024 EmDev LLC
* ==========
* You may not use this file except in accordance with the License Terms of the Copyright
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* management-core
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* Copyright (C) 2020 - 2024 EmDev LLC
* ==========
* You may not use this file except in accordance with the License Terms of the Copyright
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* profile-management
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* Copyright (C) 2020 - 2024 EmDev LLC
* ==========
* You may not use this file except in accordance with the License Terms of the Copyright
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* profile-management
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* Copyright (C) 2020 - 2024 EmDev LLC
* ==========
* You may not use this file except in accordance with the License Terms of the Copyright
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
@ -25,12 +25,23 @@
*/
package ru.entaxy.esb.platform.base.management.core.utils;
import javax.management.MBeanOperationInfo;
import ru.entaxy.esb.platform.base.management.core.api.Attribute;
import ru.entaxy.esb.platform.base.management.core.api.Operation;
public interface BundleAwareMBean {
public void refreshBundleInfo();
public String getBundleState();
public long getBundleId();
public String getBundleSymbolicName();
@Operation(desc = "Refresh bundle info", impact = MBeanOperationInfo.INFO)
public void refreshBundleInfo();
@Attribute(desc = "Bundle state")
public String getBundleState();
@Attribute(desc = "Bundle Id")
public long getBundleId();
@Attribute(desc = "Bundle symbolic name")
public String getBundleSymbolicName();
}

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* profile-management
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* Copyright (C) 2020 - 2024 EmDev LLC
* ==========
* You may not use this file except in accordance with the License Terms of the Copyright
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
@ -43,110 +43,121 @@ import org.osgi.framework.FrameworkUtil;
import ru.entaxy.esb.platform.base.management.core.api.AnnotatedMBean;
import ru.entaxy.platform.base.support.osgi.tracker.BundleContextAware;
public class BundleAwareMBeanImpl<T extends BundleAwareManagedObject, I>
extends AnnotatedMBean<I> implements NotificationBroadcaster, NotificationEmitter, BundleAwareMBean, BundleContextAware {
public class BundleAwareMBeanImpl<T extends BundleAwareManagedObject, I>
extends AnnotatedMBean<I>
implements NotificationBroadcaster, NotificationEmitter, BundleAwareMBean, BundleContextAware {
protected T managedObject;
protected T managedObject;
protected BundleContext bundleContext;
protected long sequenceNumber = 0;
protected NotificationBroadcasterSupport emitter;
public BundleAwareMBeanImpl(Class<I> clazz, T managedObject) throws NotCompliantMBeanException {
super(clazz);
this.managedObject = managedObject;
this.emitter = new NotificationBroadcasterSupport(prepareNotificationInfo());
}
// BEGIN: notification stuff
protected MBeanNotificationInfo[] prepareNotificationInfo() {
String[] types = new String[] {
AttributeChangeNotification.ATTRIBUTE_CHANGE
};
String name = AttributeChangeNotification.class.getName();
String description = "An attribute of this MBean has changed";
MBeanNotificationInfo info =
new MBeanNotificationInfo(types, name, description);
return new MBeanNotificationInfo[] {info};
}
@Override
public void removeNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)
throws ListenerNotFoundException {
this.emitter.removeNotificationListener(listener, filter, handback);
}
protected BundleContext bundleContext;
@Override
public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)
throws IllegalArgumentException {
this.emitter.addNotificationListener(listener, filter, handback);
}
protected long sequenceNumber = 0;
@Override
public void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException {
this.emitter.removeNotificationListener(listener);
}
protected NotificationBroadcasterSupport emitter;
@Override
public MBeanNotificationInfo[] getNotificationInfo() {
return this.emitter==null
?prepareNotificationInfo()
:emitter.getNotificationInfo();
}
// END: notification stuff
@Override
public String getBundleState() {
return managedObject.getBundleState();
}
public BundleAwareMBeanImpl(Class<I> clazz, T managedObject) throws NotCompliantMBeanException {
super(clazz);
this.managedObject = managedObject;
this.emitter = new NotificationBroadcasterSupport(prepareNotificationInfo());
}
@Override
public long getBundleId() {
return managedObject.getBundleId();
}
// BEGIN: notification stuff
@Override
public String getBundleSymbolicName() {
return managedObject.getBundleSymbolicName();
}
@Override
public BundleContext getBundleContext() {
return bundleContext;
}
protected MBeanNotificationInfo[] prepareNotificationInfo() {
String[] types = new String[] {
AttributeChangeNotification.ATTRIBUTE_CHANGE
};
String name = AttributeChangeNotification.class.getName();
String description = "An attribute of this MBean has changed";
MBeanNotificationInfo info =
new MBeanNotificationInfo(types, name, description);
return new MBeanNotificationInfo[] {info};
}
@Override
public void setBundleContext(BundleContext bundleContext) {
this.bundleContext = bundleContext;
}
@Override
public void removeNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)
throws ListenerNotFoundException {
this.emitter.removeNotificationListener(listener, filter, handback);
}
@Override
public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)
throws IllegalArgumentException {
this.emitter.addNotificationListener(listener, filter, handback);
}
@Override
public void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException {
this.emitter.removeNotificationListener(listener);
}
@Override
public MBeanNotificationInfo[] getNotificationInfo() {
return this.emitter == null
? prepareNotificationInfo()
: emitter.getNotificationInfo();
}
// END: notification stuff
@Override
public String getBundleState() {
return managedObject.getBundleState();
}
@Override
public long getBundleId() {
return managedObject.getBundleId();
}
@Override
public String getBundleSymbolicName() {
return managedObject.getBundleSymbolicName();
}
@Override
public BundleContext getBundleContext() {
return bundleContext;
}
@Override
public void setBundleContext(BundleContext bundleContext) {
this.bundleContext = bundleContext;
}
@Override
public void refreshBundleInfo() {
// track bundleState
AttributeChangeTracker tracker = refreshBundleState();
if (tracker.isChanged()) {
// send notification
Notification n = new AttributeChangeNotification(
this,
this.sequenceNumber++,
System.currentTimeMillis(),
"bundleState changed",
"bundleState",
"String",
tracker.oldValue,
tracker.newValue);
this.emitter.sendNotification(n);
}
}
protected AttributeChangeTracker refreshBundleState() {
Bundle b = FrameworkUtil.getBundle(getClass()).getBundleContext().getBundle(getBundleId());
AttributeChangeTracker tracker = new AttributeChangeTracker();
tracker.oldValue(this.managedObject.getBundleState());
this.managedObject.bundleState(b != null ? b.getState() : Bundle.UNINSTALLED);
tracker.newValue(this.managedObject.getBundleState());
return tracker;
}
@Override
public void refreshBundleInfo() {
Bundle b = FrameworkUtil.getBundle(getClass()).getBundleContext().getBundle(getBundleId());
// track bundleState
AttributeChangeTracker tracker = new AttributeChangeTracker();
tracker.oldValue(this.managedObject.getBundleState());
this.managedObject.bundleState(b.getState());
if (tracker.newValue(this.managedObject.getBundleState()).isChanged()) {
// send notification
Notification n = new AttributeChangeNotification(
this,
this.sequenceNumber++,
System.currentTimeMillis(),
"bundleState changed",
"bundleState",
"String",
tracker.oldValue,
tracker.newValue);
this.emitter.sendNotification(n);
}
}
}

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* profile-management
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* Copyright (C) 2020 - 2024 EmDev LLC
* ==========
* You may not use this file except in accordance with the License Terms of the Copyright
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* profile-management
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* Copyright (C) 2020 - 2024 EmDev LLC
* ==========
* You may not use this file except in accordance with the License Terms of the Copyright
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* profile-management
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* Copyright (C) 2020 - 2024 EmDev LLC
* ==========
* You may not use this file except in accordance with the License Terms of the Copyright
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* management-core
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* Copyright (C) 2020 - 2024 EmDev LLC
* ==========
* You may not use this file except in accordance with the License Terms of the Copyright
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
@ -24,23 +24,26 @@
* ~~~~~~/licensing~~~~~~
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package ru.entaxy.esb.platform.base.management.core.utils;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanParameterInfo;
@ -51,200 +54,218 @@ import ru.entaxy.esb.platform.base.management.core.api.NotExported;
import ru.entaxy.esb.platform.base.management.core.api.Operation;
import ru.entaxy.esb.platform.base.management.core.api.Parameter;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
public class MBeanInfoHelper {
// Constants -----------------------------------------------------
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
// Public --------------------------------------------------------
public static MBeanOperationInfo[] getMBeanOperationsInfo(final Class mbeanInterface, MBeanExportPolicy policy) {
List<MBeanOperationInfo> operations = new ArrayList<>();
public static MBeanOperationInfo[] getMBeanOperationsInfo(final Class mbeanInterface, MBeanExportPolicy policy) {
List<MBeanOperationInfo> operations = new ArrayList<>();
for (Method method : mbeanInterface.getMethods()) {
if (!MBeanInfoHelper.isGetterMethod(method) && !MBeanInfoHelper.isSetterMethod(method) &&
!MBeanInfoHelper.isIsBooleanMethod(method)) {
MBeanOperationInfo info = MBeanInfoHelper.getOperationInfo(method, policy);
if (info != null)
operations.add(info);
}
}
return operations.toArray(new MBeanOperationInfo[operations.size()]);
}
public static MBeanAttributeInfo[] getMBeanAttributesInfo(final Class mbeanInterface, MBeanExportPolicy policy) {
List<MBeanAttributeInfo> tempAttributes = new ArrayList<>();
List<MBeanAttributeInfo> finalAttributes = new ArrayList<>();
List<String> alreadyAdded = new ArrayList<>();
for (Method method : mbeanInterface.getMethods()) {
if (MBeanInfoHelper.isGetterMethod(method) || MBeanInfoHelper.isSetterMethod(method) ||
MBeanInfoHelper.isIsBooleanMethod(method)) {
MBeanAttributeInfo info = MBeanInfoHelper.getAttributeInfo(method, policy);
if (info != null)
tempAttributes.add(info);
}
}
// since getters and setters will each have an MBeanAttributeInfo we need to de-duplicate
for (MBeanAttributeInfo info1 : tempAttributes) {
MBeanAttributeInfo infoToCopy = info1;
for (MBeanAttributeInfo info2 : tempAttributes) {
if (info1.getName().equals(info2.getName()) && !info1.equals(info2)) {
infoToCopy = new MBeanAttributeInfo(info1.getName(), info1.getType().equals("void") ? info2.getType() : info1.getType(), info1.getDescription(), (info1.isReadable() || info2.isReadable()), (info1.isWritable() || info2.isWritable()), (info1.isIs() || info2.isIs()));
for (Method method : mbeanInterface.getMethods()) {
if (!MBeanInfoHelper.isGetterMethod(method) && !MBeanInfoHelper.isSetterMethod(method) &&
!MBeanInfoHelper.isIsBooleanMethod(method)) {
MBeanOperationInfo info = MBeanInfoHelper.getOperationInfo(method, policy);
if (info != null)
operations.add(info);
} else {
// check for explicitly defined operations with @Operation annotation
if (isExplicitOperation(method, policy)) {
MBeanOperationInfo info = MBeanInfoHelper.getOperationInfo(method, policy);
if (info != null)
operations.add(info);
}
}
}
if (!alreadyAdded.contains(infoToCopy.getName())) {
finalAttributes.add(infoToCopy);
alreadyAdded.add(infoToCopy.getName());
}
}
}
return finalAttributes.toArray(new MBeanAttributeInfo[finalAttributes.size()]);
}
return operations.toArray(new MBeanOperationInfo[operations.size()]);
}
// Package protected ---------------------------------------------
protected static boolean isExplicitOperation(Method method, MBeanExportPolicy policy) {
if (!method.isAnnotationPresent(Operation.class))
return false;
if (method.isAnnotationPresent(NotExported.class))
return false;
return MBeanExportPolicy.ANNOTATED_ONLY.equals(policy) || MBeanExportPolicy.ANNOTATION_ENRICH.equals(policy);
// Protected -----------------------------------------------------
}
// Private -------------------------------------------------------
public static MBeanAttributeInfo[] getMBeanAttributesInfo(final Class mbeanInterface, MBeanExportPolicy policy) {
List<MBeanAttributeInfo> tempAttributes = new ArrayList<>();
List<MBeanAttributeInfo> finalAttributes = new ArrayList<>();
List<String> alreadyAdded = new ArrayList<>();
private static boolean isGetterMethod(final Method method) {
if (!method.getName().equals("get") && method.getName().startsWith("get") &&
method.getParameterTypes().length == 0 &&
!method.getReturnType().equals(void.class)) {
return true;
}
return false;
}
private static boolean isSetterMethod(final Method method) {
if (!method.getName().equals("set") && method.getName().startsWith("set") &&
method.getParameterTypes().length == 1 &&
method.getReturnType().equals(void.class)) {
return true;
} else {
return false;
}
}
private static boolean isIsBooleanMethod(final Method method) {
if (!method.getName().equals("is") && method.getName().startsWith("is") &&
method.getParameterTypes().length == 0 &&
method.getReturnType().equals(boolean.class)) {
return true;
} else {
return false;
}
}
private static MBeanOperationInfo getOperationInfo(final Method operation, MBeanExportPolicy policy) {
MBeanOperationInfo info = null;
Class<?> returnType = operation.getReturnType();
MBeanParameterInfo[] paramsInfo = MBeanInfoHelper.getParametersInfo(operation.getParameterAnnotations(), operation.getParameterTypes());
String description = operation.getName();
int impact = MBeanOperationInfo.UNKNOWN;
if (!MBeanExportPolicy.IGNORE_ANNOTATIONS.equals(policy)) {
// ANNOTATED_ONLY, EXCEPT_HIDDEN, ANNOTATION_ENRICH
NotExported annoNotExported = operation.getAnnotation(NotExported.class);
if (annoNotExported != null) {
// method is hidden from exporting
return null;
}
Operation annoOperation = operation.getAnnotation(Operation.class);
if (MBeanExportPolicy.ANNOTATED_ONLY.equals(policy) && (annoOperation==null)){
// method is not annotated
return null;
}
if (annoOperation != null) {
description = annoOperation.desc();
impact = annoOperation.impact();
}
}
info = new MBeanOperationInfo(operation.getName(), description, paramsInfo, returnType.getName(), impact);
return info;
}
private static MBeanAttributeInfo getAttributeInfo(final Method operation, MBeanExportPolicy policy) {
String description = "N/A";
if (!MBeanExportPolicy.IGNORE_ANNOTATIONS.equals(policy)) {
// ANNOTATED_ONLY, EXCEPT_HIDDEN, ANNOTATION_ENRICH
NotExported annoNotExported = operation.getAnnotation(NotExported.class);
if (annoNotExported != null) {
// method is hidden from exporting
return null;
}
Attribute annoAttribute = operation.getAnnotation(Attribute.class);
if (MBeanExportPolicy.ANNOTATED_ONLY.equals(policy) && (annoAttribute==null)){
// method is not annotated
return null;
}
if (annoAttribute != null) {
description = operation.getAnnotation(Attribute.class).desc();
}
}
MBeanAttributeInfo info = new MBeanAttributeInfo(getAttributeName(operation), operation.getReturnType().getName(), description, (isGetterMethod(operation) || isIsBooleanMethod(operation)), isSetterMethod(operation), isIsBooleanMethod(operation));
return info;
}
private static String getAttributeName(Method operation) {
String name = operation.getName();
if (isGetterMethod(operation) || isSetterMethod(operation))
name = operation.getName().substring(3);
else if (isIsBooleanMethod(operation))
name = operation.getName().substring(2);
return name;
}
private static MBeanParameterInfo[] getParametersInfo(final Annotation[][] params, final Class<?>[] paramTypes) {
MBeanParameterInfo[] paramsInfo = new MBeanParameterInfo[params.length];
for (int i = 0; i < params.length; i++) {
MBeanParameterInfo paramInfo = null;
String type = paramTypes[i].getName();
for (Annotation anno : params[i]) {
if (Parameter.class.isInstance(anno)) {
String name = Parameter.class.cast(anno).name();
String description = Parameter.class.cast(anno).desc();
paramInfo = new MBeanParameterInfo(name, type, description);
for (Method method : mbeanInterface.getMethods()) {
if (MBeanInfoHelper.isGetterMethod(method) || MBeanInfoHelper.isSetterMethod(method) ||
MBeanInfoHelper.isIsBooleanMethod(method)) {
MBeanAttributeInfo info = MBeanInfoHelper.getAttributeInfo(method, policy);
if (info != null)
tempAttributes.add(info);
}
}
}
if (paramInfo == null) {
paramInfo = new MBeanParameterInfo("p " + (i + 1), type, "parameter " + (i + 1));
}
// since getters and setters will each have an MBeanAttributeInfo we need to de-duplicate
for (MBeanAttributeInfo info1 : tempAttributes) {
MBeanAttributeInfo infoToCopy = info1;
for (MBeanAttributeInfo info2 : tempAttributes) {
if (info1.getName().equals(info2.getName()) && !info1.equals(info2)) {
infoToCopy = new MBeanAttributeInfo(info1.getName(),
info1.getType().equals("void") ? info2.getType() : info1.getType(), info1.getDescription(),
(info1.isReadable() || info2.isReadable()), (info1.isWritable() || info2.isWritable()),
(info1.isIs() || info2.isIs()));
}
}
if (!alreadyAdded.contains(infoToCopy.getName())) {
finalAttributes.add(infoToCopy);
alreadyAdded.add(infoToCopy.getName());
}
}
paramsInfo[i] = paramInfo;
}
return finalAttributes.toArray(new MBeanAttributeInfo[finalAttributes.size()]);
}
return paramsInfo;
}
// Package protected ---------------------------------------------
// Inner classes -------------------------------------------------
// Protected -----------------------------------------------------
// Private -------------------------------------------------------
private static boolean isGetterMethod(final Method method) {
if (!method.getName().equals("get") && method.getName().startsWith("get") &&
method.getParameterTypes().length == 0 &&
!method.getReturnType().equals(void.class)) {
return true;
}
return false;
}
private static boolean isSetterMethod(final Method method) {
if (!method.getName().equals("set") && method.getName().startsWith("set") &&
method.getParameterTypes().length == 1 &&
method.getReturnType().equals(void.class)) {
return true;
} else {
return false;
}
}
private static boolean isIsBooleanMethod(final Method method) {
if (!method.getName().equals("is") && method.getName().startsWith("is") &&
method.getParameterTypes().length == 0 &&
method.getReturnType().equals(boolean.class)) {
return true;
} else {
return false;
}
}
private static MBeanOperationInfo getOperationInfo(final Method operation, MBeanExportPolicy policy) {
MBeanOperationInfo info = null;
Class<?> returnType = operation.getReturnType();
MBeanParameterInfo[] paramsInfo =
MBeanInfoHelper.getParametersInfo(operation.getParameterAnnotations(), operation.getParameterTypes());
String description = operation.getName();
int impact = MBeanOperationInfo.UNKNOWN;
if (!MBeanExportPolicy.IGNORE_ANNOTATIONS.equals(policy)) {
// ANNOTATED_ONLY, EXCEPT_HIDDEN, ANNOTATION_ENRICH
NotExported annoNotExported = operation.getAnnotation(NotExported.class);
if (annoNotExported != null) {
// method is hidden from exporting
return null;
}
Operation annoOperation = operation.getAnnotation(Operation.class);
if (MBeanExportPolicy.ANNOTATED_ONLY.equals(policy) && (annoOperation == null)) {
// method is not annotated
return null;
}
if (annoOperation != null) {
description = annoOperation.desc();
impact = annoOperation.impact();
}
}
info = new MBeanOperationInfo(operation.getName(), description, paramsInfo, returnType.getName(), impact);
return info;
}
private static MBeanAttributeInfo getAttributeInfo(final Method operation, MBeanExportPolicy policy) {
String description = "N/A";
if (!MBeanExportPolicy.IGNORE_ANNOTATIONS.equals(policy)) {
// ANNOTATED_ONLY, EXCEPT_HIDDEN, ANNOTATION_ENRICH
NotExported annoNotExported = operation.getAnnotation(NotExported.class);
if (annoNotExported != null) {
// method is hidden from exporting
return null;
}
Attribute annoAttribute = operation.getAnnotation(Attribute.class);
if (MBeanExportPolicy.ANNOTATED_ONLY.equals(policy) && (annoAttribute == null)) {
// method is not annotated
return null;
}
if (annoAttribute != null) {
description = operation.getAnnotation(Attribute.class).desc();
}
}
MBeanAttributeInfo info =
new MBeanAttributeInfo(getAttributeName(operation), operation.getReturnType().getName(), description,
(isGetterMethod(operation) || isIsBooleanMethod(operation)), isSetterMethod(operation),
isIsBooleanMethod(operation));
return info;
}
private static String getAttributeName(Method operation) {
String name = operation.getName();
if (isGetterMethod(operation) || isSetterMethod(operation))
name = operation.getName().substring(3);
else if (isIsBooleanMethod(operation))
name = operation.getName().substring(2);
return name;
}
private static MBeanParameterInfo[] getParametersInfo(final Annotation[][] params, final Class<?>[] paramTypes) {
MBeanParameterInfo[] paramsInfo = new MBeanParameterInfo[params.length];
for (int i = 0; i < params.length; i++) {
MBeanParameterInfo paramInfo = null;
String type = paramTypes[i].getName();
for (Annotation anno : params[i]) {
if (Parameter.class.isInstance(anno)) {
String name = Parameter.class.cast(anno).name();
String description = Parameter.class.cast(anno).desc();
paramInfo = new MBeanParameterInfo(name, type, description);
}
}
if (paramInfo == null) {
paramInfo = new MBeanParameterInfo("p " + (i + 1), type, "parameter " + (i + 1));
}
paramsInfo[i] = paramInfo;
}
return paramsInfo;
}
// Inner classes -------------------------------------------------
}

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* profile-management
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* Copyright (C) 2020 - 2024 EmDev LLC
* ==========
* You may not use this file except in accordance with the License Terms of the Copyright
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property

View File

@ -2,7 +2,7 @@
* ~~~~~~licensing~~~~~~
* profile-management
* ==========
* Copyright (C) 2020 - 2023 EmDev LLC
* Copyright (C) 2020 - 2024 EmDev LLC
* ==========
* You may not use this file except in accordance with the License Terms of the Copyright
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property