ENTAXY-248 release 1.8.1

This commit is contained in:
2022-02-28 15:20:38 +03:00
parent 4d274c4fcc
commit c826adf1db
1958 changed files with 195926 additions and 10280 deletions

View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed 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
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.

View File

@ -0,0 +1,32 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ru.entaxy.esb.platform.runtime</groupId>
<artifactId>base</artifactId>
<version>1.8.1</version>
</parent>
<groupId>ru.entaxy.esb.platform.runtime.base</groupId>
<artifactId>management-core</artifactId>
<packaging>bundle</packaging>
<name>ENTAXY :: PLATFORM :: BASE :: MANAGEMENT :: CORE</name>
<description>ENTAXY :: PLATFORM :: BASE :: MANAGEMENT :: CORE</description>
<properties>
<bundle.osgi.export.pkg>
ru.entaxy.esb.platform.base.management.core,
ru.entaxy.esb.platform.base.management.core.api,
ru.entaxy.esb.platform.base.management.core.utils
</bundle.osgi.export.pkg>
</properties>
<dependencies>
<dependency>
<groupId>
ru.entaxy.esb.platform.runtime.base
</groupId>
<artifactId>base-support</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,63 @@
/*-
* ~~~~~~licensing~~~~~~
* management-core
* ==========
* Copyright (C) 2020 - 2021 EmDev LLC
* ==========
* Licensed 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
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.platform.base.management.core;
public class ManagementCore {
public static final String JMX_OBJECTNAME = "jmx.objectname";
public static final String ENTAXY_JMX_DOMAIN = "ru.entaxy.esb";
public static final String LOCAL_NODE_KEY = "localNode";
public static final String LOCAL_NODE_VALUE = "0.0.0.0";
public static final String REMOTE_NODE_KEY = "remoteNode";
public static final String PLATFORM_KEY = "group";
public static final String PLATFORM_KEY_VALUE = "platform";
public static final String RUNTIME_KEY = PLATFORM_KEY;
public static final String RUNTIME_KEY_VALUE = "runtime";
public static final Qualifier Q_LOCAL_NODE = new Qualifier(LOCAL_NODE_KEY, LOCAL_NODE_VALUE);
public static final String Q_LOCAL_NODE_S = ENTAXY_JMX_DOMAIN + ":" + LOCAL_NODE_KEY + "=" + LOCAL_NODE_VALUE;
public static final Qualifier Q_PLATFORM = ManagementCore.Q_LOCAL_NODE.qualifier(PLATFORM_KEY, PLATFORM_KEY_VALUE);
public static final Qualifier Q_RUNTIME = ManagementCore.Q_LOCAL_NODE.qualifier(RUNTIME_KEY, RUNTIME_KEY_VALUE);
public static final String Q_PLATFORM_S = Q_LOCAL_NODE_S + "," + PLATFORM_KEY + "=" + PLATFORM_KEY_VALUE;
public static final String Q_RUNTIME_S = Q_LOCAL_NODE_S + "," + RUNTIME_KEY + "=" + RUNTIME_KEY_VALUE;
// public static final Qualifier Q_PLATFORM = new Qualifier(PLATFORM_KEY, PLATFORM_KEY_VALUE);
// public static final Qualifier Q_RUNTIME = new Qualifier(RUNTIME_KEY, RUNTIME_KEY_VALUE);
}

View File

@ -0,0 +1,87 @@
/*-
* ~~~~~~licensing~~~~~~
* management-core
* ==========
* Copyright (C) 2020 - 2021 EmDev LLC
* ==========
* Licensed 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
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.platform.base.management.core;
import java.util.LinkedHashMap;
import java.util.Map;
import ru.entaxy.platform.base.support.CommonUtils;
public class Qualifier {
protected String domain = ManagementCore.ENTAXY_JMX_DOMAIN;
protected Qualifier parent;
protected Map<String, String> attributes = new LinkedHashMap<>();
public Qualifier() {
super();
}
public Qualifier(String key, String value) {
super();
attributes.put(key, value);
}
public Qualifier(Qualifier parent) {
this();
this.parent = parent;
}
public Qualifier qualifier(String key, String value) {
return (new Qualifier(this)).attribute(key, value);
}
public Qualifier attribute(String key, String value) {
this.attributes.put(key, value);
return this;
}
public String getDomain() {
if (this.parent == null)
return CommonUtils.getValid(this.domain, ManagementCore.ENTAXY_JMX_DOMAIN);
else
return parent.getDomain();
}
public String getAttributes() {
String value = this.parent==null?"":this.parent.getAttributes();
for (Map.Entry<String, String> entry: this.attributes.entrySet()) {
if (!value.isEmpty()) {
value += ",";
}
value += entry.getKey() + "=" + entry.getValue();
}
return value;
}
public String getValue() {
String value = getAttributes();
if (value.isEmpty())
return getDomain();
else
return getDomain() + ":" + value;
}
public String getFullString() {
return ManagementCore.JMX_OBJECTNAME + "=" + getValue();
}
}

View File

@ -0,0 +1,78 @@
/*-
* ~~~~~~licensing~~~~~~
* management-core
* ==========
* Copyright (C) 2020 - 2021 EmDev LLC
* ==========
* Licensed 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
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.platform.base.management.core.api;
import javax.management.Descriptor;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanConstructorInfo;
import javax.management.MBeanInfo;
import javax.management.MBeanNotificationInfo;
import javax.management.MBeanOperationInfo;
import javax.management.NotCompliantMBeanException;
import javax.management.StandardMBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.entaxy.esb.platform.base.management.core.utils.MBeanInfoHelper;
public class AnnotatedMBean<I> extends StandardMBean {
private static final Logger log = LoggerFactory.getLogger(AnnotatedMBean.class);
protected Class<I> interfaceClass;
protected AnnotatedMBean(Class<I> mbeanInterface) throws NotCompliantMBeanException {
super(mbeanInterface);
this.interfaceClass = mbeanInterface;
}
@Override
public MBeanInfo getMBeanInfo() {
log.info(this.interfaceClass==null?">> INTERFACE IS NULL":">> " + this.interfaceClass.getName());
MBeanExportPolicy policy = MBeanExportPolicy.IGNORE_ANNOTATIONS;
MBeanAnnotated anno = this.interfaceClass.getAnnotation(MBeanAnnotated.class);
if (anno != null)
policy = anno.policy();
MBeanInfo beanInfo = super.getMBeanInfo();
if (MBeanExportPolicy.IGNORE_ANNOTATIONS.equals(policy))
return beanInfo;
String className = beanInfo.getClassName();
String description = beanInfo.getDescription();
MBeanAttributeInfo[] attributes = /* beanInfo.getAttributes() */ getMBeanAttributeInfo(policy);
MBeanConstructorInfo[] constructors = beanInfo.getConstructors();
MBeanOperationInfo[] operations = /* beanInfo.getOperations() */ getMBeanOperationInfo(policy);
MBeanNotificationInfo[] notifications = beanInfo.getNotifications();
Descriptor descriptor = beanInfo.getDescriptor();
return new MBeanInfo(className, description, attributes, constructors, operations, notifications, descriptor);
}
protected MBeanAttributeInfo[] getMBeanAttributeInfo(MBeanExportPolicy policy) {
return MBeanInfoHelper.getMBeanAttributesInfo(this.interfaceClass, policy);
}
protected MBeanOperationInfo[] getMBeanOperationInfo(MBeanExportPolicy policy) {
return MBeanInfoHelper.getMBeanOperationsInfo(this.interfaceClass, policy);
}
}

View File

@ -0,0 +1,54 @@
/*-
* ~~~~~~licensing~~~~~~
* management-core
* ==========
* Copyright (C) 2020 - 2021 EmDev LLC
* ==========
* Licensed 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
*
* 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.
* ~~~~~~/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
*
* 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.
*/
package ru.entaxy.esb.platform.base.management.core.api;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Info for a MBean Attribute.
* <p>
* This annotation is used only for attributes which can be seen
* through a GUI.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Attribute {
String desc() default "";
}

View File

@ -0,0 +1,34 @@
/*-
* ~~~~~~licensing~~~~~~
* management-core
* ==========
* Copyright (C) 2020 - 2021 EmDev LLC
* ==========
* Licensed 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
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.platform.base.management.core.api;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
@Retention(RUNTIME)
@Target(TYPE)
public @interface MBeanAnnotated {
MBeanExportPolicy policy() default MBeanExportPolicy.IGNORE_ANNOTATIONS;
}

View File

@ -0,0 +1,29 @@
/*-
* ~~~~~~licensing~~~~~~
* management-core
* ==========
* Copyright (C) 2020 - 2021 EmDev LLC
* ==========
* Licensed 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
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.platform.base.management.core.api;
public enum MBeanExportPolicy {
IGNORE_ANNOTATIONS,
ANNOTATED_ONLY,
ANNOTATION_ENRICH,
EXCEPT_HIDDEN
}

View File

@ -0,0 +1,34 @@
/*-
* ~~~~~~licensing~~~~~~
* management-core
* ==========
* Copyright (C) 2020 - 2021 EmDev LLC
* ==========
* Licensed 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
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.platform.base.management.core.api;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
@Retention(RUNTIME)
@Target(METHOD)
@Inherited
public @interface NotExported {
}

View File

@ -0,0 +1,59 @@
/*-
* ~~~~~~licensing~~~~~~
* management-core
* ==========
* Copyright (C) 2020 - 2021 EmDev LLC
* ==========
* Licensed 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
*
* 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.
* ~~~~~~/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
*
* 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.
*/
package ru.entaxy.esb.platform.base.management.core.api;
import javax.management.MBeanOperationInfo;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Info for a MBean Operation.
* <p>
* This annotation is used only for methods which can be invoked
* through a GUI.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Inherited
public @interface Operation {
String desc();
int impact() default MBeanOperationInfo.INFO;
}

View File

@ -0,0 +1,56 @@
/*-
* ~~~~~~licensing~~~~~~
* management-core
* ==========
* Copyright (C) 2020 - 2021 EmDev LLC
* ==========
* Licensed 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
*
* 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.
* ~~~~~~/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
*
* 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.
*/
package ru.entaxy.esb.platform.base.management.core.api;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Info for a MBean Operation Parameter.
* <p>
* This annotation is used only for methods which can be invoked
* through a GUI.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
public @interface Parameter {
String name();
String desc() default "N/A";
}

View File

@ -0,0 +1,46 @@
/*-
* ~~~~~~licensing~~~~~~
* profile-management
* ==========
* Copyright (C) 2020 - 2021 EmDev LLC
* ==========
* Licensed 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
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.platform.base.management.core.utils;
public class AttributeChangeTracker {
Object oldValue;
Object newValue;
public AttributeChangeTracker oldValue(Object oldValue) {
this.oldValue = oldValue;
return this;
}
public AttributeChangeTracker newValue(Object newValue) {
this.newValue = newValue;
return this;
}
public boolean isChanged() {
if (oldValue == null)
if (newValue == null)
return false;
else
return true;
else
return !oldValue.equals(newValue);
}
}

View File

@ -0,0 +1,30 @@
/*-
* ~~~~~~licensing~~~~~~
* profile-management
* ==========
* Copyright (C) 2020 - 2021 EmDev LLC
* ==========
* Licensed 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
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.platform.base.management.core.utils;
public interface BundleAwareMBean {
public void refreshBundleInfo();
public String getBundleState();
public long getBundleId();
public String getBundleSymbolicName();
}

View File

@ -0,0 +1,146 @@
/*-
* ~~~~~~licensing~~~~~~
* profile-management
* ==========
* Copyright (C) 2020 - 2021 EmDev LLC
* ==========
* Licensed 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
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.platform.base.management.core.utils;
import javax.management.AttributeChangeNotification;
import javax.management.ListenerNotFoundException;
import javax.management.MBeanNotificationInfo;
import javax.management.NotCompliantMBeanException;
import javax.management.Notification;
import javax.management.NotificationBroadcaster;
import javax.management.NotificationBroadcasterSupport;
import javax.management.NotificationEmitter;
import javax.management.NotificationFilter;
import javax.management.NotificationListener;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
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 {
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);
}
@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() {
Bundle b = FrameworkUtil.getBundle(getClass()).getBundleContext().getBundle(getBundleId());
// track bundeState
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

@ -0,0 +1,44 @@
/*-
* ~~~~~~licensing~~~~~~
* profile-management
* ==========
* Copyright (C) 2020 - 2021 EmDev LLC
* ==========
* Licensed 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
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.platform.base.management.core.utils;
public interface BundleAwareManagedObject {
String getBundleState();
void setBundleState(String bundleState);
long getBundleId();
void setBundleId(long bundleId);
String getBundleSymbolicName();
void setBundleSymbolicName(String bundleSymbolicName);
BundleAwareManagedObject bundleState(String bundleState);
BundleAwareManagedObject bundleState(int bundleState);
BundleAwareManagedObject bundleId(long bundleId);
BundleAwareManagedObject bundleSymbolicName(String bundleSeymbolicName);
}

View File

@ -0,0 +1,106 @@
/*-
* ~~~~~~licensing~~~~~~
* profile-management
* ==========
* Copyright (C) 2020 - 2021 EmDev LLC
* ==========
* Licensed 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
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.platform.base.management.core.utils;
import org.osgi.framework.Bundle;
public class BundleAwareManagedObjectImpl implements BundleAwareManagedObject {
protected String bundleState;
protected long bundleId;
protected String bundleSymbolicName;
@Override
public String getBundleState() {
return bundleState;
}
@Override
public void setBundleState(String bundleState) {
this.bundleState = bundleState;
}
@Override
public long getBundleId() {
return bundleId;
}
@Override
public void setBundleId(long bundleId) {
this.bundleId = bundleId;
}
@Override
public String getBundleSymbolicName() {
return bundleSymbolicName;
}
@Override
public void setBundleSymbolicName(String bundleSymbolicName) {
this.bundleSymbolicName = bundleSymbolicName;
}
@Override
public BundleAwareManagedObject bundleState(String bundleState) {
setBundleState(bundleState);
return this;
}
@Override
public BundleAwareManagedObject bundleState(int bundleState) {
String bs = "UNKNOWN";
switch (bundleState) {
case Bundle.ACTIVE:
bs = "Active";
break;
case Bundle.INSTALLED:
bs = "Installed";
break;
case Bundle.RESOLVED:
bs = "Resolved";
break;
case Bundle.STARTING:
bs = "Starting";
break;
case Bundle.STOPPING:
bs = "Stopping";
break;
case Bundle.UNINSTALLED:
bs = "Uninstalled";
break;
}
return this.bundleState(bs);
}
@Override
public BundleAwareManagedObject bundleId(long bundleId) {
setBundleId(bundleId);
return this;
}
@Override
public BundleAwareManagedObject bundleSymbolicName(String bundleSeymbolicName) {
setBundleSymbolicName(bundleSeymbolicName);
return this;
}
}

View File

@ -0,0 +1,46 @@
/*-
* ~~~~~~licensing~~~~~~
* profile-management
* ==========
* Copyright (C) 2020 - 2021 EmDev LLC
* ==========
* Licensed 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
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.platform.base.management.core.utils;
import java.util.List;
import java.util.Map;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleEvent;
import ru.entaxy.platform.base.support.osgi.tracker.UniformBundleTrackerCustomizer;
public abstract class ExtendedBundleTrackerCustomizer<T> extends UniformBundleTrackerCustomizer<T> {
protected void enrich(Bundle bundle, BundleEvent event, Map<String, List<?>> filterResults, Object object) {
if (object instanceof BundleAwareManagedObject) {
((BundleAwareManagedObject)object)
.bundleId(bundle.getBundleId())
.bundleState(bundle.getState())
.bundleSymbolicName(bundle.getSymbolicName());
}
}
protected void update(Bundle bundle, BundleEvent event, Map<String, List<?>> filterResults, List<?> objects) {
for (Object object: objects)
enrich(bundle, event, filterResults, object);
}
}

View File

@ -0,0 +1,244 @@
/*-
* ~~~~~~licensing~~~~~~
* management-core
* ==========
* Copyright (C) 2020 - 2021 EmDev LLC
* ==========
* Licensed 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
*
* 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.
* ~~~~~~/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
*
* 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.
*/
package ru.entaxy.esb.platform.base.management.core.utils;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanParameterInfo;
import ru.entaxy.esb.platform.base.management.core.api.Attribute;
import ru.entaxy.esb.platform.base.management.core.api.MBeanExportPolicy;
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 -----------------------------------------------------
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
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()));
}
}
if (!alreadyAdded.contains(infoToCopy.getName())) {
finalAttributes.add(infoToCopy);
alreadyAdded.add(infoToCopy.getName());
}
}
return finalAttributes.toArray(new MBeanAttributeInfo[finalAttributes.size()]);
}
// Package protected ---------------------------------------------
// 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

@ -0,0 +1,28 @@
/*-
* ~~~~~~licensing~~~~~~
* profile-management
* ==========
* Copyright (C) 2020 - 2021 EmDev LLC
* ==========
* Licensed 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
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.platform.base.management.core.utils;
import org.osgi.framework.ServiceRegistration;
public class ManagedObjectDescriptor<S, I, C extends I> {
S object;
C service;
ServiceRegistration<I> registration;
}

View File

@ -0,0 +1,115 @@
/*-
* ~~~~~~licensing~~~~~~
* profile-management
* ==========
* Copyright (C) 2020 - 2021 EmDev LLC
* ==========
* Licensed 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
*
* 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.
* ~~~~~~/licensing~~~~~~
*/
package ru.entaxy.esb.platform.base.management.core.utils;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.entaxy.esb.platform.base.management.core.ManagementCore;
import ru.entaxy.platform.base.support.osgi.tracker.BundleTrackerCustomizerListener;
public abstract class ManagedObjectsListener<T, S, I, C extends I> implements BundleTrackerCustomizerListener<T> {
private static final Logger log = LoggerFactory.getLogger(ManagedObjectsListener.class);
protected Map<String, ManagedObjectDescriptor<S, I, C>> managed = new HashMap<>();
protected BundleContext bundleContext;
protected Class<I> serviceClass;
public ManagedObjectsListener(BundleContext bundleContext, Class<I> serviceClass) {
super();
this.bundleContext = bundleContext;
this.serviceClass = serviceClass;
}
public Map<String, ManagedObjectDescriptor<S, I, C>> getManaged() {
return managed;
}
@Override
public void added(T managedObject) {
Iterator<S> iter = getIterator(managedObject);
while (iter.hasNext()) {
S object = iter.next();
String key = getKeyValue(object);
if (managed.containsKey(key)) {
managed.get(key).registration.unregister();
}
C service = createService(object);
if (service == null)
continue;
ManagedObjectDescriptor<S, I, C> descriptor = new ManagedObjectDescriptor<>();
descriptor.object = object;
descriptor.service = service;
Hashtable props = new Hashtable<>();
props.put(ManagementCore.JMX_OBJECTNAME, getJmxObjectName(object));
descriptor.registration = bundleContext.registerService(this.serviceClass, service, props);
managed.put(key, descriptor);
}
}
@Override
public void removed(T managedObject) {
Iterator<S> iter = getIterator(managedObject);
while (iter.hasNext()) {
S object = iter.next();
String key = getKeyValue(object);
if (managed.containsKey(key)) {
managed.get(key).registration.unregister();
managed.remove(key);
}
}
}
@Override
public void modified(T managedObject) {
log.info(">> modified");
Iterator<S> iter = getIterator(managedObject);
while (iter.hasNext()) {
S object = iter.next();
String key = getKeyValue(object);
if (managed.containsKey(key)) {
C service = managed.get(key).service;
if (service instanceof BundleAwareMBean) {
((BundleAwareMBean)service).refreshBundleInfo();
log.info(">> refreshBundleInfo");
} else {
log.info(">> NOT BundleAwareMBean");
}
}
}
}
protected abstract Iterator<S> getIterator(T managedObject);
protected abstract String getKeyValue(S object);
protected abstract C createService(S managedObject);
protected abstract String getJmxObjectName(S managedObject);
}