You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2015/08/24 18:22:28 UTC
[1/3] incubator-tamaya git commit: Finished implementation of
management JMX support for Tamaya with minimal functionality and tests.
Repository: incubator-tamaya
Updated Branches:
refs/heads/master 1d3cb66e9 -> b6521ede9
Finished implementation of management JMX support for Tamaya with minimal functionality and tests.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/689aeafc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/689aeafc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/689aeafc
Branch: refs/heads/master
Commit: 689aeafc9aaf631cdc1f292c6e9ffefff1fedeff
Parents: 1d3cb66
Author: anatole <an...@apache.org>
Authored: Mon Aug 24 18:13:56 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Mon Aug 24 18:13:56 2015 +0200
----------------------------------------------------------------------
.../management/ConfigManagementSupport.java | 128 +++++++++++++++++++
.../apache/tamaya/management/ManagedConfig.java | 99 +++++++-------
.../tamaya/management/ManagedConfigMBean.java | 36 +++++-
.../META-INF/javaconfiguration.properties | 19 +++
.../tamaya/management/ManagedConfigTest.java | 77 -----------
.../management/internal/ManagedConfigTest.java | 121 ++++++++++++++++++
6 files changed, 350 insertions(+), 130 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/689aeafc/modules/management/src/main/java/org/apache/tamaya/management/ConfigManagementSupport.java
----------------------------------------------------------------------
diff --git a/modules/management/src/main/java/org/apache/tamaya/management/ConfigManagementSupport.java b/modules/management/src/main/java/org/apache/tamaya/management/ConfigManagementSupport.java
new file mode 100644
index 0000000..64fa062
--- /dev/null
+++ b/modules/management/src/main/java/org/apache/tamaya/management/ConfigManagementSupport.java
@@ -0,0 +1,128 @@
+/*
+ * 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 org.apache.tamaya.management;
+
+
+import org.apache.tamaya.spi.ServiceContextManager;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import java.lang.management.ManagementFactory;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Accessor singleton for the JMX configuration support module.
+ */
+public class ConfigManagementSupport {
+
+ /** The logger used. */
+ private final static Logger LOG = Logger.getLogger(ConfigManagementSupport.class.getName());
+
+ /**
+ * Private singleton constructor.
+ */
+ private ConfigManagementSupport(){}
+
+ /**
+ * Creates a new instance of a {@link ManagedConfigMBean} instance. This method uses the
+ * current {@link ServiceContextManager} to resolve the implementation to be used.
+ * @return a new ManagedConfigMBean instance, or null
+ * @throws org.apache.tamaya.ConfigException if there are multiple service implementations with the
+ * maximum priority.
+ */
+ private static ManagedConfigMBean createMBean(){
+ return ServiceContextManager.getServiceContext()
+ .getService(ManagedConfigMBean.class);
+ }
+
+ /**
+ * Registers a new instance of {@link ManagedConfigMBean} mbean for accessing config documentation into the local platform
+ * mbean server.
+ * @return the registered ObjectName, or null, if no bean could be created.
+ */
+ public static ObjectName registerMBean() {
+ return registerMBean(null);
+ }
+
+ /**
+ * Registers the {@link ManagedConfigMBean} mbean for accessing config documentation into the local platform
+ * mbean server.
+ * @param context An optional context parameter to be added to the object name.
+ * @return the registered ObjectName, or null, if no bean could be created.
+ */
+ public static ObjectName registerMBean(String context) {
+ try{
+ ManagedConfigMBean configMbean = createMBean();
+ if(configMbean==null){
+ return null;
+ }
+ MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+ ObjectName on = context==null?new ObjectName("org.apache.tamaya.managemet:type=ManagedConfigMBean"):
+ new ObjectName("org.apache.tamaya.management:type=ManagedConfigMBean,context="+context);
+ try{
+ mbs.getMBeanInfo(on);
+ LOG.info("Cannot register mbean " + on + ": already existing.");
+ return on;
+ } catch(InstanceNotFoundException e) {
+ LOG.info("Registering mbean " + on + "...");
+ mbs.registerMBean(configMbean, on);
+ return on;
+ }
+ } catch(Exception e){
+ LOG.log(Level.WARNING, "Failed to register ManagedConfigMBean.", e);
+ }
+ return null;
+ }
+
+ /**
+ * Unregisters a new instance of {@link ManagedConfigMBean} mbean for accessing config documentation
+ * into the local platform mbean server.
+ * @return the unregistered ObjectName, or null, if no bean could be found.
+ */
+ public static ObjectName unregisterMBean() {
+ return unregisterMBean(null);
+ }
+
+ /**
+ * Unegisters the {@link ManagedConfigMBean} mbean for accessing config documentation into the local
+ * platform mbean server.
+ * @param context An optional context parameter to be added to the object name.
+ * @return the unregistered ObjectName, or null, if no bean could be created.
+ */
+ public static ObjectName unregisterMBean(String context) {
+ try{
+ MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+ ObjectName on = context==null?new ObjectName("org.apache.tamaya.managemet:type=ManagedConfigMBean"):
+ new ObjectName("org.apache.tamaya.management:type=ManagedConfigMBean,context="+context);
+ try{
+ mbs.unregisterMBean(on);
+ LOG.info("Unregistered mbean " + on + ".");
+ return on;
+ } catch(InstanceNotFoundException e) {
+ LOG.log(Level.INFO, "Unregistering mbean " + on + " failed.", e);
+ }
+ } catch(Exception e){
+ LOG.log(Level.WARNING, "Failed to unregister ManagedConfigMBean.", e);
+ }
+ return null;
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/689aeafc/modules/management/src/main/java/org/apache/tamaya/management/ManagedConfig.java
----------------------------------------------------------------------
diff --git a/modules/management/src/main/java/org/apache/tamaya/management/ManagedConfig.java b/modules/management/src/main/java/org/apache/tamaya/management/ManagedConfig.java
index bd6ab68..7ab6969 100644
--- a/modules/management/src/main/java/org/apache/tamaya/management/ManagedConfig.java
+++ b/modules/management/src/main/java/org/apache/tamaya/management/ManagedConfig.java
@@ -19,88 +19,93 @@
package org.apache.tamaya.management;
-import org.apache.tamaya.functions.ConfigurationFunctions;
+import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.spi.ServiceContextManager;
+import org.apache.tamaya.functions.ConfigurationFunctions;
-import javax.management.InstanceNotFoundException;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import java.lang.management.ManagementFactory;
import java.util.Map;
import java.util.Set;
-import java.util.logging.Level;
import java.util.logging.Logger;
/**
- * Created by Anatole on 24.11.2014.
+ * Default implementation of the {@link ManagedConfigMBean} interface. Each bean binds to the
+ * current Configuration instance on creation.
*/
-public class ManagedConfig implements ManagedConfigMBean{
+public class ManagedConfig implements ManagedConfigMBean {
- /** The logger used. */
+ /**
+ * The logger used.
+ */
private final static Logger LOG = Logger.getLogger(ManagedConfig.class.getName());
+ /**
+ * Classloader that was active when this instance was created.
+ */
+ private ClassLoader classLoader;
+
+ /**
+ * Constructor, which binds this instance to the current TCCL. In the rare cases where
+ * the TCCL is null, this class's classloader is used.
+ */
+ public ManagedConfig() {
+ this.classLoader = Thread.currentThread().getContextClassLoader();
+ if (this.classLoader == null) {
+ this.classLoader = ManagedConfigMBean.class.getClassLoader();
+ }
+ }
+
@Override
- public String getConfigurationInfo() {
- return ConfigurationProvider.getConfiguration().query(ConfigurationFunctions.jsonInfo());
+ public String getJsonConfigurationInfo() {
+ return getConfigurationInternal().query(ConfigurationFunctions.jsonInfo());
}
@Override
- public Map<String, String> getConfiguration() {
- return ConfigurationProvider.getConfiguration().getProperties();
+ public String getXmlConfigurationInfo() {
+ return getConfigurationInternal().query(ConfigurationFunctions.xmlInfo());
}
@Override
- public Map<String, String> getConfigurationArea(String area, boolean recursive) {
- return ConfigurationProvider.getConfiguration().with(ConfigurationFunctions.section(area, recursive)).getProperties();
+ public Map<String, String> getConfiguration() {
+ return getConfigurationInternal().getProperties();
}
@Override
- public Set<String> getAreas() {
- return ConfigurationProvider.getConfiguration().query(ConfigurationFunctions.sections());
+ public Map<String, String> getSection(String area, boolean recursive) {
+ return getConfigurationInternal().with(ConfigurationFunctions.section(area, recursive)).getProperties();
}
@Override
- public Set<String> getTransitiveAreas() {
- return ConfigurationProvider.getConfiguration().query(ConfigurationFunctions.transitiveSections());
+ public Set<String> getSections() {
+ return getConfigurationInternal().query(ConfigurationFunctions.sections());
}
@Override
- public boolean isAreaExisting(String area) {
- return !ConfigurationProvider.getConfiguration().with(
- ConfigurationFunctions.section(area)).getProperties().isEmpty();
+ public Set<String> getTransitiveSections() {
+ return getConfigurationInternal().query(ConfigurationFunctions.transitiveSections());
}
- /**
- * Registers the {@link ManagedConfigMBean} mbean for accessing config documentation into the local platform
- * mbean server.
- */
- public static void registerMBean() {
- registerMBean(null);
+ @Override
+ public boolean isAreaExisting(String area) {
+ return !getConfigurationInternal().with(
+ ConfigurationFunctions.section(area)).getProperties().isEmpty();
}
/**
- * Registers the {@link ManagedConfigMBean} mbean for accessing config documentation into the local platform
- * mbean server.
+ * Evaluate the current configuration. By default this class is temporarely setting the
+ * TCCL to the instance active on bean creation and then calls {@link ConfigurationProvider#getConfiguration()}.
+ *
+ * @return the configuration instance to be used.
*/
- public static void registerMBean(String context) {
+ protected Configuration getConfigurationInternal() {
+ ClassLoader currentCL = Thread.currentThread().getContextClassLoader();
try{
- ManagedConfigMBean configMbean = ServiceContextManager.getServiceContext()
- .getService(ManagedConfigMBean.class);
- MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
- ObjectName on = context==null?new ObjectName("org.apache.tamaya.managemet:type=ManagedConfigMBean"):
- new ObjectName("org.apache.tamaya.management:type=ManagedConfigMBean,context="+context);
- try{
- mbs.getMBeanInfo(on);
- LOG.warning("Cannot register mbean " + on + ": already existing.");
- } catch(InstanceNotFoundException e) {
- LOG.info("Registering mbean " + on + "...");
- mbs.registerMBean(configMbean, on);
- }
- } catch(Exception e){
- Logger.getLogger(ManagedConfig.class.getName()).log(Level.WARNING,
- "Failed to register ManagedConfigMBean.", e);
+ Thread.currentThread().setContextClassLoader(this.classLoader);
+ return ConfigurationProvider.getConfiguration();
+ }
+ finally{
+ Thread.currentThread().setContextClassLoader(currentCL);
}
}
+
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/689aeafc/modules/management/src/main/java/org/apache/tamaya/management/ManagedConfigMBean.java
----------------------------------------------------------------------
diff --git a/modules/management/src/main/java/org/apache/tamaya/management/ManagedConfigMBean.java b/modules/management/src/main/java/org/apache/tamaya/management/ManagedConfigMBean.java
index 1cfb368..746d494 100644
--- a/modules/management/src/main/java/org/apache/tamaya/management/ManagedConfigMBean.java
+++ b/modules/management/src/main/java/org/apache/tamaya/management/ManagedConfigMBean.java
@@ -29,6 +29,31 @@ public interface ManagedConfigMBean {
/**
* Get a general description of the configuration (context) in place, in JSON format:
* <pre>
+ * Configuration: {
+ * "class": "org.apache.tamaya.core.internal.DefaultConfiguration",
+ * "timestamp": 1440426409388,
+ * "data": {
+ * "ALLUSERSPROFILE": "C:\ProgramData",
+ * "APPDATA": "C:\Users\Anatole\AppData\Roaming",
+ * "COMPUTERNAME": "DEVBOX-WIN",
+ * "ComSpec": "C:\Windows\system32\cmd.exe",
+ * "CommonProgramFiles": "C:\Program Files\Common Files",
+ * "CommonProgramFiles(x86)": "C:\Program Files (x86)\Common Files",
+ * "CommonProgramW6432": "C:\Program Files\Common Files",
+ * "FP_NO_HOST_CHECK": "NO",
+ * "HOMEDRIVE": "C:",
+ * // ...
+ * }
+ * }
+ * </pre>
+ *
+ * @return a JSON formatted meta-information.
+ */
+ String getJsonConfigurationInfo();
+
+ /**
+ * Get a general description of the configuration (context) in place, in JSON format:
+ * <pre>
* ConfigurationContext[gqContextClassName] {
* version = 2345-34334-2333-3434,
* config {
@@ -44,8 +69,7 @@ public interface ManagedConfigMBean {
*
* @return a JSON formatted meta-information.
*/
- String getConfigurationInfo();
-
+ String getXmlConfigurationInfo();
/**
* Accesses a configuration current a given type as Map.
@@ -62,21 +86,21 @@ public interface ManagedConfigMBean {
* @return the key/values found, including the recursive child values.
* @throws org.apache.tamaya.ConfigException If the configuration is not yet loaded.
*/
- Map<String, String> getConfigurationArea(String area, boolean recursive);
+ Map<String, String> getSection(String area, boolean recursive);
/**
* Access the defined sections for a given configuration.
* @return the sections defined (only returning the sections that contain properties).
* @throws org.apache.tamaya.ConfigException If the configuration is not yet loaded
*/
- Set<String> getAreas();
+ Set<String> getSections();
/**
* Access the transitive sections for the current configuration.
* @return the transitive sections defined.
* @throws org.apache.tamaya.ConfigException If the configuration is not yet loaded
*/
- Set<String> getTransitiveAreas();
+ Set<String> getTransitiveSections();
/**
* Allows to determine if an section is existing.
@@ -91,7 +115,7 @@ public interface ManagedConfigMBean {
* @return true, if such an section exists and is not empty.
*/
default boolean isAreaEmpty(String area){
- return getConfigurationArea(area, true).isEmpty();
+ return getSection(area, true).isEmpty();
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/689aeafc/modules/management/src/main/resources/META-INF/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/modules/management/src/main/resources/META-INF/javaconfiguration.properties b/modules/management/src/main/resources/META-INF/javaconfiguration.properties
new file mode 100644
index 0000000..333ba9c
--- /dev/null
+++ b/modules/management/src/main/resources/META-INF/javaconfiguration.properties
@@ -0,0 +1,19 @@
+#
+# 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 current 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.
+#
+a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z=alphabet
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/689aeafc/modules/management/src/test/java/org/apache/tamaya/management/ManagedConfigTest.java
----------------------------------------------------------------------
diff --git a/modules/management/src/test/java/org/apache/tamaya/management/ManagedConfigTest.java b/modules/management/src/test/java/org/apache/tamaya/management/ManagedConfigTest.java
deleted file mode 100644
index 577425e..0000000
--- a/modules/management/src/test/java/org/apache/tamaya/management/ManagedConfigTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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 org.apache.tamaya.management;
-
-import static org.junit.Assert.*;
-
-/**
- * Created by Anatole on 20.08.2015.
- */
-public class ManagedConfigTest {
-
- private ManagedConfig bean = new ManagedConfig();
-
- @org.junit.Test
- public void testGetConfigurationInfo() throws Exception {
- System.out.println(bean.getConfigurationInfo());
- }
-
- @org.junit.Test
- public void testGetConfiguration() throws Exception {
- System.out.println(bean.getConfiguration());
- }
-
- @org.junit.Test
- public void testGetConfigurationArea() throws Exception {
- System.out.println(bean.getConfigurationArea("a", false));
- }
-
- @org.junit.Test
- public void testGetAreas() throws Exception {
- System.out.println(bean.getAreas());
- }
-
- @org.junit.Test
- public void testGetTransitiveAreas() throws Exception {
- System.out.println(bean.getTransitiveAreas());
- }
-
- @org.junit.Test
- public void testIsAreaExisting() throws Exception {
- assertTrue(bean.isAreaExisting("java"));
- assertFalse(bean.isAreaExisting("sd.fldsfl.erlwsf"));
- }
-
- @org.junit.Test
- public void testRegisterMBean() throws Exception {
- ManagedConfig.registerMBean();
- ManagedConfig.registerMBean();
- // Lookup object name
-
- }
-
- @org.junit.Test
- public void testRegisterMBean1() throws Exception {
- ManagedConfig.registerMBean("SubContext1");
- ManagedConfig.registerMBean("SubContext1");
- ManagedConfig.registerMBean("SubContext2");
- // Lookup object name
-
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/689aeafc/modules/management/src/test/java/org/apache/tamaya/management/internal/ManagedConfigTest.java
----------------------------------------------------------------------
diff --git a/modules/management/src/test/java/org/apache/tamaya/management/internal/ManagedConfigTest.java b/modules/management/src/test/java/org/apache/tamaya/management/internal/ManagedConfigTest.java
new file mode 100644
index 0000000..8dcb5f6
--- /dev/null
+++ b/modules/management/src/test/java/org/apache/tamaya/management/internal/ManagedConfigTest.java
@@ -0,0 +1,121 @@
+/*
+ * 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 org.apache.tamaya.management.internal;
+
+import org.apache.tamaya.management.ConfigManagementSupport;
+import org.apache.tamaya.management.ManagedConfig;
+import org.apache.tamaya.management.ManagedConfigMBean;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import java.lang.management.ManagementFactory;
+import java.util.Map;
+import java.util.Set;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by Anatole on 20.08.2015.
+ */
+public class ManagedConfigTest {
+
+ private ManagedConfigMBean bean = new ManagedConfig();
+
+ @org.junit.Test
+ public void testGetJsonConfigurationInfo() throws Exception {
+ String info = bean.getJsonConfigurationInfo();
+ assertNotNull(info);
+ assertTrue(info.contains("java.version"));
+ System.out.println(bean.getJsonConfigurationInfo());
+ assertTrue(info.contains("\"configuration\": "));
+ }
+
+ @org.junit.Test
+ public void testGetXmlConfigurationInfo() throws Exception {
+ String info = bean.getXmlConfigurationInfo();
+ assertNotNull(info);
+ assertTrue(info.contains("java.version"));
+ assertTrue(info.contains("<configuration>"));
+ System.out.println(bean.getXmlConfigurationInfo());
+ }
+
+ @org.junit.Test
+ public void testGetConfiguration() throws Exception {
+ Map<String,String> config = bean.getConfiguration();
+ assertNotNull(config);
+ for(Map.Entry<Object, Object> en:System.getProperties().entrySet()){
+ assertEquals(config.get(en.getKey()),en.getValue());
+ }
+ }
+
+ @org.junit.Test
+ public void testGetConfigurationArea() throws Exception {
+ Map<String,String> cfg = bean.getSection("java", false);
+ for(Map.Entry<String,String> en:cfg.entrySet()){
+ assertEquals(System.getProperty(en.getKey()), en.getValue());
+ }
+ }
+
+ @org.junit.Test
+ public void testGetAreas() throws Exception {
+ Set<String> sections = (bean.getSections());
+ assertNotNull(sections);
+ assertTrue(sections.contains("java"));
+ assertTrue(sections.contains("sun"));
+ assertTrue(sections.contains("os"));
+ assertTrue(sections.contains("file"));
+ }
+
+ @org.junit.Test
+ public void testGetTransitiveAreas() throws Exception {
+ Set<String> sections = (bean.getTransitiveSections());
+ Set<String> sectionsNT = (bean.getSections());
+ assertNotNull(sections);
+ assertTrue(sections.contains("java"));
+ assertTrue(sections.contains("sun"));
+ assertTrue(sections.contains("sun.os"));
+ assertTrue(sectionsNT.size()<sections.size());
+ }
+
+ @org.junit.Test
+ public void testIsAreaExisting() throws Exception {
+ assertTrue(bean.isAreaExisting("java"));
+ assertFalse(bean.isAreaExisting("sd.fldsfl.erlwsf"));
+ }
+
+ @org.junit.Test
+ public void testRegisterMBean() throws Exception {
+ ObjectName on = ConfigManagementSupport.registerMBean();
+ ConfigManagementSupport.registerMBean();
+ // Lookup object name
+ MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+ assertTrue(mbs.getMBeanInfo(on)!=null);
+ }
+
+ @org.junit.Test
+ public void testRegisterMBean1() throws Exception {
+ ObjectName on1 = ConfigManagementSupport.registerMBean("SubContext1");
+ ConfigManagementSupport.registerMBean("SubContext1");
+ ObjectName on2 = ConfigManagementSupport.registerMBean("SubContext2");
+ // Lookup object name
+ MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+ assertTrue(mbs.getMBeanInfo(on1)!=null);
+ assertTrue(mbs.getMBeanInfo(on2)!=null);
+ }
+}
\ No newline at end of file
[3/3] incubator-tamaya git commit: Replaced the name 'area' with
'section'. Implemented management JMX extension for Tamaya incl a minimal
test bed. Added documentation/doc updates.
Posted by an...@apache.org.
Replaced the name 'area' with 'section'.
Implemented management JMX extension for Tamaya incl a minimal test bed.
Added documentation/doc updates.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/b6521ede
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/b6521ede
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/b6521ede
Branch: refs/heads/master
Commit: b6521ede9847e04937f68853a91f5ebc8132e553
Parents: a88f52f
Author: anatole <an...@apache.org>
Authored: Mon Aug 24 18:22:08 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Mon Aug 24 18:22:08 2015 +0200
----------------------------------------------------------------------
docs/src/main/asciidoc/modules.adoc | 1 +
java7/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b6521ede/docs/src/main/asciidoc/modules.adoc
----------------------------------------------------------------------
diff --git a/docs/src/main/asciidoc/modules.adoc b/docs/src/main/asciidoc/modules.adoc
index eed4fc5..9e38e1f 100644
--- a/docs/src/main/asciidoc/modules.adoc
+++ b/docs/src/main/asciidoc/modules.adoc
@@ -64,6 +64,7 @@ NOTE All extensions, despite the _tamaya-builder_ module, currently run on Java
|+org.apache.tamaya.ext:tamaya-json+ |Provides format support for JSON based configuration. |link:modjson.html[Documentation]
|+org.apache.tamaya.ext:tamaya-model+ |Provides support documenting ang validating configuration during runtime. |link:mod_model.html[Documentation]
|+org.apache.tamaya.ext:tamaya-functions+ |Provides several functional extension points. |link:mod_functions.html[Documentation]
+|+org.apache.tamaya.ext:tamaya-management+ |Provides JMX support for inspecting configuration. |link:mod_management.html[Documentation]
|=======
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b6521ede/java7/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java b/java7/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java
index ad73575..cdd481e 100644
--- a/java7/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java
+++ b/java7/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java
@@ -38,7 +38,7 @@ public interface ServiceContext {
* the one with the highest {@link javax.annotation.Priority} will be used.
*
* @param serviceType the service type.
- * @return The instance to be used, never {@code null}
+ * @return The instance to be used, or {@code null}
* @throws org.apache.tamaya.ConfigException if there are multiple service implementations with the maximum priority.
*/
<T> T getService(Class<T> serviceType);
[2/3] incubator-tamaya git commit: Replaced the name 'are' with
'section'. Implemented management JMX extension for Tamaya incl a minimal
test bed.
Posted by an...@apache.org.
Replaced the name 'are' with 'section'.
Implemented management JMX extension for Tamaya incl a minimal test bed.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/a88f52fc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/a88f52fc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/a88f52fc
Branch: refs/heads/master
Commit: a88f52fc19b9c76d8d81f2d788b61b0826b18016
Parents: 689aeaf
Author: anatole <an...@apache.org>
Authored: Mon Aug 24 18:15:29 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Mon Aug 24 18:15:29 2015 +0200
----------------------------------------------------------------------
docs/src/main/asciidoc/mod_functions.adoc | 9 +-
docs/src/main/asciidoc/mod_management.adoc | 127 ++++++++++++++++++++++++
2 files changed, 132 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a88f52fc/docs/src/main/asciidoc/mod_functions.adoc
----------------------------------------------------------------------
diff --git a/docs/src/main/asciidoc/mod_functions.adoc b/docs/src/main/asciidoc/mod_functions.adoc
index 9031940..f80cd4e 100644
--- a/docs/src/main/asciidoc/mod_functions.adoc
+++ b/docs/src/main/asciidoc/mod_functions.adoc
@@ -1,7 +1,7 @@
-= Apache Tamaya -- Extension: Formats
+= Apache Tamaya -- Extension: Functions
:name: Tamaya
-:rootpackage: org.apache.tamaya.ext.formats
+:rootpackage: org.apache.tamaya.functions
:title: Apache Tamaya Extension: Functions
:revnumber: 0.1.1
:revremark: Incubator
@@ -58,7 +58,8 @@ import static org.apache.tamaya.functions.ConfigurationFunctions.*;
Set<String> sections = ConfigurationProvider.getConfiguration().with(areas("a", false).with(transitiveAreas());
-------------------------------------------------------------------
-The expression above returns all section that are child sections of the root section 'a'.
+The expression above returns all fully qualified section names that are child sections of the root section 'a'.
+So given the entries +a.b.entry1, a.b.entry2, a.a.entry3, a.b.c.entry4+ the reult would be +a, a.a, a.b, a.b.c+.
=== Compatibility
@@ -66,7 +67,7 @@ The module is based on Java 7, so it can be used with Java 7 and beyond.
=== Installation
-To benefit from dynamic value resolution you only must add the corresponding dependency to your module:
+For using the functionality shown in this document you only must add the corresponding dependency to your module:
[source, xml]
-----------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a88f52fc/docs/src/main/asciidoc/mod_management.adoc
----------------------------------------------------------------------
diff --git a/docs/src/main/asciidoc/mod_management.adoc b/docs/src/main/asciidoc/mod_management.adoc
new file mode 100644
index 0000000..96b03d4
--- /dev/null
+++ b/docs/src/main/asciidoc/mod_management.adoc
@@ -0,0 +1,127 @@
+= Apache Tamaya -- Extension: JMX Management Access
+
+:name: Tamaya
+:rootpackage: org.apache.tamaya.management
+:title: Apache Tamaya Extension: JMX Management Access
+:revnumber: 0.1
+:revremark: Incubator
+:revdate: August 2015
+:longversion: {revnumber} ({revremark}) {revdate}
+:authorinitials: ATR
+:author: Anatole Tresch
+:email: <an...@apache.org>
+:source-highlighter: coderay
+:website: http://tamaya.incubator.apache.org/
+:toc:
+:toc-placement: manual
+:encoding: UTF-8
+:numbered:
+// 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.
+'''
+
+<<<
+
+toc::[]
+
+<<<
+:numbered!:
+<<<
+[[ExtModel]]
+== Tamaya Management (JMX Support) (Extension Module)
+=== Overview
+
+The Tamaya management module provides support for registering a JMX management bean for accessing configuration.
+
+=== Compatibility
+
+The module is based on Java 7, so it will not run on Java 7 and beyond.
+
+
+=== Installation
+
+To benefit from configuration builder support you only must add the corresponding dependency to your module:
+
+[source, xml]
+-----------------------------------------------
+<dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-management</artifactId>
+ <version>{tamayaVersion}</version>
+</dependency>
+-----------------------------------------------
+
+
+=== The ManagedConfigMBean bean
+
+The management model defines the MBean of type +ManagedConfigMBean+ as follows:
+
+
+[source,java]
+-----------------------------------------------------------------------------
+public interface ManagedConfigMBean {
+ String getJsonConfigurationInfo();
+ String getXmlConfigurationInfo();
+ Map<String, String> getConfiguration();
+ Map<String, String> getSection(String area, boolean recursive);
+ Set<String> getSections();
+ Set<String> getTransitiveSections();
+ boolean isSectionExisting(String area);
+ default boolean isSectionEmpty(String area);
+}
+-----------------------------------------------------------------------------
+
+* +getJsonConfigurationInfo,getXmlConfigurationInfo+ return a JSON or XML representation of the
+current configuration.
+* +getConfiguration+ access the current configuration properties.
+* +getSection+ allows to extract all entries below a certain subkey. With _recursive_ the query
+ will not only return direct children, but also recursively walk down all subsection of the
+ given section key.
+* +getSections+ returns all current known section names.
+* +getTransitiveSections+ return all sections, but also adds all transitive subsection as single
+ entries to the set as well.
+* +isSectionExisting+ and +isSectionEmpty+ allow for quering if entries are present under the given
+ section keys.
+
+=== Registering the ManagedConfigMBean
+
+For registering the current +ManagedConfigMBean+ instance to the current MBean platform server, the
+following static methods are available:
+
+[source,java]
+-----------------------------------------------------------------------------
+public final class ConfigManagementSupport{
+
+ private JMXSupport(){}
+
+ public static ObjectName registerMBean();
+ public static ObjectName registerMBean(String context);
+ public static ObjectName unregisterMBean();
+ public static ObjectName unregisterMBean(String context);
+}
+-----------------------------------------------------------------------------
+
+* +registerMBean+ creates a new +ManagedConfigMBean+ instance using the +ServiceContextManager+
+ and registers it. Optionally an additional _context_ parameter can be passed, which allows
+ to register the management bean for different classloaders, e.g. for different
+ ears.
+* +unregisterMBean+ does the oppsite than registering obviously.
+
+NOTE: The instance of +ManagedConfigMBean+ to be created and registered is evaluated by use og the
+ +ServiceContextManager+. So you can replace the bean implementation by registering your
+ overriding implementation using the current +ServiceContext+ (by default using
+ +java.util.ServiceLoader+ and +@Priority+ annotation.
\ No newline at end of file